Skip to content

Commit eec1c87

Browse files
committed
Add modified timestamps to supersetdataset
1 parent 9b51b12 commit eec1c87

File tree

4 files changed

+59
-78
lines changed

4 files changed

+59
-78
lines changed

metadata-ingestion/src/datahub/ingestion/source/superset.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import logging
3-
from datetime import datetime, timezone
3+
from datetime import datetime
44
from functools import lru_cache
55
from typing import Any, Dict, Iterable, List, Optional
66

@@ -107,6 +107,18 @@ class SupersetDataset(BaseModel):
107107
changed_on_utc: Optional[str] = None
108108
explore_url: Optional[str] = ""
109109

110+
@property
111+
def modified_dt(self) -> Optional[datetime]:
112+
if self.changed_on_utc:
113+
return dp.parse(self.changed_on_utc)
114+
return None
115+
116+
@property
117+
def modified_ts(self) -> Optional[int]:
118+
if self.modified_dt:
119+
return int(self.modified_dt.timestamp() * 1000)
120+
return None
121+
110122

111123
class SupersetConfig(
112124
StatefulIngestionConfigBase, EnvConfigMixin, PlatformInstanceConfigMixin
@@ -149,6 +161,7 @@ class SupersetConfig(
149161
)
150162

151163
class Config:
164+
# This is required to allow preset configs to get parsed
152165
extra = "allow"
153166

154167
@validator("connect_uri", "display_uri")
@@ -219,7 +232,6 @@ def __init__(self, ctx: PipelineContext, config: SupersetConfig):
219232
graph=self.ctx.graph,
220233
)
221234
self.session = self.login()
222-
# Default to postgres field type mappings
223235

224236
def login(self) -> requests.Session:
225237
login_response = requests.post(
@@ -258,7 +270,6 @@ def create(cls, config_dict: dict, ctx: PipelineContext) -> Source:
258270
config = SupersetConfig.parse_obj(config_dict)
259271
return cls(ctx, config)
260272

261-
@lru_cache(maxsize=None)
262273
def paginate_entity_api_results(self, entity_type, page_size=100):
263274
current_page = 0
264275
total_items = page_size
@@ -336,7 +347,7 @@ def get_datasource_urn_from_id(
336347

337348
if database_id and table_name:
338349
return make_dataset_urn(
339-
platform=self.platform,
350+
platform=platform,
340351
name=".".join(
341352
name for name in [database_name, schema_name, table_name] if name
342353
),
@@ -585,18 +596,15 @@ def construct_dataset_from_dataset_data(
585596
datasource_urn = self.get_datasource_urn_from_id(
586597
dataset_response, self.platform
587598
)
588-
if dataset.changed_on_utc:
589-
modified_dt = dp.parse(dataset.changed_on_utc)
590-
else:
591-
modified_dt = datetime.now(timezone.utc)
592599

593-
modified_ts = int(modified_dt.timestamp() * 1000)
594600
dataset_url = f"{self.config.display_uri}{dataset.explore_url or ''}"
595601

596602
dataset_info = DatasetPropertiesClass(
597603
name=dataset.table_name,
598604
description="",
599-
lastModified=TimeStamp(time=modified_ts),
605+
lastModified=TimeStamp(time=dataset.modified_ts)
606+
if dataset.modified_ts
607+
else None,
600608
externalUrl=dataset_url,
601609
)
602610
aspects_items: List[Any] = []

metadata-ingestion/tests/integration/superset/golden_test_ingest.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"chartUrl": "mock://mock-domain.superset.com/explore/test_chart_url_10",
130130
"inputs": [
131131
{
132-
"string": "urn:li:dataset:(urn:li:dataPlatform:superset,test_database_name.test_schema_name.test_table_name,PROD)"
132+
"string": "urn:li:dataset:(urn:li:dataPlatform:external,test_database_name.test_schema_name.test_table_name,PROD)"
133133
}
134134
],
135135
"type": "BAR"
@@ -176,7 +176,7 @@
176176
"chartUrl": "mock://mock-domain.superset.com/explore/test_chart_url_11",
177177
"inputs": [
178178
{
179-
"string": "urn:li:dataset:(urn:li:dataPlatform:superset,test_database_name.test_schema_name.test_table_name,PROD)"
179+
"string": "urn:li:dataset:(urn:li:dataPlatform:external,test_database_name.test_schema_name.test_table_name,PROD)"
180180
}
181181
],
182182
"type": "PIE"
@@ -223,7 +223,7 @@
223223
"chartUrl": "mock://mock-domain.superset.com/explore/test_chart_url_12",
224224
"inputs": [
225225
{
226-
"string": "urn:li:dataset:(urn:li:dataPlatform:superset,test_database_name.test_schema_name.test_table_name,PROD)"
226+
"string": "urn:li:dataset:(urn:li:dataPlatform:external,test_database_name.test_schema_name.test_table_name,PROD)"
227227
}
228228
],
229229
"type": "AREA"
@@ -270,7 +270,7 @@
270270
"chartUrl": "mock://mock-domain.superset.com/explore/test_chart_url_13",
271271
"inputs": [
272272
{
273-
"string": "urn:li:dataset:(urn:li:dataPlatform:superset,test_database_name.test_schema_name.test_table_name,PROD)"
273+
"string": "urn:li:dataset:(urn:li:dataPlatform:external,test_database_name.test_schema_name.test_table_name,PROD)"
274274
}
275275
],
276276
"type": "HISTOGRAM"

0 commit comments

Comments
 (0)