carloea2 commented on code in PR #5603:
URL: https://github.com/apache/texera/pull/5603#discussion_r3417912738


##########
amber/src/main/python/core/models/schema/attribute_type.py:
##########
@@ -78,6 +81,53 @@ class AttributeType(Enum):
 }
 
 
+FROM_STRING_PARSER_MAPPING = {
+    AttributeType.STRING: str,
+    AttributeType.INT: lambda v: (
+        0 if v is None or (isinstance(v, str) and v.strip() == "") else int(v)
+    ),
+    AttributeType.LONG: lambda v: (
+        0 if v is None or (isinstance(v, str) and v.strip() == "") else int(v)
+    ),
+    AttributeType.DOUBLE: lambda v: (
+        0.0 if v is None or (isinstance(v, str) and v.strip() == "") else 
float(v)
+    ),
+    AttributeType.BOOL: lambda v: (
+        False
+        if v is None or (isinstance(v, str) and v.strip() == "")
+        else (
+            True
+            if str(v).strip().lower() == "true"
+            else (
+                False
+                if str(v).strip().lower() == "false"
+                else float(str(v).strip()) != 0
+            )
+        )
+    ),
+    AttributeType.BINARY: lambda v: (
+        (_ for _ in ()).throw(
+            ValueError(
+                "UiParameter does not support BINARY values. "
+                "Use a supported type instead."
+            )
+        )
+    ),
+    AttributeType.TIMESTAMP: lambda v: (
+        datetime.datetime.fromtimestamp(0)
+        if v is None or (isinstance(v, str) and v.strip() == "")
+        else datetime.datetime.fromisoformat(v)

Review Comment:
   Done. _parse_timestamp now normalizes trailing Z to +00:00 before 
fromisoformat, and there is a test covering the Z timestamp case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to