Skip to content

Commit fbae2d2

Browse files
fix the dataplex entity for multiple matches for bigquery uri (#192)
* fix the dataplex entity for multiple matches for bigquery uri * fix the dataplex entity for multiple matches for bigquery uri * incorporated review comments * updated loggers
1 parent d4d9e2f commit fbae2d2

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

clouddq/classes/dataplex_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def to_dict(self: DataplexEntity) -> dict:
174174
"dataPath": self.dataPath,
175175
"system": self.system,
176176
"format": self.format,
177-
"schema": self.schema,
177+
"schema": self.schema.to_dict(),
178178
"project_id": self.project_id,
179179
"location": self.location,
180180
"lake": self.lake,

clouddq/classes/dq_configs_cache.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,24 @@ def is_dataplex_entity(
534534
data_path=entity_uri.get_entity_id(),
535535
)
536536
logger.info(f"Retrieved Dataplex Entities:\n{pformat(dataplex_entities_match)}")
537-
if len(dataplex_entities_match) != 1:
537+
if len(dataplex_entities_match) == 0:
538538
logger.info(
539539
"Failed to retrieve Dataplex Metadata entry for "
540540
f"entity_uri '{entity_uri.complete_uri_string}' "
541541
f"with error:\n"
542-
f"{pformat(json.dumps(dataplex_entities_match))}\n\n"
542+
f"{pformat(json.dumps([entity.to_dict() for entity in dataplex_entities_match]))}\n\n"
543543
f"Parsed entity_uri configs:\n"
544544
f"{pformat(entity_uri.to_dict())}\n\n"
545545
)
546546
return False
547+
if len(dataplex_entities_match) > 1:
548+
logger.warning(
549+
"Unexpected number of Dataplex entities found for entity_uri \n"
550+
f"${entity_uri.complete_uri_string}:\n"
551+
f"${pformat([entity.to_dict() for entity in dataplex_entities_match])}. \n"
552+
f"Only one match is expected."
553+
)
554+
return False
547555
else:
548556
dataplex_entity = dataplex_entities_match[0]
549557
clouddq_entity = dq_entity.DqEntity.from_dataplex_entity(

clouddq/integration/dataplex/clouddq_dataplex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def list_dataplex_entities(
307307
if prefix:
308308
params.update({"filter": f"id=starts_with({prefix})"})
309309
if data_path:
310-
params.update({"filter": f"data_path=starts_with({data_path})"})
310+
params.update({"filter": f"data_path={data_path}"})
311311

312312
response_dict = {}
313313
response = self._client.list_entities(

tests/unit/test_dataplex_entity.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ def test_validate_dataplex_entity_to_dict(self, mock_valid_dataplex_input):
9090
schema = {"fields": [{"name": "column1", "type": "STRING", "mode": "REQUIRED"},
9191
{"name": "column2", "type": "STRING", "mode": "REQUIRED"}, # noqa: E127
9292
{"name": "column3", "type": "STRING", "mode": "REQUIRED"}, # noqa: E127
93-
{"name": "column4", "type": "TIMESTAMP", "mode": "REQUIRED"}]} # noqa: E127
93+
{"name": "column4", "type": "TIMESTAMP", "mode": "REQUIRED"}],
94+
"partitionFields": None,
95+
"partitionStyle": None
96+
} # noqa: E127
9497

9598
dataplex_entity_expected = {
9699
"name": name,
@@ -103,7 +106,7 @@ def test_validate_dataplex_entity_to_dict(self, mock_valid_dataplex_input):
103106
"dataPath": "projects/project-id/datasets/bigquery_dataset_id/tables/table_name",
104107
"system": "BIGQUERY",
105108
"format": {"format": "OTHER"},
106-
"schema": DataplexEntitySchema.from_dict(entity_id=name, kwargs=schema),
109+
"schema": schema,
107110
"project_id": "project-id",
108111
"location": "location-id",
109112
"lake": "lake_name",
@@ -122,7 +125,10 @@ def test_validate_dataplex_entity_to_dict_no_format(self, mock_valid_dataplex_in
122125
schema = {"fields": [{"name": "column1", "type": "STRING", "mode": "REQUIRED"},
123126
{"name": "column2", "type": "STRING", "mode": "REQUIRED"}, # noqa: E127
124127
{"name": "column3", "type": "STRING", "mode": "REQUIRED"}, # noqa: E127
125-
{"name": "column4", "type": "TIMESTAMP", "mode": "REQUIRED"}]} # noqa: E127
128+
{"name": "column4", "type": "TIMESTAMP", "mode": "REQUIRED"}],
129+
"partitionFields": None,
130+
"partitionStyle": None
131+
} # noqa: E127
126132

127133
dataplex_entity_expected = {
128134
"name": name,
@@ -135,7 +141,7 @@ def test_validate_dataplex_entity_to_dict_no_format(self, mock_valid_dataplex_in
135141
"dataPath": "projects/project-id/datasets/bigquery_dataset_id/tables/table_name",
136142
"system": "BIGQUERY",
137143
"format": None,
138-
"schema": DataplexEntitySchema.from_dict(entity_id=name, kwargs=schema),
144+
"schema": schema,
139145
"project_id": "project-id",
140146
"location": "location-id",
141147
"lake": "lake_name",

0 commit comments

Comments
 (0)