From aa92a99130b1636d25d104a6e645066bda78242c Mon Sep 17 00:00:00 2001 From: sid-acryl <155424659+sid-acryl@users.noreply.github.com> Date: Fri, 12 Jul 2024 13:17:53 +0530 Subject: [PATCH] fix(ingestion/looker): column name missing in explore (#10892) --- .../ingestion/source/looker/looker_common.py | 34 +++++++------------ .../ingestion/source/looker/lookml_config.py | 2 +- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/metadata-ingestion/src/datahub/ingestion/source/looker/looker_common.py b/metadata-ingestion/src/datahub/ingestion/source/looker/looker_common.py index ce135f90e828b5..1f54767de5a68b 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/looker/looker_common.py +++ b/metadata-ingestion/src/datahub/ingestion/source/looker/looker_common.py @@ -347,26 +347,20 @@ def _form_field_name( model_name: str, upstream_views_file_path: Dict[str, Optional[str]], config: LookerCommonConfig, + remove_variant: bool = False, ) -> Optional[ColumnRef]: assert self.field.name is not None if len(self.field.name.split(".")) != 2: return None # Inconsistent info received - assert self.explore.name - - view_name: Optional[str] = ( - self.explore.name - if self.field.original_view is not None - else self.field.original_view - ) + view_name: Optional[str] = self.explore.name + if self.field.original_view is not None: + view_name = self.field.original_view field_name = self.field.name.split(".")[1] - if ( - self.field.field_group_variant is not None - and self.field.field_group_variant.lower() in field_name.lower() - ): + if remove_variant and self.field.field_group_variant is not None: # remove variant at the end. +1 for "_" field_name = field_name[ : -(len(self.field.field_group_variant.lower()) + 1) @@ -381,7 +375,7 @@ def _form_field_name( file_path: Optional[str] = ( upstream_views_file_path.get(view_name) - if upstream_views_file_path.get(view_name) is not None + if upstream_views_file_path.get(view_name) else ViewFieldValue.NOT_AVAILABLE.value ) @@ -413,7 +407,7 @@ def upstream( ) -> Optional[ColumnRef]: assert self.field.name is not None - if self.field.dimension_group is None: # It is not part of Dimensional Group + if self.field.dimension_group is None or self.field.field_group_variant is None: return self._form_field_name( view_project_map, explore_project_name, @@ -422,15 +416,6 @@ def upstream( config, ) - if self.field.field_group_variant is None: - return self._form_field_name( - view_project_map, - explore_project_name, - model_name, - upstream_views_file_path, - config, - ) # Variant i.e. Month, Day, Year ... is not available - if self.field.type is None or not self.field.type.startswith("date_"): return self._form_field_name( view_project_map, @@ -456,6 +441,7 @@ def upstream( model_name, upstream_views_file_path, config, + remove_variant=True, ) @@ -999,12 +985,15 @@ def from_api( # noqa: C901 view_fields: List[ViewField] = [] field_name_vs_raw_explore_field: Dict = {} + if explore.fields is not None: + if explore.fields.dimensions is not None: for dim_field in explore.fields.dimensions: if dim_field.name is None: continue else: + field_name_vs_raw_explore_field[dim_field.name] = dim_field view_fields.append( @@ -1045,6 +1034,7 @@ def from_api( # noqa: C901 if measure_field.name is None: continue else: + field_name_vs_raw_explore_field[ measure_field.name ] = measure_field diff --git a/metadata-ingestion/src/datahub/ingestion/source/looker/lookml_config.py b/metadata-ingestion/src/datahub/ingestion/source/looker/lookml_config.py index 937c75b7eaf35a..aa5719547c03ed 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/looker/lookml_config.py +++ b/metadata-ingestion/src/datahub/ingestion/source/looker/lookml_config.py @@ -121,7 +121,7 @@ class LookMLSourceConfig( AllowDenyPattern.allow_all(), description="List of regex patterns for LookML views to include in the extraction.", ) - parse_table_names_from_sql: bool = Field(False, description="See note below.") + parse_table_names_from_sql: bool = Field(True, description="See note below.") sql_parser: str = Field( "datahub.utilities.sql_parser.DefaultSQLParser", description="See note below." )