You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "nssalian (via GitHub)" <gi...@apache.org> on 2026/06/02 04:31:40 UTC

Re: [PR] Add CAST expression support to parser [iceberg-python]

nssalian commented on code in PR #3207:
URL: https://github.com/apache/iceberg-python/pull/3207#discussion_r3338699134


##########
pyiceberg/expressions/parser.py:
##########
@@ -265,7 +276,51 @@ def _evaluate_like_statement(result: ParseResults) -> BooleanExpression:
         return EqualTo(result.column, StringLiteral(literal_like.value.replace("\\%", "%")))
 
 
-predicate = (between | comparison | in_check | null_check | nan_check | starts_check | boolean).set_results_name("predicate")
+# CAST expression support: CAST(column AS type) maps to Iceberg transforms
+_CAST_TYPE_TO_TRANSFORM: dict[str, Transform[Any, Any]] = {
+    "date": DayTransform(),
+    "year": YearTransform(),
+    "month": MonthTransform(),
+    "hour": HourTransform(),
+}
+
+cast_type = Word(alphas, alphanums + "_")
+cast_term = Suppress(CAST) + Suppress("(") + column + Suppress(AS) + cast_type + Suppress(")")
+
+
+@cast_term.set_parse_action
+def _(result: ParseResults) -> UnboundTransform:
+    ref = result[0]
+    target = str(result[1]).lower()
+    if target not in _CAST_TYPE_TO_TRANSFORM:
+        raise ValueError(f"Unsupported CAST target type: {target}")
+    return UnboundTransform(ref, _CAST_TYPE_TO_TRANSFORM[target])
+
+
+cast_left_ref = cast_term + comparison_op + literal
+
+
+@cast_left_ref.set_parse_action

Review Comment:
   Done.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org