acryl-datahub 1.2.0.10rc4__py3-none-any.whl → 1.2.0.10rc5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of acryl-datahub might be problematic. Click here for more details.

datahub/sdk/chart.py CHANGED
@@ -10,6 +10,8 @@ import datahub.metadata.schema_classes as models
10
10
  from datahub.emitter.enum_helpers import get_enum_options
11
11
  from datahub.metadata.urns import ChartUrn, DatasetUrn, Urn
12
12
  from datahub.sdk._shared import (
13
+ ActorUrnOrStr,
14
+ ChangeAuditStampsMixin,
13
15
  DataPlatformInstanceUrnOrStr,
14
16
  DataPlatformUrnOrStr,
15
17
  DatasetUrnOrStr,
@@ -34,6 +36,7 @@ from datahub.utilities.sentinels import Unset, unset
34
36
 
35
37
 
36
38
  class Chart(
39
+ ChangeAuditStampsMixin,
37
40
  HasPlatformInstance,
38
41
  HasSubtype,
39
42
  HasOwnership,
@@ -70,6 +73,11 @@ class Chart(
70
73
  chart_url: Optional[str] = None,
71
74
  custom_properties: Optional[Dict[str, str]] = None,
72
75
  last_modified: Optional[datetime] = None,
76
+ last_modified_by: Optional[ActorUrnOrStr] = None,
77
+ created_at: Optional[datetime] = None,
78
+ created_by: Optional[ActorUrnOrStr] = None,
79
+ deleted_on: Optional[datetime] = None,
80
+ deleted_by: Optional[ActorUrnOrStr] = None,
73
81
  last_refreshed: Optional[datetime] = None,
74
82
  chart_type: Optional[Union[str, models.ChartTypeClass]] = None,
75
83
  access: Optional[str] = None,
@@ -94,13 +102,60 @@ class Chart(
94
102
  self._set_extra_aspects(extra_aspects)
95
103
 
96
104
  self._set_platform_instance(platform, platform_instance)
97
-
98
105
  self._ensure_chart_props(display_name=display_name)
106
+ self._init_chart_properties(
107
+ description,
108
+ display_name,
109
+ external_url,
110
+ chart_url,
111
+ custom_properties,
112
+ last_modified,
113
+ last_modified_by,
114
+ created_at,
115
+ created_by,
116
+ last_refreshed,
117
+ deleted_on,
118
+ deleted_by,
119
+ chart_type,
120
+ access,
121
+ input_datasets,
122
+ )
123
+ self._init_standard_aspects(
124
+ parent_container, subtype, owners, links, tags, terms, domain
125
+ )
99
126
 
100
- if display_name is not None:
101
- self.set_display_name(display_name)
127
+ @classmethod
128
+ def _new_from_graph(cls, urn: Urn, current_aspects: models.AspectBag) -> Self:
129
+ assert isinstance(urn, ChartUrn)
130
+ entity = cls(
131
+ platform=urn.dashboard_tool,
132
+ name=urn.chart_id,
133
+ )
134
+ return entity._init_from_graph(current_aspects)
135
+
136
+ def _init_chart_properties(
137
+ self,
138
+ description: Optional[str],
139
+ display_name: Optional[str],
140
+ external_url: Optional[str],
141
+ chart_url: Optional[str],
142
+ custom_properties: Optional[Dict[str, str]],
143
+ last_modified: Optional[datetime],
144
+ last_modified_by: Optional[ActorUrnOrStr],
145
+ created_at: Optional[datetime],
146
+ created_by: Optional[ActorUrnOrStr],
147
+ last_refreshed: Optional[datetime],
148
+ deleted_on: Optional[datetime],
149
+ deleted_by: Optional[ActorUrnOrStr],
150
+ chart_type: Optional[Union[str, models.ChartTypeClass]],
151
+ access: Optional[str],
152
+ input_datasets: Optional[Sequence[Union[DatasetUrnOrStr, Dataset]]],
153
+ ) -> None:
154
+ """Initialize chart-specific properties."""
102
155
  if description is not None:
103
156
  self.set_description(description)
157
+ if display_name is not None:
158
+ self.set_display_name(display_name)
104
159
  if external_url is not None:
105
160
  self.set_external_url(external_url)
106
161
  if chart_url is not None:
@@ -109,6 +164,16 @@ class Chart(
109
164
  self.set_custom_properties(custom_properties)
110
165
  if last_modified is not None:
111
166
  self.set_last_modified(last_modified)
167
+ if last_modified_by is not None:
168
+ self.set_last_modified_by(last_modified_by)
169
+ if created_at is not None:
170
+ self.set_created_at(created_at)
171
+ if created_by is not None:
172
+ self.set_created_by(created_by)
173
+ if deleted_on is not None:
174
+ self.set_deleted_on(deleted_on)
175
+ if deleted_by is not None:
176
+ self.set_deleted_by(deleted_by)
112
177
  if last_refreshed is not None:
113
178
  self.set_last_refreshed(last_refreshed)
114
179
  if chart_type is not None:
@@ -118,6 +183,17 @@ class Chart(
118
183
  if input_datasets is not None:
119
184
  self.set_input_datasets(input_datasets)
120
185
 
186
+ def _init_standard_aspects(
187
+ self,
188
+ parent_container: ParentContainerInputType | Unset,
189
+ subtype: Optional[str],
190
+ owners: Optional[OwnersInputType],
191
+ links: Optional[LinksInputType],
192
+ tags: Optional[TagsInputType],
193
+ terms: Optional[TermsInputType],
194
+ domain: Optional[DomainInputType],
195
+ ) -> None:
196
+ """Initialize standard aspects."""
121
197
  if parent_container is not unset:
122
198
  self._set_container(parent_container)
123
199
  if subtype is not None:
@@ -133,15 +209,6 @@ class Chart(
133
209
  if domain is not None:
134
210
  self.set_domain(domain)
135
211
 
136
- @classmethod
137
- def _new_from_graph(cls, urn: Urn, current_aspects: models.AspectBag) -> Self:
138
- assert isinstance(urn, ChartUrn)
139
- entity = cls(
140
- platform=urn.dashboard_tool,
141
- name=urn.chart_id,
142
- )
143
- return entity._init_from_graph(current_aspects)
144
-
145
212
  @property
146
213
  def urn(self) -> ChartUrn:
147
214
  assert isinstance(self._urn, ChartUrn)
@@ -159,6 +226,14 @@ class Chart(
159
226
  )
160
227
  )
161
228
 
229
+ def _get_audit_stamps(self) -> models.ChangeAuditStampsClass:
230
+ """Get the audit stamps from the chart properties."""
231
+ return self._ensure_chart_props().lastModified
232
+
233
+ def _set_audit_stamps(self, audit_stamps: models.ChangeAuditStampsClass) -> None:
234
+ """Set the audit stamps on the chart properties."""
235
+ self._ensure_chart_props().lastModified = audit_stamps
236
+
162
237
  @property
163
238
  def name(self) -> str:
164
239
  """Get the name of the chart."""
@@ -220,24 +295,6 @@ class Chart(
220
295
  """Set the custom properties of the chart."""
221
296
  self._ensure_chart_props().customProperties = custom_properties
222
297
 
223
- @property
224
- def last_modified(self) -> Optional[datetime]:
225
- """Get the last modification timestamp of the chart."""
226
- last_modified_time = self._ensure_chart_props().lastModified.lastModified.time
227
- if not last_modified_time:
228
- return None
229
- return datetime.fromtimestamp(last_modified_time)
230
-
231
- def set_last_modified(self, last_modified: datetime) -> None:
232
- """Set the last modification timestamp of the chart."""
233
- chart_props = self._ensure_chart_props()
234
- chart_props.lastModified = models.ChangeAuditStampsClass(
235
- lastModified=models.AuditStampClass(
236
- time=int(last_modified.timestamp()),
237
- actor="urn:li:corpuser:datahub",
238
- )
239
- )
240
-
241
298
  @property
242
299
  def last_refreshed(self) -> Optional[datetime]:
243
300
  """Get the last refresh timestamp of the chart."""
datahub/sdk/dashboard.py CHANGED
@@ -9,6 +9,8 @@ from typing_extensions import Self
9
9
  import datahub.metadata.schema_classes as models
10
10
  from datahub.metadata.urns import ChartUrn, DashboardUrn, DatasetUrn, Urn
11
11
  from datahub.sdk._shared import (
12
+ ActorUrnOrStr,
13
+ ChangeAuditStampsMixin,
12
14
  ChartUrnOrStr,
13
15
  DashboardUrnOrStr,
14
16
  DataPlatformInstanceUrnOrStr,
@@ -36,6 +38,7 @@ from datahub.utilities.sentinels import Unset, unset
36
38
 
37
39
 
38
40
  class Dashboard(
41
+ ChangeAuditStampsMixin,
39
42
  HasPlatformInstance,
40
43
  HasSubtype,
41
44
  HasOwnership,
@@ -72,6 +75,11 @@ class Dashboard(
72
75
  dashboard_url: Optional[str] = None,
73
76
  custom_properties: Optional[Dict[str, str]] = None,
74
77
  last_modified: Optional[datetime] = None,
78
+ last_modified_by: Optional[ActorUrnOrStr] = None,
79
+ created_at: Optional[datetime] = None,
80
+ created_by: Optional[ActorUrnOrStr] = None,
81
+ deleted_on: Optional[datetime] = None,
82
+ deleted_by: Optional[ActorUrnOrStr] = None,
75
83
  last_refreshed: Optional[datetime] = None,
76
84
  input_datasets: Optional[Sequence[Union[DatasetUrnOrStr, Dataset]]] = None,
77
85
  charts: Optional[Sequence[Union[ChartUrnOrStr, Chart]]] = None,
@@ -96,17 +104,48 @@ class Dashboard(
96
104
  self._set_extra_aspects(extra_aspects)
97
105
 
98
106
  self._set_platform_instance(platform, platform_instance)
107
+ self._ensure_dashboard_props(display_name=display_name)
108
+
109
+ self._init_dashboard_properties(
110
+ description,
111
+ display_name,
112
+ external_url,
113
+ dashboard_url,
114
+ custom_properties,
115
+ last_modified,
116
+ last_modified_by,
117
+ created_at,
118
+ created_by,
119
+ last_refreshed,
120
+ deleted_on,
121
+ deleted_by,
122
+ input_datasets,
123
+ charts,
124
+ dashboards,
125
+ )
126
+ self._init_standard_aspects(
127
+ parent_container, subtype, owners, links, tags, terms, domain
128
+ )
99
129
 
100
- # Initialize DashboardInfoClass with default values
101
- dashboard_info = self._ensure_dashboard_props(display_name=display_name)
102
- if last_modified:
103
- dashboard_info.lastModified = models.ChangeAuditStampsClass(
104
- lastModified=models.AuditStampClass(
105
- time=int(last_modified.timestamp()),
106
- actor="urn:li:corpuser:datahub",
107
- ),
108
- )
109
-
130
+ def _init_dashboard_properties(
131
+ self,
132
+ description: Optional[str],
133
+ display_name: Optional[str],
134
+ external_url: Optional[str],
135
+ dashboard_url: Optional[str],
136
+ custom_properties: Optional[Dict[str, str]],
137
+ last_modified: Optional[datetime],
138
+ last_modified_by: Optional[ActorUrnOrStr],
139
+ created_at: Optional[datetime],
140
+ created_by: Optional[ActorUrnOrStr],
141
+ last_refreshed: Optional[datetime],
142
+ deleted_on: Optional[datetime],
143
+ deleted_by: Optional[ActorUrnOrStr],
144
+ input_datasets: Optional[Sequence[Union[DatasetUrnOrStr, Dataset]]],
145
+ charts: Optional[Sequence[Union[ChartUrnOrStr, Chart]]],
146
+ dashboards: Optional[Sequence[Union[DashboardUrnOrStr, Dashboard]]],
147
+ ) -> None:
148
+ """Initialize dashboard-specific properties."""
110
149
  if description is not None:
111
150
  self.set_description(description)
112
151
  if display_name is not None:
@@ -119,6 +158,16 @@ class Dashboard(
119
158
  self.set_custom_properties(custom_properties)
120
159
  if last_modified is not None:
121
160
  self.set_last_modified(last_modified)
161
+ if last_modified_by is not None:
162
+ self.set_last_modified_by(last_modified_by)
163
+ if created_at is not None:
164
+ self.set_created_at(created_at)
165
+ if created_by is not None:
166
+ self.set_created_by(created_by)
167
+ if deleted_on is not None:
168
+ self.set_deleted_on(deleted_on)
169
+ if deleted_by is not None:
170
+ self.set_deleted_by(deleted_by)
122
171
  if last_refreshed is not None:
123
172
  self.set_last_refreshed(last_refreshed)
124
173
  if input_datasets is not None:
@@ -128,6 +177,17 @@ class Dashboard(
128
177
  if dashboards is not None:
129
178
  self.set_dashboards(dashboards)
130
179
 
180
+ def _init_standard_aspects(
181
+ self,
182
+ parent_container: ParentContainerInputType | Unset,
183
+ subtype: Optional[str],
184
+ owners: Optional[OwnersInputType],
185
+ links: Optional[LinksInputType],
186
+ tags: Optional[TagsInputType],
187
+ terms: Optional[TermsInputType],
188
+ domain: Optional[DomainInputType],
189
+ ) -> None:
190
+ """Initialize standard aspects."""
131
191
  if parent_container is not unset:
132
192
  self._set_container(parent_container)
133
193
  if subtype is not None:
@@ -165,16 +225,20 @@ class Dashboard(
165
225
  models.DashboardInfoClass(
166
226
  title=display_name or self.urn.dashboard_id,
167
227
  description="",
168
- lastModified=models.ChangeAuditStampsClass(
169
- lastModified=models.AuditStampClass(
170
- time=0, actor="urn:li:corpuser:unknown"
171
- )
172
- ),
228
+ lastModified=models.ChangeAuditStampsClass(),
173
229
  customProperties={},
174
230
  dashboards=[],
175
231
  )
176
232
  )
177
233
 
234
+ def _get_audit_stamps(self) -> models.ChangeAuditStampsClass:
235
+ """Get the audit stamps from the dashboard properties."""
236
+ return self._ensure_dashboard_props().lastModified
237
+
238
+ def _set_audit_stamps(self, audit_stamps: models.ChangeAuditStampsClass) -> None:
239
+ """Set the audit stamps on the dashboard properties."""
240
+ self._ensure_dashboard_props().lastModified = audit_stamps
241
+
178
242
  @property
179
243
  def name(self) -> str:
180
244
  """Get the name of the dashboard."""
@@ -238,23 +302,6 @@ class Dashboard(
238
302
  """Set the custom properties of the dashboard."""
239
303
  self._ensure_dashboard_props().customProperties = custom_properties
240
304
 
241
- @property
242
- def last_modified(self) -> Optional[datetime]:
243
- """Get the last modification timestamp of the dashboard."""
244
- props = self._ensure_dashboard_props()
245
- if props.lastModified.lastModified.time == 0:
246
- return None
247
- return datetime.fromtimestamp(props.lastModified.lastModified.time)
248
-
249
- def set_last_modified(self, last_modified: datetime) -> None:
250
- """Set the last modification timestamp of the dashboard."""
251
- self._ensure_dashboard_props().lastModified = models.ChangeAuditStampsClass(
252
- lastModified=models.AuditStampClass(
253
- time=int(last_modified.timestamp()),
254
- actor="urn:li:corpuser:datahub",
255
- ),
256
- )
257
-
258
305
  @property
259
306
  def last_refreshed(self) -> Optional[datetime]:
260
307
  """Get the last refresh timestamp of the dashboard."""