|
10 | 10 | from dataform2looker.lookml import LookML |
11 | 11 |
|
12 | 12 |
|
13 | | -def _generate_view(path_to_json_file: str, target_dir: str, tags: set[str]) -> int: |
| 13 | +def _generate_view( |
| 14 | + path_to_json_file: str, target_dir: str, tags: set[str], gen_extra_measures: bool |
| 15 | +) -> int: |
14 | 16 | """Generates LookML view files from a Dataform model. |
15 | 17 |
|
16 | 18 | Args: |
17 | 19 | path_to_json_file (str): Path to the JSON file from compiled Dataform project. |
18 | 20 | target_dir (str): Target directory for Looker views. |
19 | 21 | tags (set[str]): Filter to dataform models using this tag. |
| 22 | + gen_extra_measures (bool): Whether to generate extra measures. |
20 | 23 |
|
21 | 24 | Returns: |
22 | 25 | int: 0 if the view generation was successful, 1 otherwise. |
23 | 26 | """ |
24 | 27 | logging.info(f" Generating views from: {path_to_json_file}") |
25 | 28 | try: |
26 | | - lookml_object = LookML(path_to_json_file, target_dir, tags=tags) |
| 29 | + lookml_object = LookML( |
| 30 | + path_to_json_file, |
| 31 | + target_dir, |
| 32 | + tags=tags, |
| 33 | + gen_extra_measures=gen_extra_measures, |
| 34 | + ) |
27 | 35 | lookml_object.save_lookml_views() |
28 | 36 | return 0 |
29 | 37 | except subprocess.CalledProcessError as e: |
@@ -70,17 +78,26 @@ def main(argv: Sequence[str] | None = None) -> int: |
70 | 78 | required=False, |
71 | 79 | ) |
72 | 80 |
|
| 81 | + parser.add_argument( |
| 82 | + "--gen-extra-measures", |
| 83 | + action="store_true", |
| 84 | + help="Generate extra measures like sum and count distinct.", |
| 85 | + ) |
| 86 | + |
73 | 87 | args = parser.parse_args(argv) |
74 | 88 |
|
75 | 89 | source_file = args.source_file_path |
76 | 90 | target_dir = args.target_dir |
77 | 91 | verbose = args.verbose |
78 | 92 | tags = args.tags |
| 93 | + gen_extra_measures = args.gen_extra_measures |
79 | 94 |
|
80 | 95 | logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) |
81 | 96 |
|
82 | 97 | if source_file.is_file(): |
83 | 98 | logging.info(f" Processing file: {source_file}") |
84 | | - return _generate_view(str(source_file), str(target_dir), set(tags)) |
| 99 | + return _generate_view( |
| 100 | + str(source_file), str(target_dir), set(tags), gen_extra_measures |
| 101 | + ) |
85 | 102 | logging.error("The provided path is not taking to a JSON file") |
86 | 103 | sys.exit(1) |
0 commit comments