This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f382e06aef [clean](planner) remove legacy planner's constant folding 
(#58680)
7f382e06aef is described below

commit 7f382e06aef5f3082e7f09d59842c9dc76e9b667
Author: morrySnow <[email protected]>
AuthorDate: Thu Dec 4 15:58:43 2025 +0800

    [clean](planner) remove legacy planner's constant folding (#58680)
    
    This pull request removes support for evaluating partition expressions
    defined as functions (e.g., function(column)) during partition pruning
    and related logic. The changes simplify the handling of binary
    predicates by eliminating function-based partition expression handling,
    and remove several related classes and utilities that are no longer
    needed.
    
    Key changes include:
    
    **Removal of function-based partition expression support:**
    
    * The `invokeFunctionExpr` method and all related logic for handling
    `FunctionCallExpr` in partition expressions have been removed from
    `BinaryPredicate`. The `getSlotBinding` method now only supports direct
    slot references and no longer accepts or processes a list of partition
    expressions.
    
    * The `ScanNode` class has been updated to stop passing partition
    expressions to `getSlotBinding`, reflecting the simplified interface.
    
    **Code cleanup and removal of unused utilities:**
    
    * The entire `ExpressionFunctions` class, which provided function
    evaluation utilities for partition expressions, has been deleted.
    
    * The annotation classes `FEFunction` and `FEFunctionList`, which were
    used for registering and managing function metadata for partition
    pruning, have also been removed.
    
    These changes collectively simplify the codebase and partition pruning
    logic by removing support and code paths for function-based partition
    expressions.
---
 .../org/apache/doris/analysis/BinaryPredicate.java |   54 +-
 .../main/java/org/apache/doris/analysis/Expr.java  |  126 ---
 .../apache/doris/analysis/ExpressionFunctions.java |  358 -------
 .../java/org/apache/doris/planner/ScanNode.java    |   10 +-
 .../java/org/apache/doris/rewrite/FEFunction.java  |   33 -
 .../org/apache/doris/rewrite/FEFunctionList.java   |   29 -
 .../java/org/apache/doris/rewrite/FEFunctions.java | 1022 --------------------
 7 files changed, 3 insertions(+), 1629 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
index 26ec9fed147..8cf53ab5fda 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
@@ -33,7 +33,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.gson.annotations.SerializedName;
 
-import java.util.ArrayList;
 import java.util.Objects;
 
 /**
@@ -190,33 +189,12 @@ public class BinaryPredicate extends Predicate {
         msg.setChildType(getChild(0).getType().getPrimitiveType().toThrift());
     }
 
-    public Expr invokeFunctionExpr(ArrayList<Expr> partitionExprs, Expr 
paramExpr) {
-        for (Expr partExpr : partitionExprs) {
-            if (partExpr instanceof FunctionCallExpr) {
-                FunctionCallExpr function = (FunctionCallExpr) 
partExpr.clone();
-                ArrayList<Expr> children = function.getChildren();
-                for (int i = 0; i < children.size(); ++i) {
-                    if (children.get(i) instanceof SlotRef) {
-                        // when create partition have check only support one 
slotRef
-                        function.setChild(i, paramExpr);
-                        return ExpressionFunctions.INSTANCE.evalExpr(function);
-                    }
-                }
-            }
-        }
-        return null;
-    }
-
     /**
      * If predicate is of the form "<slotref> <op> <expr>", returns expr,
      * otherwise returns null. Slotref may be wrapped in a CastExpr.
-     * now, when support auto create partition by function(column), so need 
check the "<function(column)> <op> <expr>"
-     * because import data use function result to create partition,
-     * so when have a SQL of query, prune partition also need use this function
      */
-    public Expr getSlotBinding(SlotId id, ArrayList<Expr> partitionExprs) {
+    public Expr getSlotBinding(SlotId id) {
         SlotRef slotRef = null;
-        boolean isFunctionCallExpr = false;
         // check left operand
         if (getChild(0) instanceof SlotRef) {
             slotRef = (SlotRef) getChild(0);
@@ -224,25 +202,10 @@ public class BinaryPredicate extends Predicate {
             if (((CastExpr) getChild(0)).canHashPartition()) {
                 slotRef = (SlotRef) getChild(0).getChild(0);
             }
-        } else if (getChild(0) instanceof FunctionCallExpr) {
-            FunctionCallExpr left = (FunctionCallExpr) getChild(0);
-            if (partitionExprs != null && left.findEqual(partitionExprs) != 
null) {
-                ArrayList<Expr> children = left.getChildren();
-                for (int i = 0; i < children.size(); ++i) {
-                    if (children.get(i) instanceof SlotRef) {
-                        slotRef = (SlotRef) children.get(i);
-                        isFunctionCallExpr = true;
-                        break;
-                    }
-                }
-            }
         }
 
         if (slotRef != null && slotRef.getSlotId() == id) {
             slotIsleft = true;
-            if (isFunctionCallExpr) {
-                return invokeFunctionExpr(partitionExprs, getChild(1));
-            }
             return getChild(1);
         }
 
@@ -253,25 +216,10 @@ public class BinaryPredicate extends Predicate {
             if (((CastExpr) getChild(1)).canHashPartition()) {
                 slotRef = (SlotRef) getChild(1).getChild(0);
             }
-        } else if (getChild(1) instanceof FunctionCallExpr) {
-            FunctionCallExpr left = (FunctionCallExpr) getChild(1);
-            if (partitionExprs != null && left.findEqual(partitionExprs) != 
null) {
-                ArrayList<Expr> children = left.getChildren();
-                for (int i = 0; i < children.size(); ++i) {
-                    if (children.get(i) instanceof SlotRef) {
-                        slotRef = (SlotRef) children.get(i);
-                        isFunctionCallExpr = true;
-                        break;
-                    }
-                }
-            }
         }
 
         if (slotRef != null && slotRef.getSlotId() == id) {
             slotIsleft = false;
-            if (isFunctionCallExpr) {
-                return invokeFunctionExpr(partitionExprs, getChild(0));
-            }
             return getChild(0);
         }
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
index e692d99eb52..06e5744c2f9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
@@ -46,9 +46,7 @@ import com.google.gson.annotations.SerializedName;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
-import java.util.ListIterator;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
@@ -167,19 +165,6 @@ public abstract class Expr extends TreeNode<Expr> 
implements Cloneable {
         return childNullables;
     }
 
-    public List<Expr> getChildrenWithoutCast() {
-        List<Expr> result = new ArrayList<>();
-        for (int i = 0; i < children.size(); ++i) {
-            if (children.get(i) instanceof CastExpr) {
-                CastExpr castExpr = (CastExpr) children.get(i);
-                result.add(castExpr.getChild(0));
-            } else {
-                result.add(children.get(i));
-            }
-        }
-        return result;
-    }
-
     public Expr getChildWithoutCast(int i) {
         Preconditions.checkArgument(i < children.size(), "child index {0} out 
of range {1}", i, children.size());
         Expr child = children.get(i);
@@ -205,30 +190,6 @@ public abstract class Expr extends TreeNode<Expr> 
implements Cloneable {
         return "(" + Joiner.on(" ").join(strings) + ")";
     }
 
-    /**
-     * Return true if l1 equals l2 when both lists are interpreted as sets.
-     */
-    public static <C extends Expr> boolean equalSets(List<C> l1, List<C> l2) {
-        if (l1.size() != l2.size()) {
-            return false;
-        }
-        Map cMap1 = toCountMap(l1);
-        Map cMap2 = toCountMap(l2);
-        if (cMap1.size() != cMap2.size()) {
-            return false;
-        }
-        Iterator it = cMap1.keySet().iterator();
-        while (it.hasNext()) {
-            C obj = (C) it.next();
-            Integer count1 = (Integer) cMap1.get(obj);
-            Integer count2 = (Integer) cMap2.get(obj);
-            if (count2 == null || count1 != count2) {
-                return false;
-            }
-        }
-        return true;
-    }
-
     public static <C extends Expr> HashMap<C, Integer> toCountMap(List<C> 
list) {
         HashMap countMap = new HashMap<C, Integer>();
         for (int i = 0; i < list.size(); i++) {
@@ -282,22 +243,6 @@ public abstract class Expr extends TreeNode<Expr> 
implements Cloneable {
         }
     }
 
-    /**
-     * get the expr which in l1 and l2 in the same time.
-     * Return the intersection of l1 and l2
-     */
-    public static <C extends Expr> List<C> intersect(List<C> l1, List<C> l2) {
-        List<C> result = new ArrayList<C>();
-
-        for (C element : l1) {
-            if (l2.contains(element)) {
-                result.add(element);
-            }
-        }
-
-        return result;
-    }
-
     public static void extractSlots(Expr root, Set<SlotId> slotIdSet) {
         if (root instanceof SlotRef) {
             slotIdSet.add(((SlotRef) root).getDesc().getId());
@@ -308,35 +253,6 @@ public abstract class Expr extends TreeNode<Expr> 
implements Cloneable {
         }
     }
 
-    /**
-     * Removes duplicate exprs (according to equals()).
-     */
-    public static <C extends Expr> void removeDuplicates(List<C> l) {
-        if (l == null) {
-            return;
-        }
-        ListIterator<C> it1 = l.listIterator();
-        while (it1.hasNext()) {
-            C e1 = it1.next();
-            ListIterator<C> it2 = l.listIterator();
-            boolean duplicate = false;
-            while (it2.hasNext()) {
-                C e2 = it2.next();
-                if (e1 == e2) {
-                    // only check up to but excluding e1
-                    break;
-                }
-                if (e1.equals(e2)) {
-                    duplicate = true;
-                    break;
-                }
-            }
-            if (duplicate) {
-                it1.remove();
-            }
-        }
-    }
-
     public String toSql() {
         if (disableTableName) {
             return toSqlWithoutTbl();
@@ -612,36 +528,6 @@ public abstract class Expr extends TreeNode<Expr> 
implements Cloneable {
         return this;
     }
 
-    public boolean isImplicitCast() {
-        return this instanceof CastExpr && ((CastExpr) this).isImplicit();
-    }
-
-    public boolean contains(Expr expr) {
-        if (this.equals(expr)) {
-            return true;
-        }
-
-        for (Expr child : getChildren()) {
-            if (child.contains(expr)) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    public Expr findEqual(List<Expr> exprs) {
-        if (exprs.isEmpty()) {
-            return null;
-        }
-        for (Expr expr : exprs) {
-            if (contains(expr)) {
-                return expr;
-            }
-        }
-        return null;
-    }
-
     public String getStringValue() {
         return "";
     }
@@ -727,18 +613,6 @@ public abstract class Expr extends TreeNode<Expr> 
implements Cloneable {
         return new AggStateType(name, resultNullable, typeList, nullableList);
     }
 
-    public static List<Expr> getMockedExprs(List<Type> typeList, List<Boolean> 
nullableList) {
-        List<Expr> mockedExprs = Lists.newArrayList();
-        for (int i = 0; i < typeList.size(); i++) {
-            mockedExprs.add(new SlotRef(typeList.get(i), nullableList.get(i)));
-        }
-        return mockedExprs;
-    }
-
-    public static List<Expr> getMockedExprs(AggStateType type) {
-        return getMockedExprs(type.getSubTypes(), type.getSubTypeNullables());
-    }
-
     // This is only for transactional insert operation,
     // to check it the given value in insert stmt is LiteralExpr.
     // And if we write "1" to a boolean column, there will be a cast(1 as 
boolean) expr,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java
deleted file mode 100644
index 7296516907a..00000000000
--- 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java
+++ /dev/null
@@ -1,358 +0,0 @@
-// 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.analysis;
-
-import org.apache.doris.catalog.Env;
-import org.apache.doris.catalog.Function;
-import org.apache.doris.catalog.PrimitiveType;
-import org.apache.doris.catalog.ScalarType;
-import org.apache.doris.catalog.Type;
-import org.apache.doris.common.AnalysisException;
-import org.apache.doris.qe.ConnectContext;
-import org.apache.doris.rewrite.FEFunction;
-import org.apache.doris.rewrite.FEFunctionList;
-import org.apache.doris.rewrite.FEFunctions;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-
-public enum ExpressionFunctions {
-    INSTANCE;
-
-    private static final Logger LOG = 
LogManager.getLogger(ExpressionFunctions.class);
-    private ImmutableMultimap<String, FEFunctionInvoker> functions;
-    public static final Set<String> unfixedFn = ImmutableSet.of(
-            "uuid",
-            "random"
-    );
-
-    private ExpressionFunctions() {
-        registerFunctions();
-    }
-
-    public Expr evalExpr(Expr constExpr) {
-        // Function's arg are all LiteralExpr.
-        for (Expr child : constExpr.getChildren()) {
-            if (!(child instanceof LiteralExpr) && !(child instanceof 
VariableExpr)) {
-                return constExpr;
-            }
-        }
-
-        if (constExpr instanceof ArithmeticExpr
-                || constExpr instanceof FunctionCallExpr
-                || constExpr instanceof TimestampArithmeticExpr) {
-            Function fn = constExpr.getFn();
-            if (fn == null) {
-                return constExpr;
-            }
-            if (ConnectContext.get() != null
-                    && ConnectContext.get().getSessionVariable() != null
-                    && 
!ConnectContext.get().getSessionVariable().isEnableFoldNondeterministicFn()
-                    && unfixedFn.contains(fn.getFunctionName().getFunction())) 
{
-                return constExpr;
-            }
-
-            Preconditions.checkNotNull(fn, "Expr's fn can't be null.");
-
-            // return NullLiteral directly iff:
-            // 1. Not UDF
-            // 2. Not in NonNullResultWithNullParamFunctions
-            // 3. Has null parameter
-            if ((fn.getNullableMode() == 
Function.NullableMode.DEPEND_ON_ARGUMENT
-                    || 
Env.getCurrentEnv().isNullResultWithOneNullParamFunction(
-                            fn.getFunctionName().getFunction()))
-                    && !fn.isUdf()) {
-                for (Expr e : constExpr.getChildren()) {
-                    if (e instanceof NullLiteral) {
-                        return new NullLiteral();
-                    }
-                }
-            }
-
-            // In some cases, non-deterministic functions should not be 
rewritten as constants,
-            // such as non-deterministic functions in the create view 
statement.
-            // eg: create view v1 as select rand();
-            if 
(Env.getCurrentEnv().isNondeterministicFunction(fn.getFunctionName().getFunction())
-                    && ConnectContext.get() != null && 
ConnectContext.get().notEvalNondeterministicFunction()) {
-                return constExpr;
-            }
-
-            FEFunctionSignature signature = new 
FEFunctionSignature(fn.functionName(),
-                    fn.getArgs(), fn.getReturnType());
-            FEFunctionInvoker invoker = getFunction(signature);
-            if (invoker != null) {
-                try {
-                    if (fn.getReturnType().isDateType()) {
-                        Expr dateLiteral = 
invoker.invoke(constExpr.getChildrenWithoutCast());
-                        Preconditions.checkArgument(dateLiteral instanceof 
DateLiteral);
-                        try {
-                            ((DateLiteral) dateLiteral).checkValueValid();
-                        } catch (AnalysisException e) {
-                            if (ConnectContext.get() != null) {
-                                ConnectContext.get().getState().reset();
-                            }
-                            return NullLiteral.create(dateLiteral.getType());
-                        }
-                        return dateLiteral;
-                    } else {
-                        return 
invoker.invoke(constExpr.getChildrenWithoutCast());
-                    }
-                } catch (AnalysisException e) {
-                    if (ConnectContext.get() != null) {
-                        ConnectContext.get().getState().reset();
-                    }
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("failed to invoke", e);
-                    }
-                    return constExpr;
-                }
-            }
-        } else if (constExpr instanceof VariableExpr) {
-            return ((VariableExpr) constExpr).getLiteralExpr();
-        }
-        return constExpr;
-    }
-
-    private FEFunctionInvoker getFunction(FEFunctionSignature signature) {
-        Collection<FEFunctionInvoker> functionInvokers = 
functions.get(signature.getName());
-        if (functionInvokers == null) {
-            return null;
-        }
-        for (FEFunctionInvoker invoker : functionInvokers) {
-            // Make functions for date/datetime applicable to datev2/datetimev2
-            if (!(invoker.getSignature().returnType.isDate() && 
signature.getReturnType().isDateV2())
-                    && !(invoker.getSignature().returnType.isDatetime() && 
signature.getReturnType().isDatetimeV2())
-                    && !(invoker.getSignature().returnType.isDecimalV2() && 
signature.getReturnType().isDecimalV3())
-                    && !(invoker.getSignature().returnType.isDecimalV2() && 
signature.getReturnType().isDecimalV2())
-                    && 
!invoker.getSignature().returnType.equals(signature.getReturnType())) {
-                continue;
-            }
-
-            Type[] argTypes1 = invoker.getSignature().getArgTypes();
-            Type[] argTypes2 = signature.getArgTypes();
-
-            if (argTypes1.length != argTypes2.length) {
-                continue;
-            }
-            boolean match = true;
-            for (int i = 0; i < argTypes1.length; i++) {
-                if (!(argTypes1[i].isDate() && argTypes2[i].isDateV2())
-                        && !(argTypes1[i].isDatetime() && 
argTypes2[i].isDatetimeV2())
-                        && !(argTypes1[i].isDecimalV2() && 
argTypes2[i].isDecimalV3())
-                        && !(argTypes1[i].isDecimalV2() && 
argTypes2[i].isDecimalV2())
-                        && !argTypes1[i].equals(argTypes2[i])) {
-                    match = false;
-                    break;
-                }
-            }
-            if (match) {
-                return invoker;
-            }
-        }
-        return null;
-    }
-
-    private synchronized void registerFunctions() {
-        // double checked locking pattern
-        // functions only need to init once
-        if (functions != null) {
-            return;
-        }
-        ImmutableMultimap.Builder<String, FEFunctionInvoker> mapBuilder =
-                new ImmutableMultimap.Builder<String, FEFunctionInvoker>();
-        Class clazz = FEFunctions.class;
-        for (Method method : clazz.getDeclaredMethods()) {
-            FEFunctionList annotationList = 
method.getAnnotation(FEFunctionList.class);
-            if (annotationList != null) {
-                for (FEFunction f : annotationList.value()) {
-                    registerFEFunction(mapBuilder, method, f);
-                }
-            }
-            registerFEFunction(mapBuilder, method, 
method.getAnnotation(FEFunction.class));
-        }
-        this.functions = mapBuilder.build();
-    }
-
-    private void registerFEFunction(ImmutableMultimap.Builder<String, 
FEFunctionInvoker> mapBuilder,
-                                    Method method, FEFunction annotation) {
-        if (annotation != null) {
-            String name = annotation.name();
-            Type returnType = 
Type.fromPrimitiveType(PrimitiveType.valueOf(annotation.returnType()));
-            List<Type> argTypes = new ArrayList<>();
-            for (String type : annotation.argTypes()) {
-                argTypes.add(ScalarType.createType(type));
-            }
-            FEFunctionSignature signature = new FEFunctionSignature(name,
-                    argTypes.toArray(new Type[argTypes.size()]), returnType);
-            mapBuilder.put(name, new FEFunctionInvoker(method, signature));
-        }
-    }
-
-    public static class FEFunctionInvoker {
-        private final Method method;
-        private final FEFunctionSignature signature;
-
-        public FEFunctionInvoker(Method method, FEFunctionSignature signature) 
{
-            this.method = method;
-            this.signature = signature;
-        }
-
-        public Method getMethod() {
-            return method;
-        }
-
-        public FEFunctionSignature getSignature() {
-            return signature;
-        }
-
-        // Now ExpressionFunctions doesn't support function that it's args 
contain
-        // array type except last one.
-        public LiteralExpr invoke(List<Expr> args) throws AnalysisException {
-            final List<Object> invokeArgs = createInvokeArgs(args);
-            try {
-                return (LiteralExpr) method.invoke(null, invokeArgs.toArray());
-            } catch (InvocationTargetException | IllegalAccessException | 
IllegalArgumentException e) {
-                throw new AnalysisException(e.getLocalizedMessage());
-            }
-        }
-
-        private List<Object> createInvokeArgs(List<Expr> args) throws 
AnalysisException {
-            final List<Object> invokeArgs = Lists.newArrayList();
-            for (int typeIndex = 0; typeIndex < 
method.getParameterTypes().length; typeIndex++) {
-                final Class<?> argType = method.getParameterTypes()[typeIndex];
-                if (argType.isArray()) {
-                    
Preconditions.checkArgument(method.getParameterTypes().length == typeIndex + 1);
-                    final List<Expr> variableLengthExprs = 
Lists.newArrayList();
-                    for (int variableLengthArgIndex = typeIndex;
-                            variableLengthArgIndex < args.size(); 
variableLengthArgIndex++) {
-                        
variableLengthExprs.add(args.get(variableLengthArgIndex));
-                    }
-                    LiteralExpr[] variableLengthArgs = 
createVariableLengthArgs(variableLengthExprs, typeIndex);
-                    invokeArgs.add(variableLengthArgs);
-                } else {
-                    invokeArgs.add(args.get(typeIndex));
-                }
-            }
-            return invokeArgs;
-        }
-
-        private LiteralExpr[] createVariableLengthArgs(List<Expr> args, int 
typeIndex) throws AnalysisException {
-            final Set<Class<?>> classSet = Sets.newHashSet();
-            for (Expr e : args) {
-                classSet.add(e.getClass());
-            }
-            if (classSet.size() > 1) {
-                // Variable-length args' types can't exceed two kinds.
-                throw new AnalysisException("Function's args doesn't match.");
-            }
-
-            final Type argType = signature.getArgTypes()[typeIndex];
-            LiteralExpr[] exprs;
-            if (argType.isStringType()) {
-                exprs = new StringLiteral[args.size()];
-            } else if (argType.isIntegerType()) {
-                exprs = new IntLiteral[args.size()];
-            } else if (argType.isLargeIntType()) {
-                exprs = new LargeIntLiteral[args.size()];
-            } else if (argType.isDateType()) {
-                exprs = new DateLiteral[args.size()];
-            } else if (argType.isDecimalV2() || argType.isDecimalV3()) {
-                exprs = new DecimalLiteral[args.size()];
-            } else if (argType.isFloatingPointType()) {
-                exprs = new FloatLiteral[args.size()];
-            } else if (argType.isBoolean()) {
-                exprs = new BoolLiteral[args.size()];
-            } else {
-                throw new IllegalArgumentException("Doris doesn't support 
type:" + argType);
-            }
-
-            // if args all is NullLiteral
-            long size = args.stream().filter(e -> e instanceof 
NullLiteral).count();
-            if (args.size() == size) {
-                exprs = new NullLiteral[args.size()];
-            }
-            args.toArray(exprs);
-            return exprs;
-        }
-    }
-
-    public static class FEFunctionSignature {
-        private final String name;
-        private final Type[] argTypes;
-        private final Type returnType;
-
-        public FEFunctionSignature(String name, Type[] argTypes, Type 
returnType) {
-            this.name = name;
-            this.argTypes = argTypes;
-            this.returnType = returnType;
-        }
-
-        public Type[] getArgTypes() {
-            return argTypes;
-        }
-
-        public Type getReturnType() {
-            return returnType;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder();
-            sb.append("FEFunctionSignature. name: ").append(name).append(", 
return: ").append(returnType);
-            sb.append(", args: ").append(Joiner.on(",").join(argTypes));
-            return sb.toString();
-        }
-
-        @Override
-        public boolean equals(Object o) {
-            if (this == o) {
-                return true;
-            }
-            if (o == null || getClass() != o.getClass()) {
-                return false;
-            }
-            FEFunctionSignature signature = (FEFunctionSignature) o;
-            return Objects.equals(name, signature.name) && 
Arrays.equals(argTypes, signature.argTypes)
-                    && Objects.equals(returnType, signature.returnType);
-        }
-
-        @Override
-        public int hashCode() {
-            return Objects.hash(name, argTypes, returnType);
-        }
-    }
-}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java
index 1dc2dda2c25..26c0024af8e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java
@@ -259,10 +259,7 @@ public abstract class ScanNode extends PlanNode implements 
SplitGenerator {
         List<Range<ColumnBound>> result = Lists.newArrayList();
         if (expr instanceof BinaryPredicate) {
             BinaryPredicate binPred = (BinaryPredicate) expr;
-            ArrayList<Expr> partitionExprs = (partitionsInfo != null && 
partitionsInfo.enableAutomaticPartition())
-                    ? partitionsInfo.getPartitionExprs()
-                    : null;
-            Expr slotBinding = binPred.getSlotBinding(desc.getId(), 
partitionExprs);
+            Expr slotBinding = binPred.getSlotBinding(desc.getId());
             if (slotBinding == null || !slotBinding.isConstant() || 
!(slotBinding instanceof LiteralExpr)) {
                 return ColumnRanges.createFailure();
             }
@@ -352,10 +349,7 @@ public abstract class ScanNode extends PlanNode implements 
SplitGenerator {
                     continue;
                 }
 
-                ArrayList<Expr> partitionExprs = (partitionsInfo != null && 
partitionsInfo.enableAutomaticPartition())
-                        ? partitionsInfo.getPartitionExprs()
-                        : null;
-                Expr slotBinding = binPredicate.getSlotBinding(desc.getId(), 
partitionExprs);
+                Expr slotBinding = binPredicate.getSlotBinding(desc.getId());
 
                 if (slotBinding == null || !slotBinding.isConstant() || 
!(slotBinding instanceof LiteralExpr)) {
                     continue;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunction.java 
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunction.java
deleted file mode 100644
index 8b1f9a70e38..00000000000
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunction.java
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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.rewrite;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface FEFunction {
-    String name();
-
-    String[] argTypes();
-
-    String returnType();
-}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctionList.java 
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctionList.java
deleted file mode 100644
index d6119d337b0..00000000000
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctionList.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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.rewrite;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface FEFunctionList {
-    FEFunction[] value();
-}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java 
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
deleted file mode 100755
index 75a0d26d5d6..00000000000
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
+++ /dev/null
@@ -1,1022 +0,0 @@
-// 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.rewrite;
-
-import org.apache.doris.analysis.DateLiteral;
-import org.apache.doris.analysis.DecimalLiteral;
-import org.apache.doris.analysis.FloatLiteral;
-import org.apache.doris.analysis.IntLiteral;
-import org.apache.doris.analysis.LargeIntLiteral;
-import org.apache.doris.analysis.LiteralExpr;
-import org.apache.doris.analysis.NullLiteral;
-import org.apache.doris.analysis.StringLiteral;
-import org.apache.doris.analysis.TimestampArithmeticExpr.TimeUnit;
-import org.apache.doris.catalog.Type;
-import org.apache.doris.common.AnalysisException;
-import org.apache.doris.common.InvalidFormatException;
-import org.apache.doris.common.util.TimeUtils;
-import org.apache.doris.qe.GlobalVariable;
-
-import com.google.common.base.Preconditions;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.time.LocalDateTime;
-
-/**
- * compute functions in FE.
- *
- * when you add a new function, please ensure the name, argTypes,
- * returnType and compute logic are consistent with BE's function
- */
-public class FEFunctions {
-    private static final Logger LOG = LogManager.getLogger(FEFunctions.class);
-
-    @FEFunction(name = "version", argTypes = {}, returnType = "VARCHAR")
-    public static StringLiteral version() throws AnalysisException {
-        return new StringLiteral(GlobalVariable.version);
-    }
-
-    /**
-     * date and time function
-     */
-    @FEFunction(name = "timediff", argTypes = { "DATETIME", "DATETIME" }, 
returnType = "TIMEV2")
-    public static FloatLiteral timeDiff(LiteralExpr first, LiteralExpr second) 
throws AnalysisException {
-        long firstTimestamp = ((DateLiteral) 
first).unixTimestamp(TimeUtils.getTimeZone());
-        long secondTimestamp = ((DateLiteral) 
second).unixTimestamp(TimeUtils.getTimeZone());
-        return new FloatLiteral((double) (firstTimestamp - secondTimestamp) * 
1000, Type.TIMEV2);
-    }
-
-    @FEFunction(name = "dayofweek", argTypes = {"DATETIME"}, returnType = 
"TINYINT")
-    public static IntLiteral dayOfWeek(LiteralExpr date) throws 
AnalysisException {
-        // use zellar algorithm.
-        long year = ((DateLiteral) date).getYear();
-        long month = ((DateLiteral) date).getMonth();
-        long day = ((DateLiteral) date).getDay();
-        if (month < 3) {
-            month += 12;
-            year -= 1;
-        }
-        long c = year / 100;
-        long y = year % 100;
-        long t;
-        if (date.compareTo(new DateLiteral(1582, 10, 4)) > 0) {
-            t = (y + y / 4 + c / 4 - 2 * c + 26 * (month + 1) / 10 + day - 1) 
% 7;
-        } else {
-            t = (y + y / 4 - c + 26 * (month + 1) / 10 + day + 4) % 7;
-        }
-        return new IntLiteral(t + 1);
-    }
-
-    @FEFunction(name = "date_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral dateAdd(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return daysAdd(date, day);
-    }
-
-    @FEFunction(name = "date_add", argTypes = { "DATE", "INT" }, returnType = 
"DATE")
-    public static DateLiteral dateAddDate(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return daysAdd(date, day);
-    }
-
-    @FEFunction(name = "date_add", argTypes = { "DATEV2", "INT" }, returnType 
= "DATEV2")
-    public static DateLiteral dateAddDateV2(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return daysAdd(date, day);
-    }
-
-    @FEFunction(name = "date_add", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral dateAddDateTimeV2(LiteralExpr date, LiteralExpr 
day) throws AnalysisException {
-        return daysAdd(date, day);
-    }
-
-    @FEFunction(name = "adddate", argTypes = { "DATETIME", "INT" }, returnType 
= "DATETIME")
-    public static DateLiteral addDate(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return daysAdd(date, day);
-    }
-
-    @FEFunction(name = "adddate", argTypes = { "DATEV2", "INT" }, returnType = 
"DATEV2")
-    public static DateLiteral addDateDateV2(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return daysAdd(date, day);
-    }
-
-    @FEFunction(name = "adddate", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral addDateDateTimeV2(LiteralExpr date, LiteralExpr 
day) throws AnalysisException {
-        return daysAdd(date, day);
-    }
-
-    @FEFunction(name = "years_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral yearsAdd(LiteralExpr date, LiteralExpr year) 
throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusYears(year.getLongValue());
-    }
-
-    @FEFunction(name = "years_add", argTypes = { "DATE", "INT" }, returnType = 
"DATE")
-    public static DateLiteral yearsAddDate(LiteralExpr date, LiteralExpr year) 
throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusYears((int) year.getLongValue());
-    }
-
-    @FEFunction(name = "years_add", argTypes = { "DATEV2", "INT" }, returnType 
= "DATEV2")
-    public static DateLiteral yearsAddDateV2(LiteralExpr date, LiteralExpr 
year) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusYears((int) year.getLongValue());
-    }
-
-    @FEFunction(name = "years_add", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral yearsAddDateTimeV2(LiteralExpr date, LiteralExpr 
year) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusYears((int) year.getLongValue());
-    }
-
-    @FEFunction(name = "quarters_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral quartersAdd(LiteralExpr date, LiteralExpr 
quarter) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusMonths(3 * (int) quarter.getLongValue());
-    }
-
-    @FEFunction(name = "quarters_add", argTypes = { "DATE", "INT" }, 
returnType = "DATE")
-    public static DateLiteral quartersAddDate(LiteralExpr date, LiteralExpr 
quarter) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusMonths(3 * (int) quarter.getLongValue());
-    }
-
-    @FEFunction(name = "quarters_add", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
-    public static DateLiteral quartersAddDateV2(LiteralExpr date, LiteralExpr 
quarter) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusMonths(3 * (int) quarter.getLongValue());
-    }
-
-    @FEFunction(name = "quarters_add", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral quartersAddDateTimeV2(LiteralExpr date, 
LiteralExpr quarter) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusMonths(3 * (int) quarter.getLongValue());
-    }
-
-    @FEFunction(name = "months_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral monthsAdd(LiteralExpr date, LiteralExpr month) 
throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusMonths(month.getLongValue());
-    }
-
-    @FEFunction(name = "months_add", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
-    public static DateLiteral monthsAddDate(LiteralExpr date, LiteralExpr 
month) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusMonths((int) month.getLongValue());
-    }
-
-    @FEFunction(name = "months_add", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
-    public static DateLiteral monthsAddDateV2(LiteralExpr date, LiteralExpr 
month) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusMonths((int) month.getLongValue());
-    }
-
-    @FEFunction(name = "months_add", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral monthsAddDateTimeV2(LiteralExpr date, 
LiteralExpr month) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusMonths((int) month.getLongValue());
-    }
-
-    @FEFunction(name = "days_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral daysAdd(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusDays(day.getLongValue());
-    }
-
-    @FEFunction(name = "days_add", argTypes = { "DATE", "INT" }, returnType = 
"DATE")
-    public static DateLiteral daysAddDate(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusDays((int) day.getLongValue());
-    }
-
-    @FEFunction(name = "days_add", argTypes = { "DATEV2", "INT" }, returnType 
= "DATEV2")
-    public static DateLiteral daysAddDateV2(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusDays((int) day.getLongValue());
-    }
-
-    @FEFunction(name = "days_add", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral daysAddDateTimeV2(LiteralExpr date, LiteralExpr 
day) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusDays((int) day.getLongValue());
-    }
-
-    @FEFunction(name = "hours_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral hoursAdd(LiteralExpr date, LiteralExpr hour) 
throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusHours(hour.getLongValue());
-    }
-
-    @FEFunction(name = "minutes_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral minutesAdd(LiteralExpr date, LiteralExpr minute) 
throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusMinutes(minute.getLongValue());
-    }
-
-    @FEFunction(name = "seconds_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-     public static DateLiteral secondsAdd(LiteralExpr date, LiteralExpr 
second) throws AnalysisException {
-        DateLiteral dateLiteral = (DateLiteral) date;
-        return dateLiteral.plusSeconds(second.getLongValue());
-    }
-
-    @FEFunction(name = "str_to_date", argTypes = { "VARCHAR", "VARCHAR" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral dateParse(StringLiteral date, StringLiteral 
fmtLiteral) throws AnalysisException {
-        DateLiteral dateLiteral = new DateLiteral();
-        try {
-            dateLiteral.fromDateFormatStr(fmtLiteral.getStringValue(), 
date.getStringValue(), false);
-            dateLiteral.setType(dateLiteral.getType());
-            return dateLiteral;
-        } catch (InvalidFormatException e) {
-            throw new AnalysisException(e.getMessage());
-        }
-    }
-
-    @FEFunction(name = "date_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral dateSub(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return dateAdd(date, new IntLiteral(-(int) day.getLongValue()));
-    }
-
-    @FEFunction(name = "date_sub", argTypes = { "DATE", "INT" }, returnType = 
"DATE")
-    public static DateLiteral dateSubDate(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return daysAdd(date, new IntLiteral(-(int) day.getLongValue()));
-    }
-
-    @FEFunction(name = "date_sub", argTypes = { "DATEV2", "INT" }, returnType 
= "DATEV2")
-    public static DateLiteral dateSubDateV2(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return dateAdd(date, new IntLiteral(-(int) day.getLongValue()));
-    }
-
-    @FEFunction(name = "date_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral dateSubDateTimeV2(LiteralExpr date, LiteralExpr 
day) throws AnalysisException {
-        return daysAdd(date, new IntLiteral(-(int) day.getLongValue()));
-    }
-
-    @FEFunction(name = "years_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral yearsSub(LiteralExpr date, LiteralExpr year) 
throws AnalysisException {
-        return yearsAdd(date, new IntLiteral(-(int) year.getLongValue()));
-    }
-
-    @FEFunction(name = "years_sub", argTypes = { "DATE", "INT" }, returnType = 
"DATE")
-    public static DateLiteral yearsSubDate(LiteralExpr date, LiteralExpr year) 
throws AnalysisException {
-        return yearsAdd(date, new IntLiteral(-(int) year.getLongValue()));
-    }
-
-    @FEFunction(name = "years_sub", argTypes = { "DATEV2", "INT" }, returnType 
= "DATEV2")
-    public static DateLiteral yearsSubDateV2(LiteralExpr date, LiteralExpr 
year) throws AnalysisException {
-        return yearsAdd(date, new IntLiteral(-(int) year.getLongValue()));
-    }
-
-    @FEFunction(name = "years_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral yearsSubDateTimeV2(LiteralExpr date, LiteralExpr 
year) throws AnalysisException {
-        return yearsAdd(date, new IntLiteral(-(int) year.getLongValue()));
-    }
-
-    @FEFunction(name = "quarters_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral quartersSub(LiteralExpr date, LiteralExpr 
quarter) throws AnalysisException {
-        return quartersAdd(date, new IntLiteral(-(int) 
quarter.getLongValue()));
-    }
-
-    @FEFunction(name = "quarters_sub", argTypes = { "DATE", "INT" }, 
returnType = "DATE")
-    public static DateLiteral quartersSubDate(LiteralExpr date, LiteralExpr 
quarter) throws AnalysisException {
-        return quartersAdd(date, new IntLiteral(-(int) 
quarter.getLongValue()));
-    }
-
-    @FEFunction(name = "quarters_sub", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
-    public static DateLiteral quartersSubDateV2(LiteralExpr date, LiteralExpr 
quarter) throws AnalysisException {
-        return quartersAdd(date, new IntLiteral(-(int) 
quarter.getLongValue()));
-    }
-
-    @FEFunction(name = "quarters_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral quartersSubDateTimeV2(LiteralExpr date, 
LiteralExpr quarter) throws AnalysisException {
-        return quartersAdd(date, new IntLiteral(-(int) 
quarter.getLongValue()));
-    }
-
-    @FEFunction(name = "months_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral monthsSub(LiteralExpr date, LiteralExpr month) 
throws AnalysisException {
-        return monthsAdd(date, new IntLiteral(-(int) month.getLongValue()));
-    }
-
-    @FEFunction(name = "months_sub", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
-    public static DateLiteral monthsSubDate(LiteralExpr date, LiteralExpr 
month) throws AnalysisException {
-        return monthsAdd(date, new IntLiteral(-(int) month.getLongValue()));
-    }
-
-    @FEFunction(name = "months_sub", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
-    public static DateLiteral monthsSubDateV2(LiteralExpr date, LiteralExpr 
month) throws AnalysisException {
-        return monthsAdd(date, new IntLiteral(-(int) month.getLongValue()));
-    }
-
-    @FEFunction(name = "months_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral monthsSubDateTimeV2(LiteralExpr date, 
LiteralExpr month) throws AnalysisException {
-        return monthsAdd(date, new IntLiteral(-(int) month.getLongValue()));
-    }
-
-    @FEFunction(name = "days_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral daysSub(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return daysAdd(date, new IntLiteral(-(int) day.getLongValue()));
-    }
-
-    @FEFunction(name = "days_sub", argTypes = { "DATE", "INT" }, returnType = 
"DATE")
-    public static DateLiteral daysSubDate(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return daysAdd(date, new IntLiteral(-(int) day.getLongValue()));
-    }
-
-    @FEFunction(name = "days_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
-    public static DateLiteral daysSubDateTimeV2(LiteralExpr date, LiteralExpr 
day) throws AnalysisException {
-        return daysAdd(date, new IntLiteral(-(int) day.getLongValue()));
-    }
-
-    @FEFunction(name = "days_sub", argTypes = { "DATEV2", "INT" }, returnType 
= "DATEV2")
-    public static DateLiteral daysSubDateV2(LiteralExpr date, LiteralExpr day) 
throws AnalysisException {
-        return daysAdd(date, new IntLiteral(-(int) day.getLongValue()));
-    }
-
-    @FEFunction(name = "hours_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral hoursSub(LiteralExpr date, LiteralExpr hour) 
throws AnalysisException {
-        return hoursAdd(date, new IntLiteral(-(int) hour.getLongValue()));
-    }
-
-    @FEFunction(name = "minutes_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral minutesSub(LiteralExpr date, LiteralExpr minute) 
throws AnalysisException {
-        return minutesAdd(date, new IntLiteral(-(int) minute.getLongValue()));
-    }
-
-    @FEFunction(name = "seconds_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
-    public static DateLiteral secondsSub(LiteralExpr date, LiteralExpr second) 
throws AnalysisException {
-        return secondsAdd(date, new IntLiteral(-(int) second.getLongValue()));
-    }
-
-    @FEFunction(name = "year", argTypes = { "DATETIME" }, returnType = 
"SMALLINT")
-    public static IntLiteral year(LiteralExpr arg) throws AnalysisException {
-        return new IntLiteral(((DateLiteral) arg).getYear(), Type.INT);
-    }
-
-    @FEFunction(name = "month", argTypes = { "DATETIME" }, returnType = 
"TINYINT")
-    public static IntLiteral month(LiteralExpr arg) throws AnalysisException {
-        return new IntLiteral(((DateLiteral) arg).getMonth(), Type.INT);
-    }
-
-    @FEFunction(name = "day", argTypes = { "DATETIME" }, returnType = 
"TINYINT")
-    public static IntLiteral day(LiteralExpr arg) throws AnalysisException {
-        return new IntLiteral(((DateLiteral) arg).getDay(), Type.INT);
-    }
-
-    @FEFunction(name = "unix_timestamp", argTypes = { "DATETIME" }, returnType 
= "INT")
-    public static IntLiteral unixTimestamp(LiteralExpr arg) throws 
AnalysisException {
-        long unixTime = ((DateLiteral) 
arg).unixTimestamp(TimeUtils.getTimeZone()) / 1000;
-        // date before 1970-01-01 or after 2038-01-19 03:14:07 should return 0 
for unix_timestamp() function
-        unixTime = unixTime < 0 ? 0 : unixTime;
-        unixTime = unixTime > Integer.MAX_VALUE ? 0 : unixTime;
-        return new IntLiteral(unixTime, Type.INT);
-    }
-
-    @FEFunction(name = "unix_timestamp", argTypes = { "DATE" }, returnType = 
"INT")
-    public static IntLiteral unixTimestamp2(LiteralExpr arg) throws 
AnalysisException {
-        long unixTime = ((DateLiteral) 
arg).unixTimestamp(TimeUtils.getTimeZone()) / 1000;
-        // date before 1970-01-01 or after 2038-01-19 03:14:07 should return 0 
for unix_timestamp() function
-        unixTime = unixTime < 0 ? 0 : unixTime;
-        unixTime = unixTime > Integer.MAX_VALUE ? 0 : unixTime;
-        return new IntLiteral(unixTime, Type.INT);
-    }
-
-    @FEFunction(name = "from_unixtime", argTypes = { "BIGINT" }, returnType = 
"VARCHAR")
-    public static StringLiteral fromUnixTime(LiteralExpr unixTime) throws 
AnalysisException {
-        // if unixTime < 0, we should return null, throw a exception and let 
BE process
-        // 32536771199L is max valid timestamp of mysql from_unix_time
-        if (unixTime.getLongValue() < 0 || unixTime.getLongValue() > 
32536771199L) {
-            throw new AnalysisException("unix timestamp out of range");
-        }
-        DateLiteral dl = new DateLiteral(unixTime.getLongValue() * 1000, 
TimeUtils.getTimeZone(),
-                Type.DATETIME);
-        return new StringLiteral(dl.getStringValue());
-    }
-
-    @FEFunction(name = "now", argTypes = {}, returnType = "DATETIME")
-    public static DateLiteral now() throws AnalysisException {
-        return  new 
DateLiteral(LocalDateTime.now(TimeUtils.getTimeZone().toZoneId()),
-                Type.DATETIME);
-    }
-
-    @FEFunction(name = "current_timestamp", argTypes = {}, returnType = 
"DATETIME")
-    public static DateLiteral currentTimestamp() throws AnalysisException {
-        return now();
-    }
-
-    @FEFunction(name = "curdate", argTypes = {}, returnType = "DATE")
-    public static DateLiteral curDate() {
-        return new 
DateLiteral(LocalDateTime.now(TimeUtils.getTimeZone().toZoneId()),
-                Type.DATE);
-    }
-
-    @FEFunction(name = "current_date", argTypes = {}, returnType = "DATE")
-    public static DateLiteral currentDate() {
-        return curDate();
-    }
-
-    @FEFunction(name = "curtime", argTypes = {}, returnType = "TIMEV2")
-    public static FloatLiteral curTime() throws AnalysisException {
-        DateLiteral now = now();
-        return new FloatLiteral((double) (now.getHour() * 3600 + 
now.getMinute() * 60 + now.getSecond()), Type.TIMEV2);
-    }
-
-    @FEFunction(name = "current_time", argTypes = {}, returnType = "TIMEV2")
-    public static FloatLiteral currentTime() throws AnalysisException {
-        return curTime();
-    }
-
-    @FEFunction(name = "utc_timestamp", argTypes = {}, returnType = "DATETIME")
-    public static DateLiteral utcTimestamp() {
-        return new 
DateLiteral(LocalDateTime.now(TimeUtils.getOrSystemTimeZone("+00:00").toZoneId()),
-                Type.DATETIME);
-    }
-
-    @FEFunction(name = "hour", argTypes = {"DATETIME"}, returnType = "TINYINT")
-    public static IntLiteral hour(LiteralExpr arg) throws AnalysisException {
-        if (arg instanceof DateLiteral) {
-            return new IntLiteral(((DateLiteral) arg).getHour());
-        }
-        return null;
-    }
-
-    @FEFunction(name = "minute", argTypes = {"DATETIME"}, returnType = 
"TINYINT")
-    public static IntLiteral minute(LiteralExpr arg) throws AnalysisException {
-        if (arg instanceof DateLiteral) {
-            return new IntLiteral(((DateLiteral) arg).getMinute());
-        }
-        return null;
-    }
-
-    @FEFunction(name = "second", argTypes = {"DATETIME"}, returnType = 
"TINYINT")
-    public static IntLiteral second(LiteralExpr arg) throws AnalysisException {
-        if (arg instanceof DateLiteral) {
-            return new IntLiteral(((DateLiteral) arg).getSecond());
-        }
-        return null;
-    }
-
-    @FEFunction(name = "timestamp", argTypes = {"DATETIME"}, returnType = 
"DATETIME")
-    public static DateLiteral timestamp(LiteralExpr arg) throws 
AnalysisException {
-        if (arg instanceof DateLiteral) {
-            return (DateLiteral) arg;
-        }
-        return null;
-    }
-
-    @FEFunction(name = "to_monday", argTypes = {"DATETIME"}, returnType = 
"DATE")
-    public static DateLiteral toMonday(LiteralExpr arg) {
-        if (arg instanceof DateLiteral && (arg.getType().isDate() || 
arg.getType().isDatetime())) {
-            DateLiteral dateLiteral = ((DateLiteral) arg);
-            LocalDateTime dateTime = LocalDateTime.of(
-                    ((int) dateLiteral.getYear()), ((int) 
dateLiteral.getMonth()), ((int) dateLiteral.getDay()),
-                    0, 0, 0);
-            dateTime = toMonday(dateTime);
-            return new DateLiteral(dateTime.getYear(), 
dateTime.getMonthValue(), dateTime.getDayOfMonth(), Type.DATE);
-        }
-        return null;
-    }
-
-    @FEFunction(name = "to_monday", argTypes = {"DATETIMEV2"}, returnType = 
"DATEV2")
-    public static DateLiteral toMondayV2(LiteralExpr arg) {
-        if (arg instanceof DateLiteral && (arg.getType().isDateV2() || 
arg.getType().isDatetimeV2())) {
-            DateLiteral dateLiteral = ((DateLiteral) arg);
-            LocalDateTime dateTime = LocalDateTime.of(
-                    ((int) dateLiteral.getYear()), ((int) 
dateLiteral.getMonth()), ((int) dateLiteral.getDay()),
-                    0, 0, 0);
-            dateTime = toMonday(dateTime);
-            return new DateLiteral(dateTime.getYear(), 
dateTime.getMonthValue(), dateTime.getDayOfMonth(), Type.DATEV2);
-        }
-        return null;
-    }
-
-    @FEFunction(name = "second_floor", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral second_floor(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
false, TimeUnit.SECOND);
-    }
-
-    @FEFunction(name = "second_ceil", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral second_ceil(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
true, TimeUnit.SECOND);
-    }
-
-    @FEFunction(name = "minute_floor", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral minute_floor(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
false, TimeUnit.MINUTE);
-    }
-
-    @FEFunction(name = "minute_ceil", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral minute_ceil(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
true, TimeUnit.MINUTE);
-    }
-
-    @FEFunction(name = "hour_floor", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral hour_floor(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
false, TimeUnit.HOUR);
-    }
-
-    @FEFunction(name = "hour_ceil", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral hour_ceil(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
true, TimeUnit.HOUR);
-    }
-
-    @FEFunction(name = "day_floor", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral day_floor(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
false, TimeUnit.DAY);
-    }
-
-    @FEFunction(name = "day_ceil", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral day_ceil(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
true, TimeUnit.DAY);
-    }
-
-    // get it's from 
be/src/vec/functions/function_datetime_floor_ceil.cpp##time_round
-    public static DateLiteral getFloorCeilDateLiteral(LiteralExpr datetime, 
LiteralExpr period,
-            LiteralExpr defaultDatetime, boolean isCeil, TimeUnit type) throws 
AnalysisException {
-        DateLiteral dt = ((DateLiteral) datetime);
-        DateLiteral start = ((DateLiteral) defaultDatetime);
-        long periodValue = ((IntLiteral) period).getValue();
-        long diff = 0;
-        long trivialPart = 0;
-
-        switch (type) {
-            case YEAR: {
-                diff = dt.getYear() - start.getYear();
-                trivialPart = (dt.getLongValue() % 10000000000L) - 
(start.getLongValue() % 10000000000L);
-                break;
-            }
-            case MONTH: {
-                diff = (dt.getYear() - start.getYear()) * 12 + (dt.getMonth() 
- start.getMonth());
-                trivialPart = (dt.getLongValue() % 100000000L) - 
(start.getLongValue() % 100000000L);
-                break;
-            }
-            case WEEK: {
-                diff = (dt.daynr() / 7) - (start.daynr() / 7);
-                long part2 = (dt.daynr() % 7) * 24 * 3600 + dt.getHour() * 
3600 + dt.getMinute() * 60 + dt.getSecond();
-                long part1 = (start.daynr() % 7) * 24 * 3600 + start.getHour() 
* 3600 + start.getMinute() * 60
-                        + start.getSecond();
-                trivialPart = part2 - part1;
-                break;
-            }
-            case DAY: {
-                diff = dt.daynr() - start.daynr();
-                long part2 = dt.getHour() * 3600 + dt.getMinute() * 60 + 
dt.getSecond();
-                long part1 = start.getHour() * 3600 + start.getMinute() * 60 + 
start.getSecond();
-                trivialPart = part2 - part1;
-                break;
-            }
-            case HOUR: {
-                diff = (dt.daynr() - start.daynr()) * 24 + (dt.getHour() - 
start.getHour());
-                trivialPart = (dt.getMinute() * 60 + dt.getSecond()) - 
(start.getMinute() * 60 + start.getSecond());
-                break;
-            }
-            case MINUTE: {
-                diff = (dt.daynr() - start.daynr()) * 24 * 60 + (dt.getHour() 
- start.getHour()) * 60
-                        + (dt.getMinute() - start.getMinute());
-                trivialPart = dt.getSecond() - start.getSecond();
-                break;
-            }
-            case SECOND: {
-                diff = (dt.daynr() - start.daynr()) * 24 * 60 * 60 + 
(dt.getHour() - start.getHour()) * 60 * 60
-                        + (dt.getMinute() - start.getMinute()) * 60 + 
(dt.getSecond() - start.getSecond());
-                trivialPart = 0;
-                break;
-            }
-            default:
-                break;
-        }
-
-        if (isCeil) {
-            diff = diff + (trivialPart > 0 ? 1 : 0);
-        } else {
-            diff = diff - (trivialPart < 0 ? 1 : 0);
-        }
-        long deltaInsidePeriod = (diff % periodValue + periodValue) % 
periodValue;
-        long step = diff - deltaInsidePeriod;
-        if (isCeil) {
-            step = step + (deltaInsidePeriod == 0 ? 0 : periodValue);
-        }
-        switch (type) {
-            case YEAR:
-                return start.plusYears(step);
-            case MONTH:
-                return start.plusMonths(step);
-            case WEEK:
-                return start.plusDays(step * 7);
-            case DAY:
-                return start.plusDays(step);
-            case HOUR:
-                return start.plusHours(step);
-            case MINUTE:
-                return start.plusMinutes(step);
-            case SECOND:
-                return start.plusSeconds(step);
-            default:
-                break;
-        }
-        return null;
-    }
-
-    @FEFunction(name = "week_floor", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral week_floor(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
false, TimeUnit.WEEK);
-    }
-
-    @FEFunction(name = "week_ceil", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral week_ceil(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
true, TimeUnit.WEEK);
-    }
-
-    @FEFunction(name = "month_floor", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral month_floor(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
false, TimeUnit.MONTH);
-    }
-
-    @FEFunction(name = "month_ceil", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral month_ceil(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
true, TimeUnit.MONTH);
-    }
-
-    @FEFunction(name = "year_floor", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral year_floor(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
false, TimeUnit.YEAR);
-    }
-
-    @FEFunction(name = "year_ceil", argTypes = { "DATETIMEV2", "INT", 
"DATETIMEV2" }, returnType = "DATETIMEV2")
-    public static DateLiteral year_ceil(LiteralExpr datetime, LiteralExpr 
period, LiteralExpr defaultDatetime)
-            throws AnalysisException {
-        return getFloorCeilDateLiteral(datetime, period, defaultDatetime, 
true, TimeUnit.YEAR);
-    }
-
-    @FEFunction(name = "date_trunc", argTypes = {"DATETIME", "VARCHAR"}, 
returnType = "DATETIME")
-    public static DateLiteral dateTruncDatetime(LiteralExpr date, LiteralExpr 
truncate) {
-        if (date.getType().isDateType()) {
-            DateLiteral dateLiteral = ((DateLiteral) date);
-            LocalDateTime localDate = dateTruncHelper(LocalDateTime.of(
-                            (int) dateLiteral.getYear(), (int) 
dateLiteral.getMonth(), (int) dateLiteral.getDay(),
-                            (int) dateLiteral.getHour(), (int) 
dateLiteral.getMinute(), (int) dateLiteral.getSecond()),
-                    truncate.getStringValue());
-
-            return new DateLiteral(localDate.getYear(), 
localDate.getMonthValue(), localDate.getDayOfMonth(),
-                    localDate.getHour(), localDate.getMinute(), 
localDate.getSecond(), date.getType());
-        }
-        return null;
-    }
-
-    @FEFunction(name = "date_trunc", argTypes = {"DATETIMEV2", "VARCHAR"}, 
returnType = "DATETIMEV2")
-    public static DateLiteral dateTruncDatetimeV2(LiteralExpr date, 
LiteralExpr truncate) {
-        if (date.getType().isDateType()) {
-            DateLiteral dateLiteral = ((DateLiteral) date);
-            LocalDateTime localDate = dateTruncHelper(LocalDateTime.of(
-                            (int) dateLiteral.getYear(), (int) 
dateLiteral.getMonth(), (int) dateLiteral.getDay(),
-                            (int) dateLiteral.getHour(), (int) 
dateLiteral.getMinute(), (int) dateLiteral.getSecond()),
-                    truncate.getStringValue());
-
-            return new DateLiteral(localDate.getYear(), 
localDate.getMonthValue(), localDate.getDayOfMonth(),
-                    localDate.getHour(), localDate.getMinute(), 
localDate.getSecond(), date.getType());
-        }
-        return null;
-    }
-
-    @FEFunction(name = "date_trunc", argTypes = { "DATE", "VARCHAR" }, 
returnType = "DATE")
-    public static DateLiteral dateTruncDate(LiteralExpr date, LiteralExpr 
truncate) {
-        if (date.getType().isDateType()) {
-            DateLiteral dateLiteral = ((DateLiteral) date);
-            LocalDateTime localDate = dateTruncHelper(LocalDateTime.of(
-                    (int) dateLiteral.getYear(), (int) dateLiteral.getMonth(), 
(int) dateLiteral.getDay(), 0, 0, 0),
-                    truncate.getStringValue());
-
-            return new DateLiteral(localDate.getYear(), 
localDate.getMonthValue(), localDate.getDayOfMonth(),
-                    localDate.getHour(), localDate.getMinute(), 
localDate.getSecond(), date.getType());
-        }
-        return null;
-    }
-
-    @FEFunction(name = "date_trunc", argTypes = { "DATEV2", "VARCHAR" }, 
returnType = "DATEV2")
-    public static DateLiteral dateTruncDateV2(LiteralExpr date, LiteralExpr 
truncate) {
-        if (date.getType().isDateType()) {
-            DateLiteral dateLiteral = ((DateLiteral) date);
-            LocalDateTime localDate = dateTruncHelper(LocalDateTime.of(
-                    (int) dateLiteral.getYear(), (int) dateLiteral.getMonth(), 
(int) dateLiteral.getDay(), 0, 0, 0),
-                    truncate.getStringValue());
-
-            return new DateLiteral(localDate.getYear(), 
localDate.getMonthValue(), localDate.getDayOfMonth(),
-                    localDate.getHour(), localDate.getMinute(), 
localDate.getSecond(), date.getType());
-        }
-        return null;
-    }
-
-    private static LocalDateTime dateTruncHelper(LocalDateTime dateTime, 
String trunc) {
-        int year = dateTime.getYear();
-        int month = dateTime.getMonthValue();
-        int day = dateTime.getDayOfMonth();
-        int hour = dateTime.getHour();
-        int minute = dateTime.getMinute();
-        int second = dateTime.getSecond();
-        switch (trunc.toLowerCase()) {
-            case "year":
-                month = 0;
-            case "quarter": // CHECKSTYLE IGNORE THIS LINE
-                month = ((month - 1) / 3) * 3 + 1;
-            case "month": // CHECKSTYLE IGNORE THIS LINE
-                day = 1;
-                break;
-            case "week":
-                LocalDateTime firstDayOfWeek = firstDayOfWeek(dateTime);
-                year = firstDayOfWeek.getYear();
-                month = firstDayOfWeek.getMonthValue();
-                day = firstDayOfWeek.getDayOfMonth();
-            default: // CHECKSTYLE IGNORE THIS LINE
-                break;
-        }
-        switch (trunc.toLowerCase()) {
-            case "year":
-            case "quarter":
-            case "month":
-            case "week":
-            case "day": // CHECKSTYLE IGNORE THIS LINE
-                hour = 0;
-            case "hour": // CHECKSTYLE IGNORE THIS LINE
-                minute = 0;
-            case "minute": // CHECKSTYLE IGNORE THIS LINE
-                second = 0;
-            default: // CHECKSTYLE IGNORE THIS LINE
-        }
-        return LocalDateTime.of(year, month, day, hour, minute, second);
-    }
-
-    private static int distanceToFirstDayOfWeek(LocalDateTime dateTime) {
-        return dateTime.getDayOfWeek().getValue() - 1;
-    }
-
-    private static LocalDateTime firstDayOfWeek(LocalDateTime dateTime) {
-        return dateTime.plusDays(-distanceToFirstDayOfWeek(dateTime));
-    }
-
-    private static LocalDateTime toMonday(LocalDateTime dateTime) {
-        LocalDateTime specialUpperBound = LocalDateTime.of(1970, 1, 4, 0, 0, 
0);
-        LocalDateTime specialLowerBound = LocalDateTime.of(1970, 1, 1, 0, 0, 
0);
-        if (dateTime.isAfter(specialUpperBound) || 
dateTime.isBefore(specialLowerBound)) {
-            return dateTime.plusDays(-dateTime.getDayOfWeek().getValue() + 1);
-        }
-        return specialLowerBound;
-    }
-
-    /**
-     
------------------------------------------------------------------------------
-     */
-
-    /**
-     * Math function
-     */
-
-    @FEFunction(name = "floor", argTypes = { "DOUBLE"}, returnType = "BIGINT")
-    public static IntLiteral floor(LiteralExpr expr) throws AnalysisException {
-        long result = (long) Math.floor(expr.getDoubleValue());
-        return new IntLiteral(result, Type.BIGINT);
-    }
-
-    /**
-     
------------------------------------------------------------------------------
-     */
-
-    /**
-     * Arithmetic function
-     */
-
-    @FEFunction(name = "add", argTypes = { "TINYINT", "TINYINT" }, returnType 
= "SMALLINT")
-    public static IntLiteral addTinyint(LiteralExpr first, LiteralExpr second) 
throws AnalysisException {
-        long result = Math.addExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.SMALLINT);
-    }
-
-    @FEFunction(name = "add", argTypes = { "SMALLINT", "SMALLINT" }, 
returnType = "INT")
-    public static IntLiteral addSmallint(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        long result = Math.addExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.INT);
-    }
-
-    @FEFunction(name = "add", argTypes = { "INT", "INT" }, returnType = 
"BIGINT")
-    public static IntLiteral addInt(LiteralExpr first, LiteralExpr second) 
throws AnalysisException {
-        long result = Math.addExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.BIGINT);
-    }
-
-    @FEFunction(name = "add", argTypes = { "BIGINT", "BIGINT" }, returnType = 
"BIGINT")
-    public static IntLiteral addBigint(LiteralExpr first, LiteralExpr second) 
throws AnalysisException {
-        long result = Math.addExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.BIGINT);
-    }
-
-    @FEFunction(name = "add", argTypes = { "DOUBLE", "DOUBLE" }, returnType = 
"DOUBLE")
-    public static FloatLiteral addDouble(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        double result = first.getDoubleValue() + second.getDoubleValue();
-        return new FloatLiteral(result, Type.DOUBLE);
-    }
-
-    @FEFunction(name = "add", argTypes = { "DECIMALV2", "DECIMALV2" }, 
returnType = "DECIMALV2")
-    public static DecimalLiteral addDecimalV2(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        BigDecimal left = new BigDecimal(first.getStringValue());
-        BigDecimal right = new BigDecimal(second.getStringValue());
-
-        BigDecimal result = left.add(right);
-        return new DecimalLiteral(result);
-    }
-
-    @FEFunction(name = "add", argTypes = { "LARGEINT", "LARGEINT" }, 
returnType = "LARGEINT")
-    public static LargeIntLiteral addBigInt(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        BigInteger left = new BigInteger(first.getStringValue());
-        BigInteger right = new BigInteger(second.getStringValue());
-        BigInteger result = left.add(right);
-        return new LargeIntLiteral(result.toString());
-    }
-
-    @FEFunction(name = "subtract", argTypes = { "TINYINT", "TINYINT" }, 
returnType = "SMALLINT")
-    public static IntLiteral subtractTinyint(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        long result = Math.subtractExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.SMALLINT);
-    }
-
-    @FEFunction(name = "subtract", argTypes = { "SMALLINT", "SMALLINT" }, 
returnType = "INT")
-    public static IntLiteral subtractSmallint(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        long result = Math.subtractExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.INT);
-    }
-
-    @FEFunction(name = "subtract", argTypes = { "INT", "INT" }, returnType = 
"BIGINT")
-    public static IntLiteral subtractInt(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        long result = Math.subtractExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.BIGINT);
-    }
-
-    @FEFunction(name = "subtract", argTypes = { "BIGINT", "BIGINT" }, 
returnType = "BIGINT")
-    public static IntLiteral subtractBigint(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        long result = Math.subtractExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.BIGINT);
-    }
-
-    @FEFunction(name = "subtract", argTypes = { "DOUBLE", "DOUBLE" }, 
returnType = "DOUBLE")
-    public static FloatLiteral subtractDouble(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        double result = first.getDoubleValue() - second.getDoubleValue();
-        return new FloatLiteral(result, Type.DOUBLE);
-    }
-
-    @FEFunction(name = "subtract", argTypes = { "DECIMALV2", "DECIMALV2" }, 
returnType = "DECIMALV2")
-    public static DecimalLiteral subtractDecimalV2(LiteralExpr first, 
LiteralExpr second) throws AnalysisException {
-        BigDecimal left = new BigDecimal(first.getStringValue());
-        BigDecimal right = new BigDecimal(second.getStringValue());
-
-        BigDecimal result = left.subtract(right);
-        return new DecimalLiteral(result);
-    }
-
-    @FEFunction(name = "subtract", argTypes = { "LARGEINT", "LARGEINT" }, 
returnType = "LARGEINT")
-    public static LargeIntLiteral subtractBigInt(LiteralExpr first, 
LiteralExpr second) throws AnalysisException {
-        BigInteger left = new BigInteger(first.getStringValue());
-        BigInteger right = new BigInteger(second.getStringValue());
-        BigInteger result = left.subtract(right);
-        return new LargeIntLiteral(result.toString());
-    }
-
-    @FEFunction(name = "multiply", argTypes = { "TINYINT", "TINYINT" }, 
returnType = "SMALLINT")
-    public static IntLiteral multiplyTinyint(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        long result = Math.multiplyExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.SMALLINT);
-    }
-
-    @FEFunction(name = "multiply", argTypes = { "SMALLINT", "SMALLINT" }, 
returnType = "INT")
-    public static IntLiteral multiplySmallint(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        long result = Math.multiplyExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.INT);
-    }
-
-    @FEFunction(name = "multiply", argTypes = { "INT", "INT" }, returnType = 
"BIGINT")
-    public static IntLiteral multiplyInt(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        long result = Math.multiplyExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.BIGINT);
-    }
-
-    @FEFunction(name = "multiply", argTypes = { "BIGINT", "BIGINT" }, 
returnType = "BIGINT")
-    public static IntLiteral multiplyBigint(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        long result = Math.multiplyExact(first.getLongValue(), 
second.getLongValue());
-        return new IntLiteral(result, Type.BIGINT);
-    }
-
-    @FEFunction(name = "multiply", argTypes = { "DOUBLE", "DOUBLE" }, 
returnType = "DOUBLE")
-    public static FloatLiteral multiplyDouble(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        double result = first.getDoubleValue() * second.getDoubleValue();
-        return new FloatLiteral(result, Type.DOUBLE);
-    }
-
-    @FEFunction(name = "multiply", argTypes = { "DECIMALV2", "DECIMALV2" }, 
returnType = "DECIMALV2")
-    public static DecimalLiteral multiplyDecimalV2(LiteralExpr first, 
LiteralExpr second) throws AnalysisException {
-        BigDecimal left = new BigDecimal(first.getStringValue());
-        BigDecimal right = new BigDecimal(second.getStringValue());
-
-        BigDecimal result = left.multiply(right);
-        return new DecimalLiteral(result);
-    }
-
-    @FEFunction(name = "multiply", argTypes = { "LARGEINT", "LARGEINT" }, 
returnType = "LARGEINT")
-    public static LargeIntLiteral multiplyBigInt(LiteralExpr first, 
LiteralExpr second) throws AnalysisException {
-        BigInteger left = new BigInteger(first.getStringValue());
-        BigInteger right = new BigInteger(second.getStringValue());
-        BigInteger result = left.multiply(right);
-        return new LargeIntLiteral(result.toString());
-    }
-
-    @FEFunction(name = "divide", argTypes = { "DOUBLE", "DOUBLE" }, returnType 
= "DOUBLE")
-    public static FloatLiteral divideDouble(LiteralExpr first, LiteralExpr 
second) throws AnalysisException {
-        if (second.getDoubleValue() == 0.0) {
-            return null;
-        }
-        double result = first.getDoubleValue() / second.getDoubleValue();
-        return new FloatLiteral(result, Type.DOUBLE);
-    }
-
-    @FEFunction(name = "divide", argTypes = { "DECIMALV2", "DECIMALV2" }, 
returnType = "DECIMALV2")
-    public static DecimalLiteral divideDecimalV2(LiteralExpr first, 
LiteralExpr second) throws AnalysisException {
-        BigDecimal left = new BigDecimal(first.getStringValue());
-        BigDecimal right = new BigDecimal(second.getStringValue());
-        if (right.compareTo(BigDecimal.ZERO) == 0) {
-            return null;
-        }
-        BigDecimal result = left.divide(right);
-        return new DecimalLiteral(result);
-    }
-
-    @FEFunction(name = "concat", argTypes = { "VARCHAR"}, returnType = 
"VARCHAR")
-    public static StringLiteral concat(StringLiteral... values) throws 
AnalysisException {
-        Preconditions.checkArgument(values.length > 0);
-        final StringBuilder resultBuilder = new StringBuilder();
-        for (StringLiteral value : values) {
-            resultBuilder.append(value.getStringValue());
-        }
-        return new StringLiteral(resultBuilder.toString());
-    }
-
-    @FEFunction(name = "concat_ws", argTypes = {"VARCHAR", "VARCHAR"}, 
returnType = "VARCHAR")
-    public static StringLiteral concat_ws(StringLiteral split, 
StringLiteral... values) throws AnalysisException {
-        Preconditions.checkArgument(values.length > 0);
-        final StringBuilder resultBuilder = new StringBuilder();
-        for (int i = 0; i < values.length - 1; i++) {
-            
resultBuilder.append(values[i].getStringValue()).append(split.getStringValue());
-        }
-        resultBuilder.append(values[values.length - 1].getStringValue());
-        return new StringLiteral(resultBuilder.toString());
-    }
-
-    @FEFunctionList({
-        @FEFunction(name = "ifnull", argTypes = {"VARCHAR", "VARCHAR"}, 
returnType = "VARCHAR"),
-        @FEFunction(name = "ifnull", argTypes = {"TINYINT", "TINYINT"}, 
returnType = "TINYINT"),
-        @FEFunction(name = "ifnull", argTypes = {"INT", "INT"}, returnType = 
"INT"),
-        @FEFunction(name = "ifnull", argTypes = {"BIGINT", "BIGINT"}, 
returnType = "BIGINT"),
-        @FEFunction(name = "ifnull", argTypes = {"DATETIME", "DATETIME"}, 
returnType = "DATETIME"),
-        @FEFunction(name = "ifnull", argTypes = { "DATE", "DATETIME" }, 
returnType = "DATETIME"),
-        @FEFunction(name = "ifnull", argTypes = { "DATETIME", "DATE" }, 
returnType = "DATETIME")
-    })
-    public static LiteralExpr ifNull(LiteralExpr first, LiteralExpr second) 
throws AnalysisException {
-        return first instanceof NullLiteral ? second : first;
-    }
-
-    // maybe use alias info to reduce redundant code
-    @FEFunctionList({
-        @FEFunction(name = "nvl", argTypes = {"VARCHAR", "VARCHAR"}, 
returnType = "VARCHAR"),
-        @FEFunction(name = "nvl", argTypes = {"TINYINT", "TINYINT"}, 
returnType = "TINYINT"),
-        @FEFunction(name = "nvl", argTypes = {"INT", "INT"}, returnType = 
"INT"),
-        @FEFunction(name = "nvl", argTypes = {"BIGINT", "BIGINT"}, returnType 
= "BIGINT"),
-        @FEFunction(name = "nvl", argTypes = {"DATETIME", "DATETIME"}, 
returnType = "DATETIME"),
-        @FEFunction(name = "nvl", argTypes = { "DATE", "DATETIME" }, 
returnType = "DATETIME"),
-        @FEFunction(name = "nvl", argTypes = { "DATETIME", "DATE" }, 
returnType = "DATETIME")
-    })
-    public static LiteralExpr nvl(LiteralExpr first, LiteralExpr second) 
throws AnalysisException {
-        return first instanceof NullLiteral ? second : first;
-    }
-
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to