Fokko commented on code in PR #3207:
URL: https://github.com/apache/iceberg-python/pull/3207#discussion_r3201376552
##########
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:
It looks like we've already copied this logic multiple times, should we
consolidate this:
https://github.com/apache/iceberg-python/blob/d008a04a7cf8ec6c73855285117dca1ad25b35d1/pyiceberg/expressions/parser.py#L161-L192
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]