Skip to content

Commit c5d8b2d

Browse files
fix: minor pr comments
1 parent 250b876 commit c5d8b2d

File tree

4 files changed

+27
-42
lines changed

4 files changed

+27
-42
lines changed

metadata-ingestion/src/datahub/ingestion/source/looker/looker_file_loader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import pathlib
33
from dataclasses import replace
4-
from typing import Dict, List, Optional
4+
from typing import Dict, Optional
55

66
from datahub.ingestion.source.looker.looker_config import LookerConnectionDefinition
77
from datahub.ingestion.source.looker.looker_dataclasses import (
@@ -33,7 +33,7 @@ def __init__(
3333
base_projects_folder: Dict[str, pathlib.Path],
3434
reporter: LookMLSourceReport,
3535
source_config: LookMLSourceConfig,
36-
manifest_constants: List[LookerConstant] = [],
36+
manifest_constants: Dict[str, LookerConstant] = {},
3737
) -> None:
3838
self.viewfile_cache: Dict[str, Optional[LookerViewFile]] = {}
3939
self._root_project_name = root_project_name

metadata-ingestion/src/datahub/ingestion/source/looker/looker_template_language.py

+11-26
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,18 @@ def resolve_liquid_variable(
105105
# Resolve liquid template
106106
return create_template(text).render(liquid_variable)
107107
except LiquidSyntaxError as e:
108-
report.info(
109-
title="Unsupported liquid template",
110-
message="There are some tag specific to looker and python-liquid library does not understand them. Currently we are not parsing such liquid template.",
111-
context=f"view-name: {view_name}, text: {text}, liquid_variable: {liquid_variable}",
112-
exc=e,
113-
)
108+
# TODO: Will add warning once we get rid of duplcate warning message for same view
109+
logger.warning(f"Unsupported liquid template encountered. error [{e.message}]")
114110
# TODO: There are some tag specific to looker and python-liquid library does not understand them. currently
115111
# we are not parsing such liquid template.
116112
#
117113
# See doc: https://cloud.google.com/looker/docs/templated-filters and look for { % condition region %}
118114
# order.region { % endcondition %}
119115
except CustomTagException as e:
120-
report.info(
121-
title="Unsupported liquid template",
122-
message="Rendering the Liquid template failed due to an issue with the provided variables or template syntax",
123-
context=f"view-name: {view_name}, text: {text}, liquid_variable: {liquid_variable}",
124-
exc=e,
125-
)
116+
# TODO: Will add warning once we get rid of duplcate warning message for same view
117+
logger.warning(e)
118+
logger.debug(e, exc_info=e)
119+
126120
return text
127121

128122

@@ -370,7 +364,7 @@ def __init__(
370364
self,
371365
source_config: LookMLSourceConfig,
372366
reporter: LookMLSourceReport,
373-
manifest_constants: List["LookerConstant"],
367+
manifest_constants: Dict[str, "LookerConstant"],
374368
):
375369
super().__init__(source_config=source_config, reporter=reporter)
376370
self.manifest_constants = manifest_constants
@@ -388,17 +382,8 @@ def replace_constants(match):
388382
return str(self.source_config.lookml_constants.get(key))
389383

390384
# Resolve constant from manifest
391-
if self.manifest_constants:
392-
value = next(
393-
(
394-
constant.value
395-
for constant in self.manifest_constants
396-
if constant.name == key
397-
),
398-
None,
399-
)
400-
if value:
401-
return value
385+
if key in self.manifest_constants:
386+
return self.manifest_constants[key].value
402387

403388
# Check if it's a misplaced lookml constant
404389
if key in self.source_config.liquid_variables:
@@ -479,7 +464,7 @@ def process_lookml_template_language(
479464
source_config: LookMLSourceConfig,
480465
view_lkml_file_dict: dict,
481466
reporter: LookMLSourceReport,
482-
manifest_constants: List["LookerConstant"] = [],
467+
manifest_constants: Dict[str, "LookerConstant"] = {},
483468
resolve_constants: bool = False,
484469
) -> None:
485470
if "views" not in view_lkml_file_dict:
@@ -522,7 +507,7 @@ def load_and_preprocess_file(
522507
path: Union[str, pathlib.Path],
523508
source_config: LookMLSourceConfig,
524509
reporter: LookMLSourceReport,
525-
manifest_constants: List["LookerConstant"] = [],
510+
manifest_constants: Dict[str, "LookerConstant"] = {},
526511
resolve_constants: bool = False,
527512
) -> dict:
528513
parsed = load_lkml(path)

metadata-ingestion/src/datahub/ingestion/source/looker/lookml_source.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def __init__(self, config: LookMLSourceConfig, ctx: PipelineContext):
311311
"manage_models permission enabled on this API key."
312312
) from err
313313

314-
self.manifest_constants: List[LookerConstant] = []
314+
self.manifest_constants: Dict[str, "LookerConstant"] = {}
315315

316316
def _load_model(self, path: str) -> LookerModel:
317317
logger.debug(f"Loading model from file {path}")
@@ -605,7 +605,7 @@ def _recursively_check_manifests(
605605
tmp_dir: str,
606606
project_name: str,
607607
project_visited: Set[str],
608-
manifest_constants: List[LookerConstant],
608+
manifest_constants: Dict[str, "LookerConstant"],
609609
) -> None:
610610
if project_name in project_visited:
611611
return
@@ -623,14 +623,13 @@ def _recursively_check_manifests(
623623
return
624624

625625
if manifest.constants:
626-
manifest_constants.extend(
627-
LookerConstant(
628-
name=constant["name"],
629-
value=constant["value"],
630-
)
631-
for constant in manifest.constants
632-
if constant.get("name") and constant.get("value")
633-
)
626+
for constant in manifest.constants:
627+
if constant.get("name") and constant.get("value"):
628+
manifest_constants[constant["name"]] = LookerConstant(
629+
name=constant["name"],
630+
value=constant["value"],
631+
)
632+
634633
# Special case handling if the root project has a name in the manifest file.
635634
if project_name == BASE_PROJECT_NAME and manifest.project_name:
636635
if (
@@ -710,6 +709,7 @@ def get_internal_workunits(self) -> Iterable[MetadataWorkUnit]: # noqa: C901
710709
self.source_config,
711710
self.manifest_constants,
712711
)
712+
logger.debug(f"LookML Constants : {', '.join(self.manifest_constants.keys())}")
713713

714714
# Some views can be mentioned by multiple 'include' statements and can be included via different connections.
715715

metadata-ingestion/tests/integration/lookml/test_lookml.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1083,10 +1083,10 @@ def test_lookml_constant_transformer(view, expected_result, warning_expected):
10831083
transformer = LookmlConstantTransformer(
10841084
source_config=config,
10851085
reporter=report,
1086-
manifest_constants=[
1087-
LookerConstant(name="constant1", value="manifest_value1"),
1088-
LookerConstant(name="constant3", value="manifest_value3"),
1089-
],
1086+
manifest_constants={
1087+
"constant1": LookerConstant(name="constant1", value="manifest_value1"),
1088+
"constant3": LookerConstant(name="constant3", value="manifest_value3"),
1089+
},
10901090
)
10911091

10921092
result = transformer.transform(view)

0 commit comments

Comments
 (0)