Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add duplication validation logic in DataTransformManager #126

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/spaceone/dashboard/error/data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ class ERROR_NOT_GLOBAL_VARIABLE_KEY(ERROR_INVALID_ARGUMENT):

class ERROR_NO_FIELDS_TO_GLOBAL_VARIABLES(ERROR_INVALID_ARGUMENT):
_message = "There is no fields in GLOBAL_VARIABLES. (vars = {vars})"


class ERROR_DUPLICATED_FIELD_NAME(ERROR_INVALID_ARGUMENT):
_message = (
"The variable to be created is duplicated. (field = {field}, fields = {fields})"
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ERROR_REQUIRED_PARAMETER,
ERROR_DUPLICATED_DATA_FIELDS,
ERROR_INVALID_PARAMETER_TYPE,
ERROR_DUPLICATED_FIELD_NAME,
)
from spaceone.dashboard.manager.data_table_manager import DataTableManager, GRANULARITY
from spaceone.dashboard.manager.data_table_manager.data_source_manager import (
Expand Down Expand Up @@ -279,6 +280,11 @@ def evaluate_data_table(
if name is None:
raise ERROR_REQUIRED_PARAMETER(key="options.EVAL.expressions.name")

if name in self.data_keys or name in self.label_keys:
raise ERROR_DUPLICATED_FIELD_NAME(
field=name, fields=list(df.columns)
)

if value_expression is None:
raise ERROR_REQUIRED_PARAMETER(
key="options.EVAL.expressions.expression"
Expand Down Expand Up @@ -462,7 +468,11 @@ def value_mapping_data_table(

self.label_keys = list(data_table_vo.labels_info.keys())
self.data_keys = list(data_table_vo.data_info.keys())

name = self.options["name"]
if name in self.data_keys or name in self.label_keys:
raise ERROR_DUPLICATED_FIELD_NAME(field=name, fields=list(df.columns))

field_type = self.options.get("field_type", "LABEL")

filtered_df = self.filter_data(df, vars)
Expand Down
Loading