sohardforaname commented on code in PR #18257:
URL: https://github.com/apache/doris/pull/18257#discussion_r1247497367


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/AliasUdfBuilder.java:
##########
@@ -0,0 +1,110 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.expressions.functions.udf;
+
+import org.apache.doris.common.util.ReflectionUtils;
+import org.apache.doris.nereids.rules.expression.rules.FunctionBinder;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.SlotReference;
+import org.apache.doris.nereids.trees.expressions.VirtualSlotReference;
+import org.apache.doris.nereids.trees.expressions.functions.BoundFunction;
+import 
org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.util.TypeCoercionUtils;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * alias function builder
+ */
+public class AliasUdfBuilder extends UdfBuilder {
+    private final AliasUdf aliasUdf;
+
+    public AliasUdfBuilder(AliasUdf aliasUdf) {
+        this.aliasUdf = aliasUdf;
+    }
+
+    @Override
+    public List<DataType> getArgTypes() {
+        return aliasUdf.getArgTypes();
+    }
+
+    @Override
+    public boolean canApply(List<?> arguments) {
+        if (arguments.size() != aliasUdf.arity()) {
+            return false;
+        }
+        for (Object argument : arguments) {
+            if (!(argument instanceof Expression)) {
+                Optional<Class> primitiveType = 
ReflectionUtils.getPrimitiveType(argument.getClass());
+                if (!primitiveType.isPresent() || 
!Expression.class.isAssignableFrom(primitiveType.get())) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public BoundFunction build(String name, List<?> arguments) {
+        // use AliasFunction to process TypeCoercion
+        BoundFunction boundAliasFunction = ((BoundFunction) 
aliasUdf.withChildren(arguments.stream()
+                .map(Expression.class::cast).collect(Collectors.toList())));
+
+        Expression processedExpression = 
TypeCoercionUtils.processBoundFunction(boundAliasFunction);
+        List<Expression> inputs = processedExpression.getArguments();
+
+        Expression boundFunction = 
FunctionBinder.INSTANCE.rewrite(aliasUdf.getUnboundFunction(), null);

Review Comment:
   no, consider this case:
   ```sql
   create alias function f1 as days_add(now(3), n)
   create alias function f2 as days_add(f1(3), n)
   drop function f1
   create alias function f1 as days_sub(now(3), n)
   ```
   if we bind the function when we create f2, and f1 changed, the f2 will not 
work expectedly.



-- 
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: commits-unsubscr...@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to