Skip to content

Commit 24562c6

Browse files
anyalee0221anya-li
andauthored
Refactor the logic for source_metadata to be better readable. (#35370)
* Refactor source_metadata validation * Reorg the logic for source_metadata to be more readable. * update * minor * Minor --------- Co-authored-by: Anya Li <[email protected]>
1 parent 587da6f commit 24562c6

File tree

1 file changed

+35
-50
lines changed

1 file changed

+35
-50
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_feature_set/source_metadata.py

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,60 +25,45 @@ def __init__(
2525
dict: Optional[Dict] = None,
2626
**kwargs: Any,
2727
):
28-
if type != "featureset":
29-
if not timestamp_column:
30-
msg = f"You need to provide timestamp_column for {type} feature source."
31-
raise ValidationException(
32-
message=msg,
33-
no_personal_data_message=msg,
34-
error_type=ValidationErrorType.INVALID_VALUE,
35-
target=ErrorTarget.FEATURE_SET,
36-
error_category=ErrorCategory.USER_ERROR,
37-
)
38-
39-
if type != "custom":
40-
if type == "featureset":
41-
if not path:
42-
msg = f"You need to provide path for {type} feature source."
43-
raise ValidationException(
44-
message=msg,
45-
no_personal_data_message=msg,
46-
error_type=ValidationErrorType.INVALID_VALUE,
47-
target=ErrorTarget.FEATURE_SET,
48-
error_category=ErrorCategory.USER_ERROR,
49-
)
50-
if timestamp_column or source_delay or source_process_code:
51-
msg = f"Cannot provide timestamp_column/source_delay/source_process_code for {type} feature source."
52-
raise ValidationException(
53-
message=msg,
54-
no_personal_data_message=msg,
55-
error_type=ValidationErrorType.INVALID_VALUE,
56-
target=ErrorTarget.FEATURE_SET,
57-
error_category=ErrorCategory.USER_ERROR,
58-
)
59-
60-
if not (path and not dict and not source_process_code):
61-
msg = f"Cannot provide source_process_code or kwargs for {type} feature source."
62-
raise ValidationException(
63-
message=msg,
64-
no_personal_data_message=msg,
65-
error_type=ValidationErrorType.INVALID_VALUE,
66-
target=ErrorTarget.FEATURE_SET,
67-
error_category=ErrorCategory.USER_ERROR,
68-
)
28+
if type == "custom":
29+
# For custom feature source
30+
# Required: timestamp_column, dict and source_process_code.
31+
# Not support: path.
32+
if path:
33+
self.throw_exception("path", type, should_provide=False)
34+
if not (timestamp_column and dict and source_process_code):
35+
self.throw_exception("timestamp_column/dict/source_process_code", type, should_provide=True)
36+
elif type == "featureset":
37+
# For featureset feature source
38+
# Required: path.
39+
# Not support: timestamp_column, source_delay and source_process_code.
40+
if timestamp_column or source_delay or source_process_code:
41+
self.throw_exception("timestamp_column/source_delay/source_process_code", type, should_provide=False)
42+
if not path:
43+
self.throw_exception("path", type, should_provide=True)
6944
else:
70-
if not (dict and source_process_code and not path):
71-
msg = "You cannot provide path for custom feature source."
72-
raise ValidationException(
73-
message=msg,
74-
no_personal_data_message=msg,
75-
error_type=ValidationErrorType.INVALID_VALUE,
76-
target=ErrorTarget.FEATURE_SET,
77-
error_category=ErrorCategory.USER_ERROR,
78-
)
45+
# For other type feature source
46+
# Required: timestamp_column, path.
47+
# Not support: source_process_code, dict
48+
if dict or source_process_code:
49+
self.throw_exception("dict/source_process_code", type, should_provide=False)
50+
if not (timestamp_column and path):
51+
self.throw_exception("timestamp_column/path", type, should_provide=True)
7952
self.type = type
8053
self.path = path
8154
self.timestamp_column = timestamp_column
8255
self.source_delay = source_delay
8356
self.source_process_code = source_process_code
8457
self.kwargs = dict
58+
59+
@staticmethod
60+
def throw_exception(property_names: str, type: str, should_provide: bool):
61+
should_or_not = "need to" if should_provide else "cannot"
62+
msg = f"You {should_or_not} provide {property_names} for {type} feature source."
63+
raise ValidationException(
64+
message=msg,
65+
no_personal_data_message=msg,
66+
error_type=ValidationErrorType.INVALID_VALUE,
67+
target=ErrorTarget.FEATURE_SET,
68+
error_category=ErrorCategory.USER_ERROR,
69+
)

0 commit comments

Comments
 (0)