Skip to content

time part enum #159

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

Merged
merged 1 commit into from
Jun 26, 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
14 changes: 14 additions & 0 deletions uncoder-core/app/translator/core/custom_types/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ class TimeFrameType(CustomEnum):
days = "days"
hours = "hours"
minutes = "minutes"


class TimePartType(CustomEnum):
day = "day"
day_of_week = "day_of_week"
day_of_year = "day_of_year"
hour = "hour"
microsecond = "microsecond"
millisecond = "millisecond"
minute = "minute"
month = "month"
quarter = "quarter"
second = "second"
year = "year"
6 changes: 4 additions & 2 deletions uncoder-core/app/translator/core/exceptions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ class StrictPlatformException(BasePlatformException):
field_name: str = None

def __init__(
self, platform_name: str, field_name: str, mapping: str = None, detected_fields: Optional[list] = None
self, platform_name: str, field_name: str, mapping: Optional[str] = None, detected_fields: Optional[list] = None
):
message = (
f"Platform {platform_name} has strict mapping. "
f"Source fields: {', '.join(detected_fields) if detected_fields else field_name} has no mapping."
f" Mapping file: {mapping}." if mapping else ""
f" Mapping file: {mapping}."
if mapping
else ""
)
self.field_name = field_name
super().__init__(message)
Expand Down
10 changes: 4 additions & 6 deletions uncoder-core/app/translator/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,14 @@ def apply_token(self, token: Union[FieldValue, Keyword, Identifier], source_mapp

def generate_query(self, tokens: list[TOKEN_TYPE], source_mapping: SourceMapping) -> str:
result_values = []
not_found_mapping_fields = set()
unmapped_fields = set()
for token in tokens:
try:
result_values.append(self.apply_token(token=token, source_mapping=source_mapping))
except StrictPlatformException as err:
not_found_mapping_fields.add(err.field_name)
if not_found_mapping_fields:
raise StrictPlatformException(
self.details.name, "", source_mapping.source_id, sorted(list(not_found_mapping_fields))
)
unmapped_fields.add(err.field_name)
if unmapped_fields:
raise StrictPlatformException(self.details.name, "", source_mapping.source_id, sorted(unmapped_fields))
return "".join(result_values)

def wrap_query_with_meta_info(self, meta_info: MetaInfoContainer, query: str) -> str:
Expand Down
Loading