AdamGS commented on code in PR #20071:
URL: https://github.com/apache/datafusion/pull/20071#discussion_r3250815183
##########
datafusion/physical-expr-adapter/src/schema_rewriter.rs:
##########
@@ -82,6 +83,30 @@ where
.data()
}
+/// Replace occurrences of a nullary scalar UDF in projection expressions with
a literal value.
+///
+/// This is useful at file-scan time where certain functions (such as
`input_file_name()`)
+/// can be replaced with per-file constant values once the current file is
known.
+pub fn replace_nullary_udf_with_literal_in_projection(
+ projection: ProjectionExprs,
+ udf_name: &str,
+ value: ScalarValue,
+) -> Result<ProjectionExprs> {
+ let literal_expr = expressions::lit(value);
+ projection.try_map_exprs(|expr| {
+ expr.transform_down(|expr| {
+ if let Some(func) =
expr.as_any().downcast_ref::<ScalarFunctionExpr>()
+ && func.fun().name() == udf_name
Review Comment:
I think its more robust to do `ScalarFunctionExpr::try_downcast_func` here,
in case of a name collision with another UDF
--
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]