Skip to content

Commit 4ff882b

Browse files
committed
handling both old and new response for to_viz
1 parent 353eb45 commit 4ff882b

12 files changed

+91
-30
lines changed

ads/feature_store/execution_strategy/spark/spark_execution.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ def __init__(self, metastore_id: str = None):
7777
self._jvm = self._spark_context._jvm
7878

7979
def ingest_feature_definition(
80-
self,
81-
feature_group: "FeatureGroup",
82-
feature_group_job: FeatureGroupJob,
83-
dataframe,
80+
self,
81+
feature_group: "FeatureGroup",
82+
feature_group_job: FeatureGroupJob,
83+
dataframe,
8484
):
8585
try:
8686
self._save_offline_dataframe(dataframe, feature_group, feature_group_job)
@@ -94,7 +94,7 @@ def ingest_dataset(self, dataset, dataset_job: DatasetJob):
9494
raise SparkExecutionException(e).with_traceback(e.__traceback__)
9595

9696
def delete_feature_definition(
97-
self, feature_group: "FeatureGroup", feature_group_job: FeatureGroupJob
97+
self, feature_group: "FeatureGroup", feature_group_job: FeatureGroupJob
9898
):
9999
"""
100100
Deletes a feature definition from the system.
@@ -188,7 +188,7 @@ def _validate_expectation(expectation_type, validation_output: dict):
188188
raise Exception(error_message)
189189

190190
def _save_offline_dataframe(
191-
self, data_frame, feature_group, feature_group_job: FeatureGroupJob
191+
self, data_frame, feature_group, feature_group_job: FeatureGroupJob
192192
):
193193
"""Ingest dataframe to the feature store system. as now this handles both spark dataframe and pandas
194194
dataframe. in case of pandas after transformation we convert it to spark and write to the delta.
@@ -211,6 +211,7 @@ def _save_offline_dataframe(
211211
feature_statistics = None
212212
validation_output = None
213213
output_features = []
214+
version = 2 # after MLM upgrade
214215

215216
try:
216217
# Create database in hive metastore if not exist
@@ -312,6 +313,7 @@ def _save_offline_dataframe(
312313
"validation_output": str(validation_output) if validation_output else None,
313314
"commit_id": "commit_id",
314315
"feature_statistics": feature_statistics,
316+
"version": version
315317
}
316318

317319
self._update_job_and_parent_details(
@@ -460,7 +462,7 @@ def _save_dataset_input(self, dataset, dataset_job: DatasetJob):
460462

461463
@staticmethod
462464
def _update_job_and_parent_details(
463-
parent_entity, job_entity, output_features=None, output_details=None
465+
parent_entity, job_entity, output_features=None, output_details=None
464466
):
465467
"""
466468
Updates the parent and job entities with relevant details.

ads/feature_store/feature_group.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,12 @@ def get_statistics(self, job_id: str = None) -> "Statistics":
13481348
feature_statistics = (
13491349
output_details.get("featureStatistics") if output_details else None
13501350
)
1351-
return Statistics(feature_statistics)
1351+
stat_version = (
1352+
output_details.get("version") if output_details else None
1353+
)
1354+
version = stat_version if stat_version is not None else 1
1355+
1356+
return Statistics(feature_statistics, version)
13521357

13531358
def get_validation_output(self, job_id: str = None) -> "ValidationOutput":
13541359
"""Retrieve validation report for the job with job_id

ads/feature_store/response/response_builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ResponseBuilder(Builder):
1212

1313
CONST_CONTENT = "content"
1414

15-
def __init__(self, content: str):
15+
def __init__(self, content: str, version: int = 1):
1616
"""
1717
Initializes a new instance of the validation output class.
1818
@@ -21,6 +21,7 @@ def __init__(self, content: str):
2121
content : str
2222
The validation output information as a JSON string.
2323
"""
24+
self.version = version
2425
super().__init__()
2526
self.set_spec(self.CONST_CONTENT, content)
2627

ads/feature_store/statistics/abs_feature_value.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ def __validate__(self):
2828

2929
@classmethod
3030
@abstractmethod
31-
def __from_json__(cls, json_dict: dict):
31+
def __from_json__(cls, json_dict: dict, version: int):
32+
pass
33+
34+
@classmethod
35+
@abstractmethod
36+
def __from_json_v2__(cls, json_dict: dict):
3237
pass
3338

3439
@classmethod
3540
def from_json(
36-
cls, json_dict: dict, ignore_errors: bool = False
41+
cls, json_dict: dict, version: int, ignore_errors: bool = False
3742
) -> Union["AbsFeatureValue", None]:
3843
try:
39-
return cls.__from_json__(json_dict=json_dict)
44+
return cls.__from_json__(json_dict=json_dict, version=version)
4045
except Exception as e:
4146
if ignore_errors:
4247
return None

ads/feature_store/statistics/charts/abstract_feature_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def add_to_figure(self, fig: Figure, xaxis: int, yaxis: int):
2424

2525
@classmethod
2626
@abstractmethod
27-
def __from_json__(cls, json_dict: dict):
27+
def __from_json__(cls, json_dict: dict, version: int):
2828
pass
2929

3030
@staticmethod

ads/feature_store/statistics/charts/box_plot.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,17 @@ def __init__(self, q1: float, q2: float, q3: float):
4444
super().__init__()
4545

4646
@classmethod
47-
def __from_json__(cls, json_dict: dict) -> "BoxPlot.Quartiles":
47+
def __from_json__(cls, json_dict: dict, version: int = 1) -> "BoxPlot.Quartiles":
48+
if version == 2:
49+
return cls.__from_json_v2__(json_dict)
50+
return cls(
51+
json_dict.get(cls.CONST_Q1),
52+
json_dict.get(cls.CONST_Q2),
53+
json_dict.get(cls.CONST_Q3),
54+
)
55+
56+
@classmethod
57+
def __from_json_v2__(cls, json_dict: dict) -> "BoxPlot.Quartiles":
4858
metric_data = json_dict.get(AbsFeatureValue.CONST_METRIC_DATA)
4959
return cls(
5060
metric_data[0],
@@ -126,12 +136,12 @@ def get_box_points_from_frequency_distribution(
126136
return []
127137

128138
@classmethod
129-
def __from_json__(cls, json_dict: dict) -> "BoxPlot":
130-
quartiles = cls.Quartiles.from_json(json_dict.get(cls.CONST_QUARTILES))
139+
def __from_json__(cls, json_dict: dict, version: int = 1) -> "BoxPlot":
140+
quartiles = cls.Quartiles.from_json(json_dict.get(cls.CONST_QUARTILES), version)
131141
return cls(
132-
mean=GenericFeatureValue.from_json(json_dict.get(cls.CONST_MEAN)).val,
142+
mean=GenericFeatureValue.from_json(json_dict.get(cls.CONST_MEAN),version).val,
133143
median=quartiles.q2,
134-
sd=GenericFeatureValue.from_json(json_dict.get(cls.CONST_SD)).val,
144+
sd=GenericFeatureValue.from_json(json_dict.get(cls.CONST_SD),version).val,
135145
q1=quartiles.q1,
136146
q3=quartiles.q3,
137147
box_points=json_dict.get(cls.CONST_BOX_POINTS),

ads/feature_store/statistics/charts/frequency_distribution.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,20 @@ def __init__(self, frequency: List, bins: List):
3030
def __validate__(self):
3131
assert type(self.frequency) == list
3232
assert type(self.bins) == list
33-
# assert 0 < len(self.frequency) == len(self.bins) > 0
33+
assert 0 < len(self.frequency)
34+
assert len(self.bins) > 0
3435

3536
@classmethod
36-
def __from_json__(cls, json_dict: dict) -> "FrequencyDistribution":
37+
def __from_json__(cls, json_dict: dict, version: int = 1) -> "FrequencyDistribution":
38+
if version == 2:
39+
return cls.__from_json_v2__(json_dict)
40+
return FrequencyDistribution(
41+
frequency=json_dict.get(cls.CONST_FREQUENCY),
42+
bins=json_dict.get(cls.CONST_BINS),
43+
)
44+
45+
@classmethod
46+
def __from_json_v2__(cls, json_dict: dict) -> "FrequencyDistribution":
3747
metric_data = json_dict.get(AbsFeatureValue.CONST_METRIC_DATA)
3848
return FrequencyDistribution(
3949
bins=metric_data[0],

ads/feature_store/statistics/charts/probability_distribution.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ def __validate__(self):
3333
# assert 0 < len(self.density) == len(self.bins) > 0
3434

3535
@classmethod
36-
def __from_json__(cls, json_dict: dict) -> "ProbabilityDistribution":
36+
def __from_json__(cls, json_dict: dict, version: int = 1) -> "ProbabilityDistribution":
37+
if version == 2:
38+
return cls.__from_json_v2__(json_dict)
39+
return cls(
40+
density=json_dict.get(ProbabilityDistribution.CONST_DENSITY),
41+
bins=json_dict.get(ProbabilityDistribution.CONST_BINS),
42+
)
43+
44+
@classmethod
45+
def __from_json_v2__(cls, json_dict: dict) -> "ProbabilityDistribution":
3746
metric_data = json_dict.get(AbsFeatureValue.CONST_METRIC_DATA)
3847
return cls(
3948
bins=metric_data[0],

ads/feature_store/statistics/charts/top_k_frequent_elements.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __validate__(self):
4444

4545
@classmethod
4646
def __from_json__(
47-
cls, json_dict: dict
47+
cls, json_dict: dict, version: int = 1
4848
) -> "TopKFrequentElements.TopKFrequentElement":
4949
return cls(
5050
value=json_dict.get(cls.CONST_VALUE),
@@ -64,7 +64,17 @@ def __validate__(self):
6464
assert 0 < len(self.values) == len(self.estimates) > 0
6565

6666
@classmethod
67-
def __from_json__(cls, json_dict: dict) -> "TopKFrequentElements":
67+
def __from_json__(cls, json_dict: dict, version: int = 1) -> "TopKFrequentElements":
68+
if version == 2:
69+
return cls.__from_json_v2__(json_dict)
70+
elements = json_dict.get(cls.CONST_VALUE)
71+
top_k_frequent_elements = [cls.TopKFrequentElement.__from_json__(element) for element in elements]
72+
values = [element.value for element in top_k_frequent_elements]
73+
estimates = [element.estimate for element in top_k_frequent_elements]
74+
return cls(values, estimates)
75+
76+
@classmethod
77+
def __from_json_v2__(cls, json_dict: dict) -> "TopKFrequentElements":
6878
metric_data = json_dict.get(AbsFeatureValue.CONST_METRIC_DATA)
6979
return cls(
7080
values=metric_data[0],

ads/feature_store/statistics/feature_stat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ def __init__(
5151
self.box_plot = box_plot
5252

5353
@classmethod
54-
def from_json(cls, feature_name: str, json_dict: dict) -> "FeatureStatistics":
54+
def from_json(cls, feature_name: str, json_dict: dict, version: int) -> "FeatureStatistics":
5555
if json_dict is not None:
5656
frequency_distribution = FrequencyDistribution.from_json(
57-
json_dict.get(cls.CONST_FREQUENCY_DISTRIBUTION), ignore_errors=True
57+
json_dict.get(cls.CONST_FREQUENCY_DISTRIBUTION), version, ignore_errors=True,
5858
)
5959

6060
# inject box points for boxplot creation
@@ -66,14 +66,14 @@ def from_json(cls, feature_name: str, json_dict: dict) -> "FeatureStatistics":
6666
return cls(
6767
feature_name,
6868
TopKFrequentElements.from_json(
69-
json_dict.get(cls.CONST_TOP_K_FREQUENT), ignore_errors=True
69+
json_dict.get(cls.CONST_TOP_K_FREQUENT), version, ignore_errors=True
7070
),
7171
frequency_distribution,
7272
ProbabilityDistribution.from_json(
73-
json_dict.get(cls.CONST_PROBABILITY_DISTRIBUTION),
73+
json_dict.get(cls.CONST_PROBABILITY_DISTRIBUTION), version,
7474
ignore_errors=True,
7575
),
76-
BoxPlot.from_json(json_dict, ignore_errors=True),
76+
BoxPlot.from_json(json_dict, version, ignore_errors=True),
7777
)
7878
else:
7979
return cls(feature_name)

0 commit comments

Comments
 (0)