From 53cae060b888b3c14651e8199ac6e697f5f32eed Mon Sep 17 00:00:00 2001 From: LiBinfeng <1204975323@qq.com> Date: Wed, 16 Oct 2024 11:08:01 +0800 Subject: [PATCH 1/3] [Feat](Nereids) support fold const by fe --- .../apache/doris/analysis/FloatLiteral.java | 3 + .../trees/expressions/ExecFunction.java | 14 - .../expressions/ExpressionEvaluator.java | 218 ++---- .../functions/executable/DateTimeAcquire.java | 24 +- .../executable/DateTimeArithmetic.java | 162 ++-- .../DateTimeExtractAndTransform.java | 292 +++---- .../executable/ExecutableFunctions.java | 132 ---- .../executable/NumericArithmetic.java | 740 +++++++++++++++--- .../executable/StringArithmetic.java | 108 +-- .../functions/executable/TimeRoundSeries.java | 288 +++---- .../expressions/literal/DecimalV3Literal.java | 28 + .../rules/expression/FoldConstantTest.java | 235 +++++- .../functions/ExecutableFunctionsTest.java | 64 -- .../datatype_p0/double/test_double_nan.out | 4 - .../data/datatype_p0/float/test_float_nan.out | 4 - .../datatype_p0/double/test_double_nan.groovy | 13 +- .../datatype_p0/float/test_float_nan.groovy | 12 +- .../string/test_string_basic.groovy | 3 +- .../scalar_function/A.groovy | 5 +- .../fold_constant/fold_constant_by_fe.groovy | 9 +- .../fold_constant_numeric_arithmatic.groovy | 412 ++++++++++ .../fold_constant_string_arithmatic.groovy | 7 +- .../test_multi_range_partition.groovy | 2 +- 23 files changed, 1889 insertions(+), 890 deletions(-) delete mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/ExecutableFunctionsTest.java create mode 100644 regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_numeric_arithmatic.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java index c6cf403f949e71..8d4a9ef576523e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java @@ -159,6 +159,9 @@ public String getStringValueInFe(FormatOptions options) { String timeStr = getStringValue(); return timeStr.substring(1, timeStr.length() - 1); } else { + if (Double.isInfinite(getValue())) { + return Double.toString(getValue()); + } return BigDecimal.valueOf(getValue()).toPlainString(); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExecFunction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExecFunction.java index 126449f4b04e34..a5c656d5ffa185 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExecFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExecFunction.java @@ -34,18 +34,4 @@ */ String name(); - /** - * args type - */ - String[] argTypes(); - - /** - * return type - */ - String returnType(); - - /** - * hasVarArgsc - */ - boolean varArgs() default false; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExpressionEvaluator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExpressionEvaluator.java index f3d471b2abedc4..0233b9882663da 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExpressionEvaluator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ExpressionEvaluator.java @@ -18,22 +18,20 @@ package org.apache.doris.nereids.trees.expressions; import org.apache.doris.catalog.Env; -import org.apache.doris.catalog.Type; -import org.apache.doris.common.AnalysisException; +import org.apache.doris.nereids.exceptions.NotSupportedException; import org.apache.doris.nereids.trees.expressions.functions.BoundFunction; import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeAcquire; import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeArithmetic; import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeExtractAndTransform; -import org.apache.doris.nereids.trees.expressions.functions.executable.ExecutableFunctions; import org.apache.doris.nereids.trees.expressions.functions.executable.NumericArithmetic; import org.apache.doris.nereids.trees.expressions.functions.executable.StringArithmetic; import org.apache.doris.nereids.trees.expressions.functions.executable.TimeRoundSeries; import org.apache.doris.nereids.trees.expressions.literal.DateLiteral; +import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.literal.NullLiteral; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.util.TypeCoercionUtils; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; @@ -41,7 +39,6 @@ import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -52,7 +49,7 @@ public enum ExpressionEvaluator { INSTANCE; - private ImmutableMultimap functions; + private ImmutableMultimap functions; ExpressionEvaluator() { registerFunctions(); @@ -68,23 +65,16 @@ public Expression eval(Expression expression) { } String fnName = null; - DataType[] args = null; DataType ret = expression.getDataType(); if (expression instanceof BinaryArithmetic) { BinaryArithmetic arithmetic = (BinaryArithmetic) expression; fnName = arithmetic.getLegacyOperator().getName(); - args = new DataType[]{arithmetic.left().getDataType(), arithmetic.right().getDataType()}; } else if (expression instanceof TimestampArithmetic) { TimestampArithmetic arithmetic = (TimestampArithmetic) expression; fnName = arithmetic.getFuncName(); - args = new DataType[]{arithmetic.left().getDataType(), arithmetic.right().getDataType()}; } else if (expression instanceof BoundFunction) { BoundFunction function = ((BoundFunction) expression); fnName = function.getName(); - args = new DataType[function.arity()]; - for (int i = 0; i < function.children().size(); i++) { - args[i] = function.child(i).getDataType(); - } } if ((Env.getCurrentEnv().isNullResultWithOneNullParamFunction(fnName))) { @@ -95,25 +85,27 @@ public Expression eval(Expression expression) { } } - return invoke(expression, fnName, args); + return invoke(expression, fnName); } - private Expression invoke(Expression expression, String fnName, DataType[] args) { - FunctionSignature signature = new FunctionSignature(fnName, args, null, false); - FunctionInvoker invoker = getFunction(signature); - if (invoker != null) { + private Expression invoke(Expression expression, String fnName) { + Method method = getFunction(fnName, expression.children()); + if (method != null) { try { - if (invoker.getSignature().hasVarArgs()) { - int fixedArgsSize = invoker.getSignature().getArgTypes().length - 1; - int totalSize = expression.children().size(); - Class[] parameterTypes = invoker.getMethod().getParameterTypes(); - Class parameterType = parameterTypes[parameterTypes.length - 1]; + int varSize = method.getParameterTypes().length; + if (varSize == 0) { + return (Literal) method.invoke(null, expression.children().toArray()); + } + boolean hasVarArgs = method.getParameterTypes()[varSize - 1].isArray(); + if (hasVarArgs) { + int fixedArgsSize = varSize - 1; + int inputSize = expression.children().size(); + Class[] parameterTypes = method.getParameterTypes(); + Class parameterType = parameterTypes[varSize - 1]; Class componentType = parameterType.getComponentType(); - Object varArgs = Array.newInstance(componentType, totalSize - fixedArgsSize); - for (int i = fixedArgsSize; i < totalSize; i++) { - if (!(expression.children().get(i) instanceof NullLiteral)) { - Array.set(varArgs, i - fixedArgsSize, expression.children().get(i)); - } + Object varArgs = Array.newInstance(componentType, inputSize - fixedArgsSize); + for (int i = fixedArgsSize; i < inputSize; i++) { + Array.set(varArgs, i - fixedArgsSize, expression.children().get(i)); } Object[] objects = new Object[fixedArgsSize + 1]; for (int i = 0; i < fixedArgsSize; i++) { @@ -121,59 +113,76 @@ private Expression invoke(Expression expression, String fnName, DataType[] args) } objects[fixedArgsSize] = varArgs; - return invoker.invokeVars(objects); + return (Literal) method.invoke(null, objects); + } + return (Literal) method.invoke(null, expression.children().toArray()); + } catch (InvocationTargetException e) { + if (e.getTargetException() instanceof NotSupportedException) { + throw new NotSupportedException(e.getTargetException().getMessage()); + } else { + return expression; } - return invoker.invoke(expression.children()); - } catch (AnalysisException e) { + } catch (IllegalAccessException | IllegalArgumentException e) { return expression; } } return expression; } - private FunctionInvoker getFunction(FunctionSignature signature) { - Collection functionInvokers = functions.get(signature.getName()); - for (FunctionInvoker candidate : functionInvokers) { - DataType[] candidateTypes = candidate.getSignature().getArgTypes(); - DataType[] expectedTypes = signature.getArgTypes(); + private boolean canDownCastTo(Class expect, Class input) { + if (DateLiteral.class.isAssignableFrom(expect) + || DateTimeLiteral.class.isAssignableFrom(expect)) { + return expect.equals(input); + } + return expect.isAssignableFrom(input); + } - if (candidate.getSignature().hasVarArgs()) { - if (candidateTypes.length > expectedTypes.length) { + private Method getFunction(String fnName, List inputs) { + Collection expectMethods = functions.get(fnName); + for (Method expect : expectMethods) { + boolean match = true; + int varSize = expect.getParameterTypes().length; + if (varSize == 0) { + if (inputs.size() == 0) { + return expect; + } else { + continue; + } + } + boolean hasVarArgs = expect.getParameterTypes()[varSize - 1].isArray(); + if (hasVarArgs) { + int fixedArgsSize = varSize - 1; + int inputSize = inputs.size(); + if (inputSize <= fixedArgsSize) { continue; } - boolean match = true; - for (int i = 0; i < candidateTypes.length - 1; i++) { - if (!(expectedTypes[i].toCatalogDataType().matchesType(candidateTypes[i].toCatalogDataType()))) { + Class[] expectVarTypes = expect.getParameterTypes(); + for (int i = 0; i < fixedArgsSize; i++) { + if (!canDownCastTo(expectVarTypes[i], inputs.get(i).getClass())) { match = false; - break; } } - Type varType = candidateTypes[candidateTypes.length - 1].toCatalogDataType(); - for (int i = candidateTypes.length - 1; i < expectedTypes.length; i++) { - if (!(expectedTypes[i].toCatalogDataType().matchesType(varType))) { + Class varArgsType = expectVarTypes[varSize - 1]; + Class varArgType = varArgsType.getComponentType(); + for (int i = fixedArgsSize; i < inputSize; i++) { + if (!canDownCastTo(varArgType, inputs.get(i).getClass())) { match = false; - break; } } - if (match) { - return candidate; - } else { + } else { + int inputSize = inputs.size(); + if (inputSize != varSize) { continue; } - } - if (candidateTypes.length != expectedTypes.length) { - continue; - } - - boolean match = true; - for (int i = 0; i < candidateTypes.length; i++) { - if (!(expectedTypes[i].toCatalogDataType().matchesType(candidateTypes[i].toCatalogDataType()))) { - match = false; - break; + Class[] expectVarTypes = expect.getParameterTypes(); + for (int i = 0; i < varSize; i++) { + if (!canDownCastTo(expectVarTypes[i], inputs.get(i).getClass())) { + match = false; + } } } if (match) { - return candidate; + return expect; } } return null; @@ -183,11 +192,10 @@ private void registerFunctions() { if (functions != null) { return; } - ImmutableMultimap.Builder mapBuilder = new ImmutableMultimap.Builder<>(); + ImmutableMultimap.Builder mapBuilder = new ImmutableMultimap.Builder<>(); List> classes = ImmutableList.of( DateTimeAcquire.class, DateTimeExtractAndTransform.class, - ExecutableFunctions.class, DateLiteral.class, DateTimeArithmetic.class, NumericArithmetic.class, @@ -208,92 +216,10 @@ private void registerFunctions() { this.functions = mapBuilder.build(); } - private void registerFEFunction(ImmutableMultimap.Builder mapBuilder, + private void registerFEFunction(ImmutableMultimap.Builder mapBuilder, Method method, ExecFunction annotation) { if (annotation != null) { - String name = annotation.name(); - DataType returnType = DataType.convertFromString(annotation.returnType()); - List argTypes = new ArrayList<>(); - for (String type : annotation.argTypes()) { - argTypes.add(TypeCoercionUtils.replaceDecimalV3WithWildcard(DataType.convertFromString(type))); - } - DataType[] array = new DataType[argTypes.size()]; - for (int i = 0; i < argTypes.size(); i++) { - array[i] = argTypes.get(i); - } - FunctionSignature signature = new FunctionSignature(name, array, returnType, annotation.varArgs()); - mapBuilder.put(name, new FunctionInvoker(method, signature)); + mapBuilder.put(annotation.name(), method); } } - - /** - * function invoker. - */ - public static class FunctionInvoker { - private final Method method; - private final FunctionSignature signature; - - public FunctionInvoker(Method method, FunctionSignature signature) { - this.method = method; - this.signature = signature; - } - - public Method getMethod() { - return method; - } - - public FunctionSignature getSignature() { - return signature; - } - - public Literal invoke(List args) throws AnalysisException { - try { - return (Literal) method.invoke(null, args.toArray()); - } catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) { - throw new AnalysisException(e.getLocalizedMessage()); - } - } - - public Literal invokeVars(Object[] args) throws AnalysisException { - try { - return (Literal) method.invoke(null, args); - } catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) { - throw new AnalysisException(e.getLocalizedMessage()); - } - } - } - - /** - * function signature. - */ - public static class FunctionSignature { - private final String name; - private final DataType[] argTypes; - private final DataType returnType; - private final boolean hasVarArgs; - - public FunctionSignature(String name, DataType[] argTypes, DataType returnType, boolean hasVarArgs) { - this.name = name; - this.argTypes = argTypes; - this.returnType = returnType; - this.hasVarArgs = hasVarArgs; - } - - public DataType[] getArgTypes() { - return argTypes; - } - - public DataType getReturnType() { - return returnType; - } - - public String getName() { - return name; - } - - public boolean hasVarArgs() { - return hasVarArgs; - } - } - } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeAcquire.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeAcquire.java index 17403bd83c0770..98d2ebfaf769ba 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeAcquire.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeAcquire.java @@ -36,12 +36,12 @@ public class DateTimeAcquire { /** * date acquire function: now */ - @ExecFunction(name = "now", argTypes = {}, returnType = "DATETIME") + @ExecFunction(name = "now") public static Expression now() { return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone())); } - @ExecFunction(name = "now", argTypes = {"INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "now") public static Expression now(IntegerLiteral precision) { return DateTimeV2Literal.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()), precision.getValue()); @@ -50,12 +50,12 @@ public static Expression now(IntegerLiteral precision) { /** * date acquire function: current_timestamp */ - @ExecFunction(name = "current_timestamp", argTypes = {}, returnType = "DATETIME") + @ExecFunction(name = "current_timestamp") public static Expression currentTimestamp() { return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone())); } - @ExecFunction(name = "current_timestamp", argTypes = {"INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "current_timestamp") public static Expression currentTimestamp(IntegerLiteral precision) { return DateTimeV2Literal.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone()), precision.getValue()); } @@ -63,12 +63,12 @@ public static Expression currentTimestamp(IntegerLiteral precision) { /** * date acquire function: localtime/localtimestamp */ - @ExecFunction(name = "localtime", argTypes = {}, returnType = "DATETIME") + @ExecFunction(name = "localtime") public static Expression localTime() { return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone())); } - @ExecFunction(name = "localtimestamp", argTypes = {}, returnType = "DATETIME") + @ExecFunction(name = "localtimestamp") public static Expression localTimestamp() { return DateTimeV2Literal.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone())); } @@ -76,12 +76,12 @@ public static Expression localTimestamp() { /** * date acquire function: current_date */ - @ExecFunction(name = "curdate", argTypes = {}, returnType = "DATE") + @ExecFunction(name = "curdate") public static Expression curDate() { return DateLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone())); } - @ExecFunction(name = "current_date", argTypes = {}, returnType = "DATE") + @ExecFunction(name = "current_date") public static Expression currentDate() { return DateLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone())); } @@ -90,12 +90,12 @@ public static Expression currentDate() { // /** // * date acquire function: current_time // */ - // @ExecFunction(name = "curtime", argTypes = {}, returnType = "TIME") + // @ExecFunction(name = "curtime") // public static Expression curTime() { // return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone())); // } - // @ExecFunction(name = "current_time", argTypes = {}, returnType = "TIME") + // @ExecFunction(name = "current_time") // public static Expression currentTime() { // return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(DateUtils.getTimeZone())); // } @@ -103,7 +103,7 @@ public static Expression currentDate() { /** * date transformation function: unix_timestamp */ - @ExecFunction(name = "unix_timestamp", argTypes = {}, returnType = "INT") + @ExecFunction(name = "unix_timestamp") public static Expression unixTimestamp() { return new IntegerLiteral((int) (System.currentTimeMillis() / 1000L)); } @@ -111,7 +111,7 @@ public static Expression unixTimestamp() { /** * date transformation function: utc_timestamp */ - @ExecFunction(name = "utc_timestamp", argTypes = {}, returnType = "INT") + @ExecFunction(name = "utc_timestamp") public static Expression utcTimestamp() { return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(ZoneId.of("UTC+0"))); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeArithmetic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeArithmetic.java index c10181a1040db4..84e5ebf272ad82 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeArithmetic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeArithmetic.java @@ -36,22 +36,22 @@ public class DateTimeArithmetic { /** * datetime arithmetic function date-add. */ - @ExecFunction(name = "date_add", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "date_add") public static Expression dateAdd(DateLiteral date, IntegerLiteral day) { return daysAdd(date, day); } - @ExecFunction(name = "date_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "date_add") public static Expression dateAdd(DateTimeLiteral date, IntegerLiteral day) { return daysAdd(date, day); } - @ExecFunction(name = "date_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "date_add") public static Expression dateAdd(DateV2Literal date, IntegerLiteral day) { return daysAdd(date, day); } - @ExecFunction(name = "date_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "date_add") public static Expression dateAdd(DateTimeV2Literal date, IntegerLiteral day) { return daysAdd(date, day); } @@ -59,22 +59,22 @@ public static Expression dateAdd(DateTimeV2Literal date, IntegerLiteral day) { /** * datetime arithmetic function date-sub. */ - @ExecFunction(name = "date_sub", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "date_sub") public static Expression dateSub(DateLiteral date, IntegerLiteral day) { return dateAdd(date, new IntegerLiteral(-day.getValue())); } - @ExecFunction(name = "date_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "date_sub") public static Expression dateSub(DateTimeLiteral date, IntegerLiteral day) { return dateAdd(date, new IntegerLiteral(-day.getValue())); } - @ExecFunction(name = "date_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "date_sub") public static Expression dateSub(DateV2Literal date, IntegerLiteral day) { return dateAdd(date, new IntegerLiteral(-day.getValue())); } - @ExecFunction(name = "date_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "date_sub") public static Expression dateSub(DateTimeV2Literal date, IntegerLiteral day) { return dateAdd(date, new IntegerLiteral(-day.getValue())); } @@ -82,22 +82,22 @@ public static Expression dateSub(DateTimeV2Literal date, IntegerLiteral day) { /** * datetime arithmetic function years-add. */ - @ExecFunction(name = "years_add", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "years_add") public static Expression yearsAdd(DateLiteral date, IntegerLiteral year) { return date.plusYears(year.getValue()); } - @ExecFunction(name = "years_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "years_add") public static Expression yearsAdd(DateTimeLiteral date, IntegerLiteral year) { return date.plusYears(year.getValue()); } - @ExecFunction(name = "years_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "years_add") public static Expression yearsAdd(DateV2Literal date, IntegerLiteral year) { return date.plusYears(year.getValue()); } - @ExecFunction(name = "years_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "years_add") public static Expression yearsAdd(DateTimeV2Literal date, IntegerLiteral year) { return date.plusYears(year.getValue()); } @@ -105,22 +105,22 @@ public static Expression yearsAdd(DateTimeV2Literal date, IntegerLiteral year) { /** * datetime arithmetic function months-add. */ - @ExecFunction(name = "months_add", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "months_add") public static Expression monthsAdd(DateLiteral date, IntegerLiteral month) { return date.plusMonths(month.getValue()); } - @ExecFunction(name = "months_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "months_add") public static Expression monthsAdd(DateTimeLiteral date, IntegerLiteral month) { return date.plusMonths(month.getValue()); } - @ExecFunction(name = "months_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "months_add") public static Expression monthsAdd(DateV2Literal date, IntegerLiteral month) { return date.plusMonths(month.getValue()); } - @ExecFunction(name = "months_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "months_add") public static Expression monthsAdd(DateTimeV2Literal date, IntegerLiteral month) { return date.plusMonths(month.getValue()); } @@ -128,22 +128,22 @@ public static Expression monthsAdd(DateTimeV2Literal date, IntegerLiteral month) /** * datetime arithmetic function weeks-add. */ - @ExecFunction(name = "weeks_add", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "weeks_add") public static Expression weeksAdd(DateLiteral date, IntegerLiteral weeks) { return date.plusWeeks(weeks.getValue()); } - @ExecFunction(name = "weeks_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "weeks_add") public static Expression weeksAdd(DateTimeLiteral date, IntegerLiteral weeks) { return date.plusWeeks(weeks.getValue()); } - @ExecFunction(name = "weeks_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "weeks_add") public static Expression weeksAdd(DateV2Literal date, IntegerLiteral weeks) { return date.plusWeeks(weeks.getValue()); } - @ExecFunction(name = "weeks_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "weeks_add") public static Expression weeksAdd(DateTimeV2Literal date, IntegerLiteral weeks) { return date.plusWeeks(weeks.getValue()); } @@ -151,22 +151,22 @@ public static Expression weeksAdd(DateTimeV2Literal date, IntegerLiteral weeks) /** * datetime arithmetic function days-add. */ - @ExecFunction(name = "days_add", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "days_add") public static Expression daysAdd(DateLiteral date, IntegerLiteral day) { return date.plusDays(day.getValue()); } - @ExecFunction(name = "days_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "days_add") public static Expression daysAdd(DateTimeLiteral date, IntegerLiteral day) { return date.plusDays(day.getValue()); } - @ExecFunction(name = "days_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "days_add") public static Expression daysAdd(DateV2Literal date, IntegerLiteral day) { return date.plusDays(day.getValue()); } - @ExecFunction(name = "days_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "days_add") public static Expression daysAdd(DateTimeV2Literal date, IntegerLiteral day) { return date.plusDays(day.getValue()); } @@ -174,12 +174,22 @@ public static Expression daysAdd(DateTimeV2Literal date, IntegerLiteral day) { /** * datetime arithmetic function hours-add. */ - @ExecFunction(name = "hours_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "hours_add") + public static Expression hoursAdd(DateLiteral date, IntegerLiteral hour) { + return date.toBeginOfTheDay().plusHours(hour.getValue()); + } + + @ExecFunction(name = "hours_add") + public static Expression hoursAdd(DateV2Literal date, IntegerLiteral hour) { + return date.toBeginOfTheDay().plusHours(hour.getValue()); + } + + @ExecFunction(name = "hours_add") public static Expression hoursAdd(DateTimeLiteral date, IntegerLiteral hour) { return date.plusHours(hour.getValue()); } - @ExecFunction(name = "hours_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hours_add") public static Expression hoursAdd(DateTimeV2Literal date, IntegerLiteral hour) { return date.plusHours(hour.getValue()); } @@ -187,12 +197,22 @@ public static Expression hoursAdd(DateTimeV2Literal date, IntegerLiteral hour) { /** * datetime arithmetic function minutes-add. */ - @ExecFunction(name = "minutes_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "minutes_add") + public static Expression minutesAdd(DateLiteral date, IntegerLiteral minute) { + return date.toBeginOfTheDay().plusMinutes(minute.getValue()); + } + + @ExecFunction(name = "minutes_add") + public static Expression minutesAdd(DateV2Literal date, IntegerLiteral minute) { + return date.toBeginOfTheDay().plusMinutes(minute.getValue()); + } + + @ExecFunction(name = "minutes_add") public static Expression minutesAdd(DateTimeLiteral date, IntegerLiteral minute) { return date.plusMinutes(minute.getValue()); } - @ExecFunction(name = "minutes_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minutes_add") public static Expression minutesAdd(DateTimeV2Literal date, IntegerLiteral minute) { return date.plusMinutes(minute.getValue()); } @@ -200,12 +220,22 @@ public static Expression minutesAdd(DateTimeV2Literal date, IntegerLiteral minut /** * datetime arithmetic function seconds-add. */ - @ExecFunction(name = "seconds_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "seconds_add") + public static Expression secondsAdd(DateLiteral date, IntegerLiteral second) { + return date.toBeginOfTheDay().plusSeconds(second.getValue()); + } + + @ExecFunction(name = "seconds_add") + public static Expression secondsAdd(DateV2Literal date, IntegerLiteral second) { + return date.toBeginOfTheDay().plusSeconds(second.getValue()); + } + + @ExecFunction(name = "seconds_add") public static Expression secondsAdd(DateTimeLiteral date, IntegerLiteral second) { return date.plusSeconds(second.getValue()); } - @ExecFunction(name = "seconds_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "seconds_add") public static Expression secondsAdd(DateTimeV2Literal date, IntegerLiteral second) { return date.plusSeconds(second.getValue()); } @@ -213,7 +243,7 @@ public static Expression secondsAdd(DateTimeV2Literal date, IntegerLiteral secon /** * datetime arithmetic function microseconds-add. */ - @ExecFunction(name = "microseconds_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "microseconds_add") public static Expression microSecondsAdd(DateTimeV2Literal date, IntegerLiteral microSecond) { return date.plusMicroSeconds(microSecond.getValue()); } @@ -221,7 +251,7 @@ public static Expression microSecondsAdd(DateTimeV2Literal date, IntegerLiteral /** * datetime arithmetic function microseconds_sub. */ - @ExecFunction(name = "microseconds_sub", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2") + @ExecFunction(name = "microseconds_sub") public static Expression microSecondsSub(DateTimeV2Literal date, IntegerLiteral microSecond) { return date.plusMicroSeconds(-microSecond.getValue()); } @@ -229,7 +259,7 @@ public static Expression microSecondsSub(DateTimeV2Literal date, IntegerLiteral /** * datetime arithmetic function milliseconds_add. */ - @ExecFunction(name = "milliseconds_add", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2") + @ExecFunction(name = "milliseconds_add") public static Expression milliSecondsAdd(DateTimeV2Literal date, IntegerLiteral milliSecond) { return date.plusMilliSeconds(milliSecond.getValue()); } @@ -237,7 +267,7 @@ public static Expression milliSecondsAdd(DateTimeV2Literal date, IntegerLiteral /** * datetime arithmetic function milliseconds_sub. */ - @ExecFunction(name = "milliseconds_sub", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2") + @ExecFunction(name = "milliseconds_sub") public static Expression milliSecondsSub(DateTimeV2Literal date, IntegerLiteral milliSecond) { return date.plusMilliSeconds(-milliSecond.getValue()); } @@ -245,22 +275,22 @@ public static Expression milliSecondsSub(DateTimeV2Literal date, IntegerLiteral /** * datetime arithmetic function years-sub. */ - @ExecFunction(name = "years_sub", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "years_sub") public static Expression yearsSub(DateLiteral date, IntegerLiteral year) { return yearsAdd(date, new IntegerLiteral(-year.getValue())); } - @ExecFunction(name = "years_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "years_sub") public static Expression yearsSub(DateTimeLiteral date, IntegerLiteral year) { return yearsAdd(date, new IntegerLiteral(-year.getValue())); } - @ExecFunction(name = "years_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "years_sub") public static Expression yearsSub(DateV2Literal date, IntegerLiteral year) { return yearsAdd(date, new IntegerLiteral(-year.getValue())); } - @ExecFunction(name = "years_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "years_sub") public static Expression yearsSub(DateTimeV2Literal date, IntegerLiteral year) { return yearsAdd(date, new IntegerLiteral(-year.getValue())); } @@ -268,22 +298,22 @@ public static Expression yearsSub(DateTimeV2Literal date, IntegerLiteral year) { /** * datetime arithmetic function months-sub */ - @ExecFunction(name = "months_sub", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "months_sub") public static Expression monthsSub(DateLiteral date, IntegerLiteral month) { return monthsAdd(date, new IntegerLiteral(-month.getValue())); } - @ExecFunction(name = "months_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "months_sub") public static Expression monthsSub(DateTimeLiteral date, IntegerLiteral month) { return monthsAdd(date, new IntegerLiteral(-month.getValue())); } - @ExecFunction(name = "months_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "months_sub") public static Expression monthsSub(DateV2Literal date, IntegerLiteral month) { return monthsAdd(date, new IntegerLiteral(-month.getValue())); } - @ExecFunction(name = "months_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "months_sub") public static Expression monthsSub(DateTimeV2Literal date, IntegerLiteral month) { return monthsAdd(date, new IntegerLiteral(-month.getValue())); } @@ -291,22 +321,22 @@ public static Expression monthsSub(DateTimeV2Literal date, IntegerLiteral month) /** * datetime arithmetic function weeks-sub. */ - @ExecFunction(name = "weeks_sub", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "weeks_sub") public static Expression weeksSub(DateLiteral date, IntegerLiteral weeks) { return date.plusWeeks(-weeks.getValue()); } - @ExecFunction(name = "weeks_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "weeks_sub") public static Expression weeksSub(DateTimeLiteral date, IntegerLiteral weeks) { return date.plusWeeks(-weeks.getValue()); } - @ExecFunction(name = "weeks_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "weeks_sub") public static Expression weeksSub(DateV2Literal date, IntegerLiteral weeks) { return date.plusWeeks(-weeks.getValue()); } - @ExecFunction(name = "weeks_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "weeks_sub") public static Expression weeksSub(DateTimeV2Literal date, IntegerLiteral weeks) { return date.plusWeeks(-weeks.getValue()); } @@ -314,22 +344,22 @@ public static Expression weeksSub(DateTimeV2Literal date, IntegerLiteral weeks) /** * datetime arithmetic function days-sub */ - @ExecFunction(name = "days_sub", argTypes = {"DATE", "INT"}, returnType = "DATE") + @ExecFunction(name = "days_sub") public static Expression daysSub(DateLiteral date, IntegerLiteral day) { return daysAdd(date, new IntegerLiteral(-day.getValue())); } - @ExecFunction(name = "days_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "days_sub") public static Expression daysSub(DateTimeLiteral date, IntegerLiteral day) { return daysAdd(date, new IntegerLiteral(-day.getValue())); } - @ExecFunction(name = "days_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "days_sub") public static Expression daysSub(DateV2Literal date, IntegerLiteral day) { return daysAdd(date, new IntegerLiteral(-day.getValue())); } - @ExecFunction(name = "days_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "days_sub") public static Expression daysSub(DateTimeV2Literal date, IntegerLiteral day) { return daysAdd(date, new IntegerLiteral(-day.getValue())); } @@ -337,12 +367,12 @@ public static Expression daysSub(DateTimeV2Literal date, IntegerLiteral day) { /** * datetime arithmetic function hours-sub */ - @ExecFunction(name = "hours_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "hours_sub") public static Expression hoursSub(DateTimeLiteral date, IntegerLiteral hour) { return hoursAdd(date, new IntegerLiteral(-hour.getValue())); } - @ExecFunction(name = "hours_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hours_sub") public static Expression hoursSub(DateTimeV2Literal date, IntegerLiteral hour) { return hoursAdd(date, new IntegerLiteral(-hour.getValue())); } @@ -350,12 +380,12 @@ public static Expression hoursSub(DateTimeV2Literal date, IntegerLiteral hour) { /** * datetime arithmetic function minutes-sub */ - @ExecFunction(name = "minutes_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "minutes_sub") public static Expression minutesSub(DateTimeLiteral date, IntegerLiteral minute) { return minutesAdd(date, new IntegerLiteral(-minute.getValue())); } - @ExecFunction(name = "minutes_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minutes_sub") public static Expression minutesSub(DateTimeV2Literal date, IntegerLiteral minute) { return minutesAdd(date, new IntegerLiteral(-minute.getValue())); } @@ -363,12 +393,12 @@ public static Expression minutesSub(DateTimeV2Literal date, IntegerLiteral minut /** * datetime arithmetic function seconds-sub */ - @ExecFunction(name = "seconds_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "seconds_sub") public static Expression secondsSub(DateTimeLiteral date, IntegerLiteral second) { return secondsAdd(date, new IntegerLiteral(-second.getValue())); } - @ExecFunction(name = "seconds_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "seconds_sub") public static Expression secondsSub(DateTimeV2Literal date, IntegerLiteral second) { return secondsAdd(date, new IntegerLiteral(-second.getValue())); } @@ -376,27 +406,27 @@ public static Expression secondsSub(DateTimeV2Literal date, IntegerLiteral secon /** * datetime arithmetic function datediff */ - @ExecFunction(name = "datediff", argTypes = {"DATETIME", "DATETIME"}, returnType = "INT") + @ExecFunction(name = "datediff") public static Expression dateDiff(DateTimeLiteral date1, DateTimeLiteral date2) { return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType())); } - @ExecFunction(name = "datediff", argTypes = {"DATEV2", "DATEV2"}, returnType = "INT") + @ExecFunction(name = "datediff") public static Expression dateDiff(DateV2Literal date1, DateV2Literal date2) { return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType())); } - @ExecFunction(name = "datediff", argTypes = {"DATEV2", "DATETIMEV2"}, returnType = "INT") + @ExecFunction(name = "datediff") public static Expression dateDiff(DateV2Literal date1, DateTimeV2Literal date2) { return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType())); } - @ExecFunction(name = "datediff", argTypes = {"DATETIMEV2", "DATEV2"}, returnType = "INT") + @ExecFunction(name = "datediff") public static Expression dateDiff(DateTimeV2Literal date1, DateV2Literal date2) { return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType())); } - @ExecFunction(name = "datediff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "INT") + @ExecFunction(name = "datediff") public static Expression dateDiff(DateTimeV2Literal date1, DateTimeV2Literal date2) { return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType())); } @@ -404,4 +434,14 @@ public static Expression dateDiff(DateTimeV2Literal date1, DateTimeV2Literal dat private static int dateDiff(LocalDateTime date1, LocalDateTime date2) { return ((int) ChronoUnit.DAYS.between(date2.toLocalDate(), date1.toLocalDate())); } + + @ExecFunction(name = "to_days") + public static Expression toDays(DateLiteral date) { + return new IntegerLiteral((int) date.getDay()); + } + + @ExecFunction(name = "to_days") + public static Expression toDays(DateV2Literal date) { + return new IntegerLiteral((int) date.getDay()); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java index 9742602a07a249..2390acd2ded95d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java @@ -67,7 +67,7 @@ public class DateTimeExtractAndTransform { /** * datetime arithmetic function date-v2 */ - @ExecFunction(name = "datev2", argTypes = {"DATETIMEV2"}, returnType = "DATEV2") + @ExecFunction(name = "datev2") public static Expression dateV2(DateTimeV2Literal dateTime) { return new DateV2Literal(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay()); } @@ -75,22 +75,22 @@ public static Expression dateV2(DateTimeV2Literal dateTime) { /** * Executable datetime extract year */ - @ExecFunction(name = "year", argTypes = {"DATE"}, returnType = "SMALLINT") + @ExecFunction(name = "year") public static Expression year(DateLiteral date) { return new SmallIntLiteral(((short) date.getYear())); } - @ExecFunction(name = "year", argTypes = {"DATETIME"}, returnType = "SMALLINT") + @ExecFunction(name = "year") public static Expression year(DateTimeLiteral date) { return new SmallIntLiteral(((short) date.getYear())); } - @ExecFunction(name = "year", argTypes = {"DATEV2"}, returnType = "SMALLINT") + @ExecFunction(name = "year") public static Expression year(DateV2Literal date) { return new SmallIntLiteral(((short) date.getYear())); } - @ExecFunction(name = "year", argTypes = {"DATETIMEV2"}, returnType = "SMALLINT") + @ExecFunction(name = "year") public static Expression year(DateTimeV2Literal date) { return new SmallIntLiteral(((short) date.getYear())); } @@ -98,22 +98,22 @@ public static Expression year(DateTimeV2Literal date) { /** * Executable datetime extract quarter */ - @ExecFunction(name = "quarter", argTypes = {"DATE"}, returnType = "TINYINT") + @ExecFunction(name = "quarter") public static Expression quarter(DateLiteral date) { return new TinyIntLiteral((byte) (((byte) date.getMonth() - 1) / 3 + 1)); } - @ExecFunction(name = "quarter", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "quarter") public static Expression quarter(DateTimeLiteral date) { return new TinyIntLiteral((byte) ((date.getMonth() - 1) / 3 + 1)); } - @ExecFunction(name = "quarter", argTypes = {"DATEV2"}, returnType = "TINYINT") + @ExecFunction(name = "quarter") public static Expression quarter(DateV2Literal date) { return new TinyIntLiteral((byte) ((date.getMonth() - 1) / 3 + 1)); } - @ExecFunction(name = "quarter", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "quarter") public static Expression quarter(DateTimeV2Literal date) { return new TinyIntLiteral((byte) ((date.getMonth() - 1) / 3 + 1)); } @@ -121,22 +121,22 @@ public static Expression quarter(DateTimeV2Literal date) { /** * Executable datetime extract month */ - @ExecFunction(name = "month", argTypes = {"DATE"}, returnType = "TINYINT") + @ExecFunction(name = "month") public static Expression month(DateLiteral date) { return new TinyIntLiteral((byte) date.getMonth()); } - @ExecFunction(name = "month", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "month") public static Expression month(DateTimeLiteral date) { return new TinyIntLiteral((byte) date.getMonth()); } - @ExecFunction(name = "month", argTypes = {"DATEV2"}, returnType = "TINYINT") + @ExecFunction(name = "month") public static Expression month(DateV2Literal date) { return new TinyIntLiteral((byte) date.getMonth()); } - @ExecFunction(name = "month", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "month") public static Expression month(DateTimeV2Literal date) { return new TinyIntLiteral((byte) date.getMonth()); } @@ -144,22 +144,22 @@ public static Expression month(DateTimeV2Literal date) { /** * Executable datetime extract day */ - @ExecFunction(name = "day", argTypes = {"DATE"}, returnType = "TINYINT") + @ExecFunction(name = "day") public static Expression day(DateLiteral date) { return new TinyIntLiteral((byte) date.getDay()); } - @ExecFunction(name = "day", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "day") public static Expression day(DateTimeLiteral date) { return new TinyIntLiteral((byte) date.getDay()); } - @ExecFunction(name = "day", argTypes = {"DATEV2"}, returnType = "TINYINT") + @ExecFunction(name = "day") public static Expression day(DateV2Literal date) { return new TinyIntLiteral((byte) date.getDay()); } - @ExecFunction(name = "day", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "day") public static Expression day(DateTimeV2Literal date) { return new TinyIntLiteral((byte) date.getDay()); } @@ -167,12 +167,12 @@ public static Expression day(DateTimeV2Literal date) { /** * Executable datetime extract hour */ - @ExecFunction(name = "hour", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "hour") public static Expression hour(DateTimeLiteral date) { return new TinyIntLiteral(((byte) date.getHour())); } - @ExecFunction(name = "hour", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "hour") public static Expression hour(DateTimeV2Literal date) { return new TinyIntLiteral(((byte) date.getHour())); } @@ -180,12 +180,12 @@ public static Expression hour(DateTimeV2Literal date) { /** * Executable datetime extract hour */ - @ExecFunction(name = "minute", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "minute") public static Expression minute(DateTimeLiteral date) { return new TinyIntLiteral(((byte) date.getMinute())); } - @ExecFunction(name = "minute", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "minute") public static Expression minute(DateTimeV2Literal date) { return new TinyIntLiteral(((byte) date.getMinute())); } @@ -193,12 +193,12 @@ public static Expression minute(DateTimeV2Literal date) { /** * Executable datetime extract second */ - @ExecFunction(name = "second", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "second") public static Expression second(DateTimeLiteral date) { return new TinyIntLiteral(((byte) date.getSecond())); } - @ExecFunction(name = "second", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "second") public static Expression second(DateTimeV2Literal date) { return new TinyIntLiteral(((byte) date.getSecond())); } @@ -206,7 +206,7 @@ public static Expression second(DateTimeV2Literal date) { /** * Executable datetime extract microsecond */ - @ExecFunction(name = "microsecond", argTypes = {"DATETIMEV2"}, returnType = "INT") + @ExecFunction(name = "microsecond") public static Expression microsecond(DateTimeV2Literal date) { return new IntegerLiteral(((int) date.getMicroSecond())); } @@ -214,45 +214,45 @@ public static Expression microsecond(DateTimeV2Literal date) { /** * Executable datetime extract dayofyear */ - @ExecFunction(name = "dayofyear", argTypes = {"DATE"}, returnType = "SMALLINT") + @ExecFunction(name = "dayofyear") public static Expression dayOfYear(DateLiteral date) { - return new SmallIntLiteral((short) date.getDayOfYear()); + return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear()); } - @ExecFunction(name = "dayofyear", argTypes = {"DATETIME"}, returnType = "SMALLINT") + @ExecFunction(name = "dayofyear") public static Expression dayOfYear(DateTimeLiteral date) { - return new SmallIntLiteral((short) date.getDayOfYear()); + return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear()); } - @ExecFunction(name = "dayofyear", argTypes = {"DATEV2"}, returnType = "SMALLINT") + @ExecFunction(name = "dayofyear") public static Expression dayOfYear(DateV2Literal date) { - return new SmallIntLiteral((short) date.getDayOfYear()); + return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear()); } - @ExecFunction(name = "dayofyear", argTypes = {"DATETIMEV2"}, returnType = "SMALLINT") + @ExecFunction(name = "dayofyear") public static Expression dayOfYear(DateTimeV2Literal date) { - return new SmallIntLiteral((short) date.getDayOfYear()); + return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear()); } /** * Executable datetime extract dayofmonth */ - @ExecFunction(name = "dayofmonth", argTypes = {"DATE"}, returnType = "TINYINT") + @ExecFunction(name = "dayofmonth") public static Expression dayOfMonth(DateLiteral date) { return new TinyIntLiteral((byte) date.toJavaDateType().getDayOfMonth()); } - @ExecFunction(name = "dayofmonth", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "dayofmonth") public static Expression dayOfMonth(DateTimeLiteral date) { return new TinyIntLiteral((byte) date.toJavaDateType().getDayOfMonth()); } - @ExecFunction(name = "dayofmonth", argTypes = {"DATEV2"}, returnType = "TINYINT") + @ExecFunction(name = "dayofmonth") public static Expression dayOfMonth(DateV2Literal date) { return new TinyIntLiteral((byte) date.toJavaDateType().getDayOfMonth()); } - @ExecFunction(name = "dayofmonth", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "dayofmonth") public static Expression dayOfMonth(DateTimeV2Literal date) { return new TinyIntLiteral((byte) date.toJavaDateType().getDayOfMonth()); } @@ -260,24 +260,24 @@ public static Expression dayOfMonth(DateTimeV2Literal date) { /** * Executable datetime extract dayofweek */ - @ExecFunction(name = "dayofweek", argTypes = {"DATE"}, returnType = "TINYINT") + @ExecFunction(name = "dayofweek") public static Expression dayOfWeek(DateLiteral date) { - return new TinyIntLiteral((byte) (date.getDayOfWeek() % 7 + 1)); + return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1)); } - @ExecFunction(name = "dayofweek", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "dayofweek") public static Expression dayOfWeek(DateTimeLiteral date) { - return new TinyIntLiteral((byte) (date.getDayOfWeek() % 7 + 1)); + return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1)); } - @ExecFunction(name = "dayofweek", argTypes = {"DATEV2"}, returnType = "TINYINT") + @ExecFunction(name = "dayofweek") public static Expression dayOfWeek(DateV2Literal date) { - return new TinyIntLiteral((byte) (date.getDayOfWeek() % 7 + 1)); + return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1)); } - @ExecFunction(name = "dayofweek", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "dayofweek") public static Expression dayOfWeek(DateTimeV2Literal date) { - return new TinyIntLiteral((byte) (date.getDayOfWeek() % 7 + 1)); + return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1)); } private static int distanceToFirstDayOfWeek(LocalDateTime dateTime) { @@ -291,26 +291,26 @@ private static LocalDateTime firstDayOfWeek(LocalDateTime dateTime) { /** * datetime arithmetic function date-format */ - @ExecFunction(name = "date_format", argTypes = {"DATE", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "date_format") public static Expression dateFormat(DateLiteral date, StringLikeLiteral format) { return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format( java.time.LocalDate.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay())))); } - @ExecFunction(name = "date_format", argTypes = {"DATETIME", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "date_format") public static Expression dateFormat(DateTimeLiteral date, StringLikeLiteral format) { return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format( java.time.LocalDateTime.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay()), ((int) date.getHour()), ((int) date.getMinute()), ((int) date.getSecond())))); } - @ExecFunction(name = "date_format", argTypes = {"DATEV2", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "date_format") public static Expression dateFormat(DateV2Literal date, StringLikeLiteral format) { return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format( java.time.LocalDate.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay())))); } - @ExecFunction(name = "date_format", argTypes = {"DATETIMEV2", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "date_format") public static Expression dateFormat(DateTimeV2Literal date, StringLikeLiteral format) { return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format( java.time.LocalDateTime.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay()), @@ -320,12 +320,12 @@ public static Expression dateFormat(DateTimeV2Literal date, StringLikeLiteral fo /** * datetime arithmetic function date */ - @ExecFunction(name = "date", argTypes = {"DATETIME"}, returnType = "DATE") + @ExecFunction(name = "date") public static Expression date(DateTimeLiteral dateTime) throws AnalysisException { return new DateLiteral(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay()); } - @ExecFunction(name = "date", argTypes = {"DATETIMEV2"}, returnType = "DATEV2") + @ExecFunction(name = "date") public static Expression date(DateTimeV2Literal dateTime) throws AnalysisException { return new DateV2Literal(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay()); } @@ -333,22 +333,22 @@ public static Expression date(DateTimeV2Literal dateTime) throws AnalysisExcepti /** * datetime arithmetic function date-trunc */ - @ExecFunction(name = "date_trunc", argTypes = {"DATETIME", "VARCHAR"}, returnType = "DATETIME") + @ExecFunction(name = "date_trunc") public static Expression dateTrunc(DateTimeLiteral date, StringLikeLiteral trunc) { return DateTimeLiteral.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), trunc.getValue())); } - @ExecFunction(name = "date_trunc", argTypes = {"DATETIMEV2", "VARCHAR"}, returnType = "DATETIMEV2") + @ExecFunction(name = "date_trunc") public static Expression dateTrunc(DateTimeV2Literal date, StringLikeLiteral trunc) { return DateTimeV2Literal.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), trunc.getValue())); } - @ExecFunction(name = "date_trunc", argTypes = {"DATE", "VARCHAR"}, returnType = "DATE") + @ExecFunction(name = "date_trunc") public static Expression dateTrunc(DateLiteral date, StringLikeLiteral trunc) { return DateLiteral.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), trunc.getValue())); } - @ExecFunction(name = "date_trunc", argTypes = {"DATEV2", "VARCHAR"}, returnType = "DATEV2") + @ExecFunction(name = "date_trunc") public static Expression dateTrunc(DateV2Literal date, StringLikeLiteral trunc) { return DateV2Literal.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), trunc.getValue())); } @@ -395,7 +395,7 @@ private static LocalDateTime dateTruncHelper(LocalDateTime dateTime, String trun /** * from_days. */ - @ExecFunction(name = "from_days", argTypes = {"INT"}, returnType = "DATEV2") + @ExecFunction(name = "from_days") public static Expression fromDays(IntegerLiteral n) { // doris treat 0000AD as ordinary year but java LocalDateTime treat it as lunar year. LocalDateTime res = LocalDateTime.of(0, 1, 1, 0, 0, 0) @@ -406,28 +406,28 @@ public static Expression fromDays(IntegerLiteral n) { return DateV2Literal.fromJavaDateType(res); } - @ExecFunction(name = "last_day", argTypes = {"DATE"}, returnType = "DATE") + @ExecFunction(name = "last_day") public static Expression lastDay(DateLiteral date) { LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) date.getYear(), (int) date.getMonth(), 1, 0, 0, 0).plusMonths(1); return DateLiteral.fromJavaDateType(nextMonthFirstDay.minusDays(1)); } - @ExecFunction(name = "last_day", argTypes = {"DATETIME"}, returnType = "DATE") + @ExecFunction(name = "last_day") public static Expression lastDay(DateTimeLiteral date) { LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) date.getYear(), (int) date.getMonth(), 1, 0, 0, 0).plusMonths(1); return DateLiteral.fromJavaDateType(nextMonthFirstDay.minusDays(1)); } - @ExecFunction(name = "last_day", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "last_day") public static Expression lastDay(DateV2Literal date) { LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) date.getYear(), (int) date.getMonth(), 1, 0, 0, 0).plusMonths(1); return DateV2Literal.fromJavaDateType(nextMonthFirstDay.minusDays(1)); } - @ExecFunction(name = "last_day", argTypes = {"DATETIMEV2"}, returnType = "DATEV2") + @ExecFunction(name = "last_day") public static Expression lastDay(DateTimeV2Literal date) { LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) date.getYear(), (int) date.getMonth(), 1, 0, 0, 0).plusMonths(1); @@ -437,22 +437,22 @@ public static Expression lastDay(DateTimeV2Literal date) { /** * datetime transformation function: to_monday */ - @ExecFunction(name = "to_monday", argTypes = {"DATE"}, returnType = "DATE") + @ExecFunction(name = "to_monday") public static Expression toMonday(DateLiteral date) { return DateLiteral.fromJavaDateType(toMonday(date.toJavaDateType())); } - @ExecFunction(name = "to_monday", argTypes = {"DATETIME"}, returnType = "DATE") + @ExecFunction(name = "to_monday") public static Expression toMonday(DateTimeLiteral date) { return DateLiteral.fromJavaDateType(toMonday(date.toJavaDateType())); } - @ExecFunction(name = "to_monday", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "to_monday") public static Expression toMonday(DateV2Literal date) { return DateV2Literal.fromJavaDateType(toMonday(date.toJavaDateType())); } - @ExecFunction(name = "to_monday", argTypes = {"DATETIMEV2"}, returnType = "DATEV2") + @ExecFunction(name = "to_monday") public static Expression toMonday(DateTimeV2Literal date) { return DateV2Literal.fromJavaDateType(toMonday(date.toJavaDateType())); } @@ -469,7 +469,7 @@ private static LocalDateTime toMonday(LocalDateTime dateTime) { /** * date transformation function: from_unixtime */ - @ExecFunction(name = "from_unixtime", argTypes = {"BIGINT"}, returnType = "VARCHAR") + @ExecFunction(name = "from_unixtime") public static Expression fromUnixTime(BigIntLiteral second) { return fromUnixTime(second, new VarcharLiteral("%Y-%m-%d %H:%i:%s")); } @@ -477,7 +477,7 @@ public static Expression fromUnixTime(BigIntLiteral second) { /** * date transformation function: from_unixtime */ - @ExecFunction(name = "from_unixtime", argTypes = {"BIGINT", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "from_unixtime") public static Expression fromUnixTime(BigIntLiteral second, StringLikeLiteral format) { // 32536771199L is max valid timestamp of mysql from_unix_time if (second.getValue() < 0 || second.getValue() > 32536771199L) { @@ -497,17 +497,17 @@ public static Expression fromUnixTime(BigIntLiteral second, StringLikeLiteral fo /** * date transformation function: unix_timestamp */ - @ExecFunction(name = "unix_timestamp", argTypes = {"DATE"}, returnType = "INT") + @ExecFunction(name = "unix_timestamp") public static Expression unixTimestamp(DateLiteral date) { return new IntegerLiteral(Integer.parseInt(getTimestamp(date.toJavaDateType()))); } - @ExecFunction(name = "unix_timestamp", argTypes = {"DATETIME"}, returnType = "INT") + @ExecFunction(name = "unix_timestamp") public static Expression unixTimestamp(DateTimeLiteral date) { return new IntegerLiteral(Integer.parseInt(getTimestamp(date.toJavaDateType()))); } - @ExecFunction(name = "unix_timestamp", argTypes = {"DATEV2"}, returnType = "INT") + @ExecFunction(name = "unix_timestamp") public static Expression unixTimestamp(DateV2Literal date) { return new IntegerLiteral(Integer.parseInt(getTimestamp(date.toJavaDateType()))); } @@ -515,7 +515,7 @@ public static Expression unixTimestamp(DateV2Literal date) { /** * date transformation function: unix_timestamp */ - @ExecFunction(name = "unix_timestamp", argTypes = {"DATETIMEV2"}, returnType = "DECIMALV3") + @ExecFunction(name = "unix_timestamp") public static Expression unixTimestamp(DateTimeV2Literal date) { if (date.getMicroSecond() == 0) { return new DecimalV3Literal(DecimalV3Type.createDecimalV3TypeLooseCheck(10, 0), @@ -529,7 +529,7 @@ public static Expression unixTimestamp(DateTimeV2Literal date) { /** * date transformation function: unix_timestamp */ - @ExecFunction(name = "unix_timestamp", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "DECIMALV3") + @ExecFunction(name = "unix_timestamp") public static Expression unixTimestamp(StringLikeLiteral date, StringLikeLiteral format) { DateTimeFormatter formatter = DateUtils.formatBuilder(format.getValue()).toFormatter(); LocalDateTime dateObj; @@ -564,12 +564,12 @@ private static String getTimestamp(LocalDateTime dateTime) { /** * date transformation function: to_date */ - @ExecFunction(name = "to_date", argTypes = {"DATETIME"}, returnType = "DATE") + @ExecFunction(name = "to_date") public static Expression toDate(DateTimeLiteral date) { return new DateLiteral(date.getYear(), date.getMonth(), date.getDay()); } - @ExecFunction(name = "to_date", argTypes = {"DATETIMEV2"}, returnType = "DATEV2") + @ExecFunction(name = "to_date") public static Expression toDate(DateTimeV2Literal date) { return new DateV2Literal(date.getYear(), date.getMonth(), date.getDay()); } @@ -577,25 +577,25 @@ public static Expression toDate(DateTimeV2Literal date) { /** * date transformation function: to_days */ - @ExecFunction(name = "to_days", argTypes = {"DATE"}, returnType = "INT") + @ExecFunction(name = "to_days") public static Expression toDays(DateLiteral date) { return new IntegerLiteral(((int) Duration.between( LocalDateTime.of(0, 1, 1, 0, 0, 0), date.toJavaDateType()).toDays())); } - @ExecFunction(name = "to_days", argTypes = {"DATETIME"}, returnType = "INT") + @ExecFunction(name = "to_days") public static Expression toDays(DateTimeLiteral date) { return new IntegerLiteral(((int) Duration.between( LocalDateTime.of(0, 1, 1, 0, 0, 0), date.toJavaDateType()).toDays())); } - @ExecFunction(name = "to_days", argTypes = {"DATEV2"}, returnType = "INT") + @ExecFunction(name = "to_days") public static Expression toDays(DateV2Literal date) { return new IntegerLiteral(((int) Duration.between( LocalDateTime.of(0, 1, 1, 0, 0, 0), date.toJavaDateType()).toDays())); } - @ExecFunction(name = "to_days", argTypes = {"DATETIMEV2"}, returnType = "INT") + @ExecFunction(name = "to_days") public static Expression toDays(DateTimeV2Literal date) { return new IntegerLiteral(((int) Duration.between( LocalDateTime.of(0, 1, 1, 0, 0, 0), date.toJavaDateType()).toDays())); @@ -604,7 +604,7 @@ public static Expression toDays(DateTimeV2Literal date) { /** * date transformation function: makedate */ - @ExecFunction(name = "makedate", argTypes = {"INT", "INT"}, returnType = "DATE") + @ExecFunction(name = "makedate") public static Expression makeDate(IntegerLiteral year, IntegerLiteral dayOfYear) { int day = dayOfYear.getValue(); return day > 0 ? DateLiteral.fromJavaDateType(LocalDateTime.of(year.getValue(), 1, 1, 0, 0, 0) @@ -614,7 +614,7 @@ public static Expression makeDate(IntegerLiteral year, IntegerLiteral dayOfYear) /** * date transformation function: str_to_date */ - @ExecFunction(name = "str_to_date", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "DATETIMEV2") + @ExecFunction(name = "str_to_date") public static Expression strToDate(StringLikeLiteral str, StringLikeLiteral format) { if (org.apache.doris.analysis.DateLiteral.hasTimePart(format.getStringValue())) { DataType returnType = DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME)); @@ -637,12 +637,12 @@ public static Expression strToDate(StringLikeLiteral str, StringLikeLiteral form } } - @ExecFunction(name = "timestamp", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "timestamp") public static Expression timestamp(DateTimeLiteral datetime) { return datetime; } - @ExecFunction(name = "timestamp", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "timestamp") public static Expression timestamp(DateTimeV2Literal datetime) { return datetime; } @@ -650,7 +650,7 @@ public static Expression timestamp(DateTimeV2Literal datetime) { /** * convert_tz */ - @ExecFunction(name = "convert_tz", argTypes = {"DATETIMEV2", "VARCHAR", "VARCHAR"}, returnType = "DATETIMEV2") + @ExecFunction(name = "convert_tz") public static Expression convertTz(DateTimeV2Literal datetime, StringLikeLiteral fromTz, StringLikeLiteral toTz) { DateTimeFormatter zoneFormatter = new DateTimeFormatterBuilder() .parseCaseInsensitive() @@ -665,52 +665,52 @@ public static Expression convertTz(DateTimeV2Literal datetime, StringLikeLiteral return DateTimeV2Literal.fromJavaDateType(resultDateTime.toLocalDateTime(), datetime.getDataType().getScale()); } - @ExecFunction(name = "weekday", argTypes = {"DATE"}, returnType = "TINYINT") + @ExecFunction(name = "weekday") public static Expression weekDay(DateLiteral date) { return new TinyIntLiteral((byte) ((date.toJavaDateType().getDayOfWeek().getValue() + 6) % 7)); } - @ExecFunction(name = "weekday", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "weekday") public static Expression weekDay(DateTimeLiteral date) { return new TinyIntLiteral((byte) ((date.toJavaDateType().getDayOfWeek().getValue() + 6) % 7)); } - @ExecFunction(name = "weekday", argTypes = {"DATEV2"}, returnType = "TINYINT") + @ExecFunction(name = "weekday") public static Expression weekDay(DateV2Literal date) { return new TinyIntLiteral((byte) ((date.toJavaDateType().getDayOfWeek().getValue() + 6) % 7)); } - @ExecFunction(name = "weekday", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "weekday") public static Expression weekDay(DateTimeV2Literal date) { return new TinyIntLiteral((byte) ((date.toJavaDateType().getDayOfWeek().getValue() + 6) % 7)); } - @ExecFunction(name = "week", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "week") public static Expression week(DateTimeV2Literal dateTime) { return week(dateTime.toJavaDateType(), 0); } - @ExecFunction(name = "week", argTypes = {"DATETIMEV2", "INT"}, returnType = "TINYINT") + @ExecFunction(name = "week") public static Expression week(DateTimeV2Literal dateTime, IntegerLiteral mode) { return week(dateTime.toJavaDateType(), mode.getIntValue()); } - @ExecFunction(name = "week", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "week") public static Expression week(DateTimeLiteral dateTime) { return week(dateTime.toJavaDateType(), 0); } - @ExecFunction(name = "week", argTypes = {"DATETIME", "INT"}, returnType = "TINYINT") + @ExecFunction(name = "week") public static Expression week(DateTimeLiteral dateTime, IntegerLiteral mode) { return week(dateTime.toJavaDateType(), mode.getIntValue()); } - @ExecFunction(name = "week", argTypes = {"DATEV2"}, returnType = "TINYINT") + @ExecFunction(name = "week") public static Expression week(DateV2Literal date) { return week(date.toJavaDateType(), 0); } - @ExecFunction(name = "week", argTypes = {"DATEV2", "INT"}, returnType = "TINYINT") + @ExecFunction(name = "week") public static Expression week(DateV2Literal date, IntegerLiteral mode) { return week(date.toJavaDateType(), mode.getIntValue()); } @@ -775,32 +775,32 @@ private static boolean isSpecificDate(LocalDateTime localDateTime) { && (localDateTime.getDayOfMonth() == 1 || localDateTime.getDayOfMonth() == 2); } - @ExecFunction(name = "yearweek", argTypes = {"DATEV2", "INT"}, returnType = "INT") + @ExecFunction(name = "yearweek") public static Expression yearWeek(DateV2Literal date, IntegerLiteral mode) { return yearWeek(date.toJavaDateType(), mode.getIntValue()); } - @ExecFunction(name = "yearweek", argTypes = {"DATETIMEV2", "INT"}, returnType = "INT") + @ExecFunction(name = "yearweek") public static Expression yearWeek(DateTimeV2Literal dateTime, IntegerLiteral mode) { return yearWeek(dateTime.toJavaDateType(), mode.getIntValue()); } - @ExecFunction(name = "yearweek", argTypes = {"DATETIME", "INT"}, returnType = "INT") + @ExecFunction(name = "yearweek") public static Expression yearWeek(DateTimeLiteral dateTime, IntegerLiteral mode) { return yearWeek(dateTime.toJavaDateType(), mode.getIntValue()); } - @ExecFunction(name = "yearweek", argTypes = {"DATEV2"}, returnType = "INT") + @ExecFunction(name = "yearweek") public static Expression yearWeek(DateV2Literal date) { return yearWeek(date.toJavaDateType(), 0); } - @ExecFunction(name = "yearweek", argTypes = {"DATETIMEV2"}, returnType = "INT") + @ExecFunction(name = "yearweek") public static Expression yearWeek(DateTimeV2Literal dateTime) { return yearWeek(dateTime.toJavaDateType(), 0); } - @ExecFunction(name = "yearweek", argTypes = {"DATETIME"}, returnType = "INT") + @ExecFunction(name = "yearweek") public static Expression yearWeek(DateTimeLiteral dateTime) { return yearWeek(dateTime.toJavaDateType(), 0); } @@ -868,7 +868,7 @@ public static Expression yearWeek(LocalDateTime localDateTime, int mode) { /** * weekofyear */ - @ExecFunction(name = "weekofyear", argTypes = {"DATETIMEV2"}, returnType = "TINYINT") + @ExecFunction(name = "weekofyear") public static Expression weekOfYear(DateTimeV2Literal dateTime) { if (dateTime.getYear() == 0 && dateTime.getDayOfWeek() == 1) { if (dateTime.getMonth() == 1 && dateTime.getDay() == 2) { @@ -883,7 +883,7 @@ public static Expression weekOfYear(DateTimeV2Literal dateTime) { /** * weekofyear */ - @ExecFunction(name = "weekofyear", argTypes = {"DATETIME"}, returnType = "TINYINT") + @ExecFunction(name = "weekofyear") public static Expression weekOfYear(DateTimeLiteral dateTime) { if (dateTime.getYear() == 0 && dateTime.getDayOfWeek() == 1) { if (dateTime.getMonth() == 1 && dateTime.getDay() == 2) { @@ -898,7 +898,7 @@ public static Expression weekOfYear(DateTimeLiteral dateTime) { /** * weekofyear */ - @ExecFunction(name = "weekofyear", argTypes = {"DATEV2"}, returnType = "TINYINT") + @ExecFunction(name = "weekofyear") public static Expression weekOfYear(DateV2Literal date) { if (date.getYear() == 0 && date.getDayOfWeek() == 1) { if (date.getMonth() == 1 && date.getDay() == 2) { @@ -909,53 +909,53 @@ public static Expression weekOfYear(DateV2Literal date) { return new TinyIntLiteral((byte) date.toJavaDateType().get(WeekFields.ISO.weekOfWeekBasedYear())); } - @ExecFunction(name = "dayname", argTypes = {"DATETIMEV2"}, returnType = "VARCHAR") + @ExecFunction(name = "dayname") public static Expression dayName(DateTimeV2Literal dateTime) { return new VarcharLiteral(dateTime.toJavaDateType().getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault())); } - @ExecFunction(name = "dayname", argTypes = {"DATETIME"}, returnType = "VARCHAR") + @ExecFunction(name = "dayname") public static Expression dayName(DateTimeLiteral dateTime) { return new VarcharLiteral(dateTime.toJavaDateType().getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault())); } - @ExecFunction(name = "dayname", argTypes = {"DATEV2"}, returnType = "VARCHAR") + @ExecFunction(name = "dayname") public static Expression dayName(DateV2Literal date) { return new VarcharLiteral(date.toJavaDateType().getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault())); } - @ExecFunction(name = "monthname", argTypes = {"DATETIMEV2"}, returnType = "VARCHAR") + @ExecFunction(name = "monthname") public static Expression monthName(DateTimeV2Literal dateTime) { return new VarcharLiteral(dateTime.toJavaDateType().getMonth().getDisplayName(TextStyle.FULL, Locale.getDefault())); } - @ExecFunction(name = "monthname", argTypes = {"DATETIME"}, returnType = "VARCHAR") + @ExecFunction(name = "monthname") public static Expression monthName(DateTimeLiteral dateTime) { return new VarcharLiteral(dateTime.toJavaDateType().getMonth().getDisplayName(TextStyle.FULL, Locale.getDefault())); } - @ExecFunction(name = "monthname", argTypes = {"DATEV2"}, returnType = "VARCHAR") + @ExecFunction(name = "monthname") public static Expression monthName(DateV2Literal date) { return new VarcharLiteral(date.toJavaDateType().getMonth().getDisplayName(TextStyle.FULL, Locale.getDefault())); } - @ExecFunction(name = "from_second", argTypes = {"BIGINT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "from_second") public static Expression fromSecond(BigIntLiteral second) { return fromMicroSecond(second.getValue() * 1000 * 1000); } - @ExecFunction(name = "from_millisecond", argTypes = {"BIGINT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "from_millisecond") public static Expression fromMilliSecond(BigIntLiteral milliSecond) { return fromMicroSecond(milliSecond.getValue() * 1000); } - @ExecFunction(name = "from_microsecond", argTypes = {"BIGINT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "from_microsecond") public static Expression fromMicroSecond(BigIntLiteral microSecond) { return fromMicroSecond(microSecond.getValue()); } @@ -972,187 +972,187 @@ private static Expression fromMicroSecond(long microSecond) { dateTime.getMinute(), dateTime.getSecond(), dateTime.getNano() / 1000); } - @ExecFunction(name = "microseconds_diff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "microseconds_diff") public static Expression microsecondsDiff(DateTimeV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.MICROS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "milliseconds_diff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "milliseconds_diff") public static Expression millisecondsDiff(DateTimeV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.MILLIS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "seconds_diff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "seconds_diff") public static Expression secondsDiff(DateTimeV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.SECONDS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "seconds_diff", argTypes = {"DATETIMEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "seconds_diff") public static Expression secondsDiff(DateTimeV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.SECONDS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "seconds_diff", argTypes = {"DATEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "seconds_diff") public static Expression secondsDiff(DateV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.SECONDS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "seconds_diff", argTypes = {"DATEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "seconds_diff") public static Expression secondsDiff(DateV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.SECONDS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "seconds_diff", argTypes = {"DATETIME", "DATETIME"}, returnType = "BIGINT") + @ExecFunction(name = "seconds_diff") public static Expression secondsDiff(DateTimeLiteral t1, DateTimeLiteral t2) { return new BigIntLiteral(ChronoUnit.SECONDS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "minutes_diff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "minutes_diff") public static Expression minutesDiff(DateTimeV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.MINUTES.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "minutes_diff", argTypes = {"DATETIMEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "minutes_diff") public static Expression minutesDiff(DateTimeV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.MINUTES.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "minutes_diff", argTypes = {"DATEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "minutes_diff") public static Expression minutesDiff(DateV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.MINUTES.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "minutes_diff", argTypes = {"DATEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "minutes_diff") public static Expression minutesDiff(DateV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.MINUTES.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "minutes_diff", argTypes = {"DATETIME", "DATETIME"}, returnType = "BIGINT") + @ExecFunction(name = "minutes_diff") public static Expression minutesDiff(DateTimeLiteral t1, DateTimeLiteral t2) { return new BigIntLiteral(ChronoUnit.MINUTES.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "hours_diff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "hours_diff") public static Expression hoursDiff(DateTimeV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.HOURS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "hours_diff", argTypes = {"DATETIMEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "hours_diff") public static Expression hoursDiff(DateTimeV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.HOURS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "hours_diff", argTypes = {"DATEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "hours_diff") public static Expression hoursDiff(DateV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.HOURS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "hours_diff", argTypes = {"DATEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "hours_diff") public static Expression hoursDiff(DateV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.HOURS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "hours_diff", argTypes = {"DATETIME", "DATETIME"}, returnType = "BIGINT") + @ExecFunction(name = "hours_diff") public static Expression hoursDiff(DateTimeLiteral t1, DateTimeLiteral t2) { return new BigIntLiteral(ChronoUnit.HOURS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "days_diff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "days_diff") public static Expression daysDiff(DateTimeV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.DAYS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "days_diff", argTypes = {"DATETIMEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "days_diff") public static Expression daysDiff(DateTimeV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.DAYS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "days_diff", argTypes = {"DATEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "days_diff") public static Expression daysDiff(DateV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.DAYS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "days_diff", argTypes = {"DATEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "days_diff") public static Expression daysDiff(DateV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.DAYS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "days_diff", argTypes = {"DATETIME", "DATETIME"}, returnType = "BIGINT") + @ExecFunction(name = "days_diff") public static Expression daysDiff(DateTimeLiteral t1, DateTimeLiteral t2) { return new BigIntLiteral(ChronoUnit.DAYS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "weeks_diff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "weeks_diff") public static Expression weeksDiff(DateTimeV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.WEEKS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "weeks_diff", argTypes = {"DATETIMEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "weeks_diff") public static Expression weeksDiff(DateTimeV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.WEEKS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "weeks_diff", argTypes = {"DATEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "weeks_diff") public static Expression weeksDiff(DateV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.WEEKS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "weeks_diff", argTypes = {"DATEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "weeks_diff") public static Expression weeksDiff(DateV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.WEEKS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "weeks_diff", argTypes = {"DATETIME", "DATETIME"}, returnType = "BIGINT") + @ExecFunction(name = "weeks_diff") public static Expression weeksDiff(DateTimeLiteral t1, DateTimeLiteral t2) { return new BigIntLiteral(ChronoUnit.WEEKS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "months_diff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "months_diff") public static Expression monthsDiff(DateTimeV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.MONTHS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "months_diff", argTypes = {"DATETIMEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "months_diff") public static Expression monthsDiff(DateTimeV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.MONTHS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "months_diff", argTypes = {"DATEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "months_diff") public static Expression monthsDiff(DateV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.MONTHS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "months_diff", argTypes = {"DATEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "months_diff") public static Expression monthsDiff(DateV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.MONTHS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "months_diff", argTypes = {"DATETIME", "DATETIME"}, returnType = "BIGINT") + @ExecFunction(name = "months_diff") public static Expression monthsDiff(DateTimeLiteral t1, DateTimeLiteral t2) { return new BigIntLiteral(ChronoUnit.MONTHS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "years_diff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "years_diff") public static Expression yearsDiff(DateTimeV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.YEARS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "years_diff", argTypes = {"DATETIMEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "years_diff") public static Expression yearsDiff(DateTimeV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.YEARS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "years_diff", argTypes = {"DATEV2", "DATETIMEV2"}, returnType = "BIGINT") + @ExecFunction(name = "years_diff") public static Expression yearsDiff(DateV2Literal t1, DateTimeV2Literal t2) { return new BigIntLiteral(ChronoUnit.YEARS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "years_diff", argTypes = {"DATEV2", "DATEV2"}, returnType = "BIGINT") + @ExecFunction(name = "years_diff") public static Expression yearsDiff(DateV2Literal t1, DateV2Literal t2) { return new BigIntLiteral(ChronoUnit.YEARS.between(t2.toJavaDateType(), t1.toJavaDateType())); } - @ExecFunction(name = "years_diff", argTypes = {"DATETIME", "DATETIME"}, returnType = "BIGINT") + @ExecFunction(name = "years_diff") public static Expression yearsDiff(DateTimeLiteral t1, DateTimeLiteral t2) { return new BigIntLiteral(ChronoUnit.YEARS.between(t2.toJavaDateType(), t1.toJavaDateType())); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java deleted file mode 100644 index 42636cfa1b5ad9..00000000000000 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/ExecutableFunctions.java +++ /dev/null @@ -1,132 +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.nereids.trees.expressions.functions.executable; - -import org.apache.doris.nereids.trees.expressions.ExecFunction; -import org.apache.doris.nereids.trees.expressions.Expression; -import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral; -import org.apache.doris.nereids.trees.expressions.literal.DecimalLiteral; -import org.apache.doris.nereids.trees.expressions.literal.DecimalV3Literal; -import org.apache.doris.nereids.trees.expressions.literal.DoubleLiteral; -import org.apache.doris.nereids.trees.expressions.literal.FloatLiteral; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; -import org.apache.doris.nereids.trees.expressions.literal.LargeIntLiteral; -import org.apache.doris.nereids.trees.expressions.literal.NullLiteral; -import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral; -import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral; -import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral; -import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral; -import org.apache.doris.nereids.types.DoubleType; - -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.Random; - -/** - * functions that can be executed in FE. - */ -public class ExecutableFunctions { - public static final ExecutableFunctions INSTANCE = new ExecutableFunctions(); - private static final Random RANDOM = new SecureRandom(); - - /** - * other scalar function - */ - @ExecFunction(name = "abs", argTypes = {"TINYINT"}, returnType = "SMALLINT") - public static Expression abs(TinyIntLiteral literal) { - return new SmallIntLiteral((short) Math.abs(literal.getValue())); - } - - @ExecFunction(name = "abs", argTypes = {"SMALLINT"}, returnType = "INT") - public static Expression abs(SmallIntLiteral literal) { - return new IntegerLiteral(Math.abs(literal.getValue())); - } - - @ExecFunction(name = "abs", argTypes = {"INT"}, returnType = "BIGINT") - public static Expression abs(IntegerLiteral literal) { - return new BigIntLiteral(Math.abs((long) literal.getValue())); - } - - @ExecFunction(name = "abs", argTypes = {"BIGINT"}, returnType = "LARGEINT") - public static Expression abs(BigIntLiteral literal) { - return new LargeIntLiteral(BigInteger.valueOf(literal.getValue()).abs()); - } - - @ExecFunction(name = "abs", argTypes = {"LARGEINT"}, returnType = "LARGEINT") - public static Expression abs(LargeIntLiteral literal) { - return new LargeIntLiteral(literal.getValue().abs()); - } - - @ExecFunction(name = "abs", argTypes = {"FLOAT"}, returnType = "FLOAT") - public static Expression abs(FloatLiteral literal) { - return new FloatLiteral(Math.abs(literal.getValue())); - } - - @ExecFunction(name = "abs", argTypes = {"DOUBLE"}, returnType = "DOUBLE") - public static Expression abs(DoubleLiteral literal) { - return new DoubleLiteral(Math.abs(literal.getValue())); - } - - @ExecFunction(name = "abs", argTypes = {"DECIMALV2"}, returnType = "DECIMALV2") - public static Expression abs(DecimalLiteral literal) { - return new DecimalLiteral(literal.getValue().abs()); - } - - @ExecFunction(name = "abs", argTypes = {"DECIMALV3"}, returnType = "DECIMALV3") - public static Expression abs(DecimalV3Literal literal) { - return new DecimalV3Literal(literal.getValue().abs()); - } - - /** - * acos scalar function - */ - @ExecFunction(name = "acos", argTypes = {"DOUBLE"}, returnType = "DOUBLE") - public static Expression acos(DoubleLiteral literal) { - double result = Math.acos(literal.getValue()); - if (Double.isNaN(result)) { - return new NullLiteral(DoubleType.INSTANCE); - } else { - return new DoubleLiteral(result); - } - } - - /** - * append_trailing_char_if_absent function - */ - @ExecFunction(name = "append_trailing_char_if_absent", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR") - public static Expression appendTrailingIfCharAbsent(StringLikeLiteral literal, StringLikeLiteral chr) { - if (chr.getValue().length() != 1) { - return new NullLiteral(literal.getDataType()); - } - if (literal.getValue().endsWith(chr.getValue())) { - return literal; - } else { - return new VarcharLiteral(literal.getValue() + chr.getValue()); - } - } - - @ExecFunction(name = "e", argTypes = {}, returnType = "DOUBLE") - public static Expression e() { // CHECKSTYLE IGNORE THIS LINE - return new DoubleLiteral(Math.E); - } - - @ExecFunction(name = "pi", argTypes = {}, returnType = "DOUBLE") - public static Expression pi() { - return new DoubleLiteral(Math.PI); - } -} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java index 9477de8ed1a890..325e676fc046a0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java @@ -17,193 +17,248 @@ package org.apache.doris.nereids.trees.expressions.functions.executable; +import org.apache.doris.nereids.exceptions.NotSupportedException; import org.apache.doris.nereids.trees.expressions.ExecFunction; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral; +import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral; import org.apache.doris.nereids.trees.expressions.literal.DecimalLiteral; import org.apache.doris.nereids.trees.expressions.literal.DecimalV3Literal; import org.apache.doris.nereids.trees.expressions.literal.DoubleLiteral; +import org.apache.doris.nereids.trees.expressions.literal.FloatLiteral; import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.literal.LargeIntLiteral; +import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.literal.NullLiteral; import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral; +import org.apache.doris.nereids.trees.expressions.literal.StringLiteral; import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral; +import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral; import org.apache.doris.nereids.types.DecimalV3Type; import java.math.BigDecimal; import java.math.BigInteger; +import java.nio.charset.StandardCharsets; /** * executable functions: * add, subtract, multiply, divide */ public class NumericArithmetic { + /** + * other scalar function + */ + @ExecFunction(name = "abs") + public static Expression abs(TinyIntLiteral literal) { + return new SmallIntLiteral((short) Math.abs(literal.getValue())); + } + + @ExecFunction(name = "abs") + public static Expression abs(SmallIntLiteral literal) { + return new IntegerLiteral(Math.abs(literal.getValue())); + } + + @ExecFunction(name = "abs") + public static Expression abs(IntegerLiteral literal) { + return new BigIntLiteral(Math.abs((long) literal.getValue())); + } + + @ExecFunction(name = "abs") + public static Expression abs(BigIntLiteral literal) { + return new LargeIntLiteral(BigInteger.valueOf(literal.getValue()).abs()); + } + + @ExecFunction(name = "abs") + public static Expression abs(LargeIntLiteral literal) { + return new LargeIntLiteral(literal.getValue().abs()); + } + + @ExecFunction(name = "abs") + public static Expression abs(FloatLiteral literal) { + return new FloatLiteral(Math.abs(literal.getValue())); + } + + @ExecFunction(name = "abs") + public static Expression abs(DoubleLiteral literal) { + return new DoubleLiteral(Math.abs(literal.getValue())); + } + + @ExecFunction(name = "abs") + public static Expression abs(DecimalLiteral literal) { + return new DecimalLiteral(literal.getValue().abs()); + } + + @ExecFunction(name = "abs") + public static Expression abs(DecimalV3Literal literal) { + return new DecimalV3Literal(literal.getValue().abs()); + } + /** * Executable arithmetic functions add */ - @ExecFunction(name = "add", argTypes = {"TINYINT", "TINYINT"}, returnType = "SMALLINT") + @ExecFunction(name = "add") public static Expression addTinyIntTinyInt(TinyIntLiteral first, TinyIntLiteral second) { short result = (short) Math.addExact(first.getValue(), second.getValue()); return new SmallIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"TINYINT", "SMALLINT"}, returnType = "INT") + @ExecFunction(name = "add") public static Expression addTinyIntSmallInt(TinyIntLiteral first, SmallIntLiteral second) { int result = Math.addExact(first.getValue(), second.getValue()); return new IntegerLiteral(result); } - @ExecFunction(name = "add", argTypes = {"TINYINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addTinyIntInt(TinyIntLiteral first, IntegerLiteral second) { long result = Math.addExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"TINYINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addTinyIntBigInt(TinyIntLiteral first, BigIntLiteral second) { long result = Math.addExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"TINYINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "add") public static Expression addTinyIntLargeInt(TinyIntLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().add(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"SMALLINT", "TINYINT"}, returnType = "INT") + @ExecFunction(name = "add") public static Expression addSmallIntTinyInt(SmallIntLiteral first, TinyIntLiteral second) { int result = Math.addExact(first.getValue(), second.getValue()); return new IntegerLiteral(result); } - @ExecFunction(name = "add", argTypes = {"SMALLINT", "SMALLINT"}, returnType = "INT") + @ExecFunction(name = "add") public static Expression addSmallIntSmallInt(SmallIntLiteral first, SmallIntLiteral second) { int result = Math.addExact(first.getValue(), second.getValue()); return new IntegerLiteral(result); } - @ExecFunction(name = "add", argTypes = {"SMALLINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addSmallIntInt(SmallIntLiteral first, IntegerLiteral second) { long result = Math.addExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"SMALLINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addSmallIntBigInt(SmallIntLiteral first, BigIntLiteral second) { long result = Math.addExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"SMALLINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "add") public static Expression addSmallIntLargeInt(SmallIntLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().add(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"INT", "TINYINT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addIntTinyInt(IntegerLiteral first, TinyIntLiteral second) { long result = Math.addExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"INT", "SMALLINT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addIntSmallInt(IntegerLiteral first, SmallIntLiteral second) { long result = Math.addExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"INT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addIntInt(IntegerLiteral first, IntegerLiteral second) { long result = Math.addExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"INT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addIntBigInt(IntegerLiteral first, BigIntLiteral second) { long result = Math.addExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"INT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "add") public static Expression addIntLargeInt(IntegerLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().add(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"BIGINT", "TINYINT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addBigIntTinyInt(BigIntLiteral first, TinyIntLiteral second) { long result = Math.addExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"BIGINT", "SMALLINT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addBigIntSmallInt(BigIntLiteral first, SmallIntLiteral second) { long result = Math.addExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"BIGINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addBigIntInt(BigIntLiteral first, IntegerLiteral second) { long result = Math.addExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"BIGINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "add") public static Expression addBigIntBigInt(BigIntLiteral first, BigIntLiteral second) { long result = Math.addExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"BIGINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "add") public static Expression addBigIntLargeInt(BigIntLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().add(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"LARGEINT", "TINYINT"}, returnType = "LARGEINT") + @ExecFunction(name = "add") public static Expression addLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) { BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"LARGEINT", "SMALLINT"}, returnType = "LARGEINT") + @ExecFunction(name = "add") public static Expression addLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) { BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"LARGEINT", "INT"}, returnType = "LARGEINT") + @ExecFunction(name = "add") public static Expression addLargeIntInt(LargeIntLiteral first, IntegerLiteral second) { BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"LARGEINT", "BIGINT"}, returnType = "LARGEINT") + @ExecFunction(name = "add") public static Expression addLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) { BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"LARGEINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "add") public static Expression addLargeIntLargeInt(LargeIntLiteral first, LargeIntLiteral second) { BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "add", argTypes = {"DOUBLE", "DOUBLE"}, returnType = "DOUBLE") + @ExecFunction(name = "add") public static Expression addDoubleDouble(DoubleLiteral first, DoubleLiteral second) { double result = first.getValue() + second.getValue(); - return new DoubleLiteral(result); + return checkOutputBoundary(new DoubleLiteral(result)); } - @ExecFunction(name = "add", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2") + @ExecFunction(name = "add") public static Expression addDecimalDecimal(DecimalLiteral first, DecimalLiteral second) { BigDecimal result = first.getValue().add(second.getValue()); return new DecimalLiteral(result); } - @ExecFunction(name = "add", argTypes = {"DECIMALV3", "DECIMALV3"}, returnType = "DECIMALV3") + @ExecFunction(name = "add") public static Expression addDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3Literal second) { BigDecimal result = first.getValue().add(second.getValue()); return new DecimalV3Literal((DecimalV3Type) first.getDataType(), result); @@ -212,169 +267,169 @@ public static Expression addDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3 /** * Executable arithmetic functions subtract */ - @ExecFunction(name = "subtract", argTypes = {"TINYINT", "TINYINT"}, returnType = "SMALLINT") + @ExecFunction(name = "subtract") public static Expression subtractTinyIntTinyInt(TinyIntLiteral first, TinyIntLiteral second) { short result = (short) Math.subtractExact(first.getValue(), second.getValue()); return new SmallIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"TINYINT", "SMALLINT"}, returnType = "INT") + @ExecFunction(name = "subtract") public static Expression subtractTinyIntSmallInt(TinyIntLiteral first, SmallIntLiteral second) { int result = Math.subtractExact(first.getValue(), second.getValue()); return new IntegerLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"TINYINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractTinyIntInt(TinyIntLiteral first, IntegerLiteral second) { long result = Math.subtractExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"TINYINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractTinyIntBigInt(TinyIntLiteral first, BigIntLiteral second) { long result = Math.subtractExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"TINYINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "subtract") public static Expression subtractTinyIntLargeInt(TinyIntLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().subtract(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"SMALLINT", "TINYINT"}, returnType = "INT") + @ExecFunction(name = "subtract") public static Expression subtractSmallIntTinyInt(SmallIntLiteral first, TinyIntLiteral second) { int result = Math.subtractExact(first.getValue(), second.getValue()); return new IntegerLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"SMALLINT", "SMALLINT"}, returnType = "INT") + @ExecFunction(name = "subtract") public static Expression subtractSmallIntSmallInt(SmallIntLiteral first, SmallIntLiteral second) { int result = Math.subtractExact(first.getValue(), second.getValue()); return new IntegerLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"SMALLINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractSmallIntInt(SmallIntLiteral first, IntegerLiteral second) { long result = Math.subtractExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"SMALLINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractSmallIntBigInt(SmallIntLiteral first, BigIntLiteral second) { long result = Math.subtractExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"SMALLINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "subtract") public static Expression subtractSmallIntLargeInt(SmallIntLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().subtract(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"INT", "TINYINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractIntTinyInt(IntegerLiteral first, TinyIntLiteral second) { long result = Math.subtractExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"INT", "SMALLINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractIntSmallInt(IntegerLiteral first, SmallIntLiteral second) { long result = Math.subtractExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"INT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractIntInt(IntegerLiteral first, IntegerLiteral second) { long result = Math.subtractExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"INT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractIntBigInt(IntegerLiteral first, BigIntLiteral second) { long result = Math.subtractExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"INT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "subtract") public static Expression subtractIntLargeInt(IntegerLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().subtract(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"BIGINT", "TINYINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractBigIntTinyInt(BigIntLiteral first, TinyIntLiteral second) { long result = Math.subtractExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"BIGINT", "SMALLINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractBigIntSmallInt(BigIntLiteral first, SmallIntLiteral second) { long result = Math.subtractExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"BIGINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractBigIntInt(BigIntLiteral first, IntegerLiteral second) { long result = Math.subtractExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"BIGINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractBigIntBigInt(BigIntLiteral first, BigIntLiteral second) { long result = Math.subtractExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"BIGINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "subtract") public static Expression subtractBigIntLargeInt(BigIntLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().subtract(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"LARGEINT", "TINYINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) { BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"LARGEINT", "SMALLINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) { BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"LARGEINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractLargeIntInt(LargeIntLiteral first, IntegerLiteral second) { BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"LARGEINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "subtract") public static Expression subtractLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) { BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"LARGEINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "subtract") public static Expression subtractLargeIntLargeInt(LargeIntLiteral first, LargeIntLiteral second) { BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"DOUBLE", "DOUBLE"}, returnType = "DOUBLE") + @ExecFunction(name = "subtract") public static Expression subtractDoubleDouble(DoubleLiteral first, DoubleLiteral second) { double result = first.getValue() - second.getValue(); - return new DoubleLiteral(result); + return checkOutputBoundary(new DoubleLiteral(result)); } - @ExecFunction(name = "subtract", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2") + @ExecFunction(name = "subtract") public static Expression subtractDecimalDecimal(DecimalLiteral first, DecimalLiteral second) { BigDecimal result = first.getValue().subtract(second.getValue()); return new DecimalLiteral(result); } - @ExecFunction(name = "subtract", argTypes = {"DECIMALV3", "DECIMALV3"}, returnType = "DECIMALV3") + @ExecFunction(name = "subtract") public static Expression subtractDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3Literal second) { BigDecimal result = first.getValue().subtract(second.getValue()); return new DecimalV3Literal((DecimalV3Type) first.getDataType(), result); @@ -383,163 +438,163 @@ public static Expression subtractDecimalV3DecimalV3(DecimalV3Literal first, Deci /** * Executable arithmetic functions multiply */ - @ExecFunction(name = "multiply", argTypes = {"TINYINT", "TINYINT"}, returnType = "SMALLINT") + @ExecFunction(name = "multiply") public static Expression multiplyTinyIntTinyInt(TinyIntLiteral first, TinyIntLiteral second) { short result = (short) Math.multiplyExact(first.getValue(), second.getValue()); return new SmallIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"TINYINT", "SMALLINT"}, returnType = "INT") + @ExecFunction(name = "multiply") public static Expression multiplyTinyIntSmallInt(TinyIntLiteral first, SmallIntLiteral second) { int result = Math.multiplyExact(first.getValue(), second.getValue()); return new IntegerLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"TINYINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyTinyIntInt(TinyIntLiteral first, IntegerLiteral second) { long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"TINYINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyTinyIntBigInt(TinyIntLiteral first, BigIntLiteral second) { long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"TINYINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "multiply") public static Expression multiplyTinyIntLargeInt(TinyIntLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().multiply(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"SMALLINT", "TINYINT"}, returnType = "INT") + @ExecFunction(name = "multiply") public static Expression multiplySmallIntTinyInt(SmallIntLiteral first, TinyIntLiteral second) { int result = Math.multiplyExact(first.getValue(), second.getValue()); return new IntegerLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"SMALLINT", "SMALLINT"}, returnType = "INT") + @ExecFunction(name = "multiply") public static Expression multiplySmallIntSmallInt(SmallIntLiteral first, SmallIntLiteral second) { int result = Math.multiplyExact(first.getValue(), second.getValue()); return new IntegerLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"SMALLINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplySmallIntInt(SmallIntLiteral first, IntegerLiteral second) { long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"SMALLINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplySmallIntBigInt(SmallIntLiteral first, BigIntLiteral second) { long result = Math.multiplyExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"SMALLINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "multiply") public static Expression multiplySmallIntLargeInt(SmallIntLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().multiply(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"INT", "TINYINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyIntTinyInt(IntegerLiteral first, TinyIntLiteral second) { long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"INT", "SMALLINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyIntSmallInt(IntegerLiteral first, SmallIntLiteral second) { long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"INT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyIntInt(IntegerLiteral first, IntegerLiteral second) { long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"INT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyIntBigInt(IntegerLiteral first, BigIntLiteral second) { long result = Math.multiplyExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"INT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "multiply") public static Expression multiplyIntLargeInt(IntegerLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().multiply(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"BIGINT", "TINYINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyBigIntTinyInt(BigIntLiteral first, TinyIntLiteral second) { long result = Math.multiplyExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"BIGINT", "SMALLINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyBigIntSmallInt(BigIntLiteral first, SmallIntLiteral second) { long result = Math.multiplyExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"BIGINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyBigIntInt(BigIntLiteral first, IntegerLiteral second) { long result = Math.multiplyExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"BIGINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyBigIntBigInt(BigIntLiteral first, BigIntLiteral second) { long result = Math.multiplyExact(first.getValue(), second.getValue()); return new BigIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"BIGINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "multiply") public static Expression multiplyBigIntLargeInt(BigIntLiteral first, LargeIntLiteral second) { BigInteger result = second.getValue().multiply(new BigInteger(first.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"LARGEINT", "TINYINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) { BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"LARGEINT", "SMALLINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) { BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"LARGEINT", "INT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyLargeIntInt(LargeIntLiteral first, IntegerLiteral second) { BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"LARGEINT", "BIGINT"}, returnType = "BIGINT") + @ExecFunction(name = "multiply") public static Expression multiplyLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) { BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"LARGEINT", "LARGEINT"}, returnType = "LARGEINT") + @ExecFunction(name = "multiply") public static Expression multiplyLargeIntLargeInt(LargeIntLiteral first, LargeIntLiteral second) { BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString())); return new LargeIntLiteral(result); } - @ExecFunction(name = "multiply", argTypes = {"DOUBLE", "DOUBLE"}, returnType = "DOUBLE") + @ExecFunction(name = "multiply") public static Expression multiplyDoubleDouble(DoubleLiteral first, DoubleLiteral second) { double result = first.getValue() * second.getValue(); - return new DoubleLiteral(result); + return checkOutputBoundary(new DoubleLiteral(result)); } - @ExecFunction(name = "multiply", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2") + @ExecFunction(name = "multiply") public static Expression multiplyDecimalDecimal(DecimalLiteral first, DecimalLiteral second) { BigDecimal result = first.getValue().multiply(second.getValue()); return new DecimalLiteral(result); @@ -548,7 +603,7 @@ public static Expression multiplyDecimalDecimal(DecimalLiteral first, DecimalLit /** * decimalV3 multiply in FE */ - @ExecFunction(name = "multiply", argTypes = {"DECIMALV3", "DECIMALV3"}, returnType = "DECIMALV3") + @ExecFunction(name = "multiply") public static Expression multiplyDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3Literal second) { BigDecimal result = first.getValue().multiply(second.getValue()); DecimalV3Type t1 = (DecimalV3Type) first.getDataType(); @@ -561,19 +616,19 @@ public static Expression multiplyDecimalV3DecimalV3(DecimalV3Literal first, Deci /** * Executable arithmetic functions divide */ - @ExecFunction(name = "divide", argTypes = {"DOUBLE", "DOUBLE"}, returnType = "DOUBLE") + @ExecFunction(name = "divide") public static Expression divideDouble(DoubleLiteral first, DoubleLiteral second) { if (second.getValue() == 0.0) { return new NullLiteral(first.getDataType()); } double result = first.getValue() / second.getValue(); - return new DoubleLiteral(result); + return checkOutputBoundary(new DoubleLiteral(result)); } /** * Executable arithmetic functions divide */ - @ExecFunction(name = "divide", argTypes = {"DECIMALV2", "DECIMALV2"}, returnType = "DECIMALV2") + @ExecFunction(name = "divide") public static Expression divideDecimal(DecimalLiteral first, DecimalLiteral second) { if (first.getValue().compareTo(BigDecimal.ZERO) == 0) { return new NullLiteral(first.getDataType()); @@ -585,7 +640,7 @@ public static Expression divideDecimal(DecimalLiteral first, DecimalLiteral seco /** * decimalv3 divide in FE */ - @ExecFunction(name = "divide", argTypes = {"DECIMALV3", "DECIMALV3"}, returnType = "DECIMALV3") + @ExecFunction(name = "divide") public static Expression divideDecimalV3(DecimalV3Literal first, DecimalV3Literal second) { if (second.getValue().compareTo(BigDecimal.ZERO) == 0) { return new NullLiteral(first.getDataType()); @@ -596,4 +651,507 @@ public static Expression divideDecimalV3(DecimalV3Literal first, DecimalV3Litera return new DecimalV3Literal(DecimalV3Type.createDecimalV3TypeLooseCheck( t1.getPrecision(), t1.getScale() - t2.getScale()), result); } + + /** + * coalesce + */ + @ExecFunction(name = "coalesce") + public static Expression coalesce(Literal first, Literal... second) { + if (!(first instanceof NullLiteral)) { + return first; + } + for (Literal secondLiteral : second) { + if (!(secondLiteral instanceof NullLiteral)) { + return secondLiteral; + } + } + return first; + } + + /** + * Method to check boundary with options for inclusive or exclusive boundaries + */ + public static void checkInputBoundary(Literal input, double lowerBound, double upperBound, + boolean isLowerInclusive, boolean isUpperInclusive) { + if (input instanceof DoubleLiteral) { + double inputValue = ((DoubleLiteral) input).getValue(); + boolean lowerCheck = isLowerInclusive ? (inputValue >= lowerBound) : (inputValue > lowerBound); + // Check upper bound + boolean upperCheck = isUpperInclusive ? (inputValue <= upperBound) : (inputValue < upperBound); + // Return true if both checks are satisfied + if (!lowerCheck || !upperCheck) { + throw new NotSupportedException("input " + input.toSql() + " is out of boundary"); + } + } + } + + private static Expression checkOutputBoundary(Literal input) { + if (input instanceof DoubleLiteral) { + if (((DoubleLiteral) input).getValue().isNaN() || ((DoubleLiteral) input).getValue().isInfinite()) { + throw new NotSupportedException(input.toSql() + " result is invalid"); + } + } + return input; + } + + /** + * round + */ + @ExecFunction(name = "round") + public static Expression round(DecimalV3Literal first) { + return first.round(0); + } + + /** + * round + */ + @ExecFunction(name = "round") + public static Expression round(DecimalV3Literal first, IntegerLiteral second) { + return first.round(second.getValue()); + } + + /** + * round + */ + @ExecFunction(name = "round") + public static Expression round(DoubleLiteral first) { + DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue()))); + return new DoubleLiteral(middleResult.round(0).getDouble()); + } + + /** + * round + */ + @ExecFunction(name = "round") + public static Expression round(DoubleLiteral first, IntegerLiteral second) { + DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue()))); + return new DoubleLiteral(middleResult.round(second.getValue()).getDouble()); + } + + /** + * ceil + */ + @ExecFunction(name = "ceil") + public static Expression ceil(DecimalV3Literal first) { + return first.roundCeiling(0); + } + + /** + * ceil + */ + @ExecFunction(name = "ceil") + public static Expression ceil(DecimalV3Literal first, IntegerLiteral second) { + return first.roundCeiling(second.getValue()); + } + + /** + * ceil + */ + @ExecFunction(name = "ceil") + public static Expression ceil(DoubleLiteral first) { + DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue()))); + return new DoubleLiteral(middleResult.roundCeiling(0).getDouble()); + } + + /** + * ceil + */ + @ExecFunction(name = "ceil") + public static Expression ceil(DoubleLiteral first, IntegerLiteral second) { + DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue()))); + return new DoubleLiteral(middleResult.roundCeiling(second.getValue()).getDouble()); + } + + /** + * floor + */ + @ExecFunction(name = "floor") + public static Expression floor(DecimalV3Literal first) { + return first.roundFloor(0); + } + + /** + * floor + */ + @ExecFunction(name = "floor") + public static Expression floor(DecimalV3Literal first, IntegerLiteral second) { + return first.roundFloor(second.getValue()); + } + + /** + * floor + */ + @ExecFunction(name = "floor") + public static Expression floor(DoubleLiteral first) { + DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue()))); + return new DoubleLiteral(middleResult.roundFloor(0).getDouble()); + } + + /** + * floor + */ + @ExecFunction(name = "floor") + public static Expression floor(DoubleLiteral first, IntegerLiteral second) { + DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue()))); + return new DoubleLiteral(middleResult.roundFloor(second.getValue()).getDouble()); + } + + /** + * exp + */ + @ExecFunction(name = "exp") + public static Expression exp(DoubleLiteral first) { + return checkOutputBoundary(new DoubleLiteral(Math.exp(first.getValue()))); + } + + /** + * ln + */ + @ExecFunction(name = "ln") + public static Expression ln(DoubleLiteral first) { + checkInputBoundary(first, 0.0d, Double.MAX_VALUE, false, true); + return checkOutputBoundary(new DoubleLiteral(Math.log(first.getValue()))); + } + + /** + * log + */ + @ExecFunction(name = "log") + public static Expression log(DoubleLiteral first, DoubleLiteral second) { + checkInputBoundary(first, 0.0d, Double.MAX_VALUE, false, true); + return checkOutputBoundary(new DoubleLiteral(Math.log(first.getValue()) / Math.log(second.getValue()))); + } + + /** + * log2 + */ + @ExecFunction(name = "log2") + public static Expression log2(DoubleLiteral first) { + checkInputBoundary(first, 0.0d, Double.MAX_VALUE, false, true); + return checkOutputBoundary(new DoubleLiteral(Math.log(first.getValue()) / Math.log(2.0))); + } + + /** + * log10 + */ + @ExecFunction(name = "log10") + public static Expression log10(DoubleLiteral first) { + checkInputBoundary(first, 0.0d, Double.MAX_VALUE, false, true); + return checkOutputBoundary(new DoubleLiteral(Math.log10(first.getValue()))); + } + + /** + * sqrt + */ + @ExecFunction(name = "sqrt") + public static Expression sqrt(DoubleLiteral first) { + checkInputBoundary(first, 0.0d, Double.MAX_VALUE, true, true); + return checkOutputBoundary(new DoubleLiteral(Math.sqrt(first.getValue()))); + } + + /** + * power + */ + @ExecFunction(name = "power") + public static Expression power(DoubleLiteral first, DoubleLiteral second) { + checkInputBoundary(second, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, false, false); + return checkOutputBoundary(new DoubleLiteral(Math.pow(first.getValue(), second.getValue()))); + } + + /** + * sin + */ + @ExecFunction(name = "sin") + public static Expression sin(DoubleLiteral first) { + checkInputBoundary(first, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, false, false); + return checkOutputBoundary(new DoubleLiteral(Math.sin(first.getValue()))); + } + + /** + * cos + */ + @ExecFunction(name = "cos") + public static Expression cos(DoubleLiteral first) { + checkInputBoundary(first, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, false, false); + return checkOutputBoundary(new DoubleLiteral(Math.cos(first.getValue()))); + } + + /** + * tan + */ + @ExecFunction(name = "tan") + public static Expression tan(DoubleLiteral first) { + checkInputBoundary(first, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, false, false); + return checkOutputBoundary(new DoubleLiteral(Math.tan(first.getValue()))); + } + + /** + * asin + */ + @ExecFunction(name = "asin") + public static Expression asin(DoubleLiteral first) { + checkInputBoundary(first, -1.0, 1.0, true, true); + return checkOutputBoundary(new DoubleLiteral(Math.asin(first.getValue()))); + } + + /** + * acos + */ + @ExecFunction(name = "acos") + public static Expression acos(DoubleLiteral first) { + checkInputBoundary(first, -1.0, 1.0, true, true); + return checkOutputBoundary(new DoubleLiteral(Math.acos(first.getValue()))); + } + + /** + * atan + */ + @ExecFunction(name = "atan") + public static Expression atan(DoubleLiteral first) { + return checkOutputBoundary(new DoubleLiteral(Math.atan(first.getValue()))); + } + + /** + * atan2 + */ + @ExecFunction(name = "atan2") + public static Expression atan2(DoubleLiteral first, DoubleLiteral second) { + return checkOutputBoundary(new DoubleLiteral(Math.atan2(first.getValue(), second.getValue()))); + } + + /** + * sign + */ + @ExecFunction(name = "sign") + public static Expression sign(DoubleLiteral first) { + if (first.getValue() < 0) { + return new TinyIntLiteral((byte) -1); + } else if (first.getValue() == 0) { + return new TinyIntLiteral((byte) 0); + } else { + return new TinyIntLiteral((byte) 1); + } + } + + /** + * bit_count + */ + @ExecFunction(name = "bit_count") + public static Expression bitCount(TinyIntLiteral first) { + return new TinyIntLiteral((byte) Integer.bitCount(first.getValue() & 0xFF)); + } + + /** + * bit_count + */ + @ExecFunction(name = "bit_count") + public static Expression bitCount(SmallIntLiteral first) { + return new TinyIntLiteral((byte) Integer.bitCount(first.getValue() & 0xFFFF)); + } + + /** + * bit_count + */ + @ExecFunction(name = "bit_count") + public static Expression bitCount(IntegerLiteral first) { + return new TinyIntLiteral((byte) Integer.bitCount(first.getValue())); + } + + /** + * bit_count + */ + @ExecFunction(name = "bit_count") + public static Expression bitCount(BigIntLiteral first) { + return new TinyIntLiteral((byte) Long.bitCount(first.getValue())); + } + + /** + * bit_count + */ + @ExecFunction(name = "bit_count") + public static Expression bitCount(LargeIntLiteral first) { + if (first.getValue().compareTo(BigInteger.ZERO) < 0) { + return new SmallIntLiteral((short) (128 - first.getValue().bitCount())); + } else { + return new SmallIntLiteral((short) first.getValue().bitCount()); + } + } + + /** + * bit_length + */ + @ExecFunction(name = "bit_length") + public static Expression bitLength(VarcharLiteral first) { + byte[] byteArray = first.getValue().getBytes(StandardCharsets.UTF_8); // Convert to bytes in UTF-8 + int byteLength = byteArray.length; + return new IntegerLiteral(byteLength * Byte.SIZE); + } + + /** + * bit_length + */ + @ExecFunction(name = "bit_length") + public static Expression bitLength(StringLiteral first) { + byte[] byteArray = first.getValue().getBytes(StandardCharsets.UTF_8); // Convert to bytes in UTF-8 + int byteLength = byteArray.length; + return new IntegerLiteral(byteLength * Byte.SIZE); + } + + /** + * cbrt + */ + @ExecFunction(name = "cbrt") + public static Expression cbrt(DoubleLiteral first) { + return checkOutputBoundary(new DoubleLiteral(Math.cbrt(first.getValue()))); + } + + /** + * cosh + */ + @ExecFunction(name = "cosh") + public static Expression cosh(DoubleLiteral first) { + return checkOutputBoundary(new DoubleLiteral(Math.cosh(first.getValue()))); + } + + /** + * tanh + */ + @ExecFunction(name = "cosh") + public static Expression tanh(DoubleLiteral first) { + return checkOutputBoundary(new DoubleLiteral(Math.tanh(first.getValue()))); + } + + /** + * dexp + */ + @ExecFunction(name = "dexp") + public static Expression dexp(DoubleLiteral first) { + double exp = Math.exp(first.getValue()); + return checkOutputBoundary(new DoubleLiteral(exp)); + } + + /** + * dlog1 + */ + @ExecFunction(name = "dlog1") + public static Expression dlog1(DoubleLiteral first) { + checkInputBoundary(first, 0.0d, Double.MAX_VALUE, false, true); + return checkOutputBoundary(new DoubleLiteral(Math.log1p(first.getValue()))); + } + + /** + * dlog10 + */ + @ExecFunction(name = "dlog10") + public static Expression dlog10(DoubleLiteral first) { + checkInputBoundary(first, 0.0d, Double.MAX_VALUE, false, true); + return checkOutputBoundary(new DoubleLiteral(Math.log10(first.getValue()))); + } + + /** + * dsqrt + */ + @ExecFunction(name = "dsqrt") + public static Expression dsqrt(DoubleLiteral first) { + checkInputBoundary(first, 0.0d, Double.MAX_VALUE, false, true); + return checkOutputBoundary(new DoubleLiteral(Math.sqrt(first.getValue()))); + } + + /** + * dpower + */ + @ExecFunction(name = "dpow") + public static Expression dpow(DoubleLiteral first, DoubleLiteral second) { + return checkOutputBoundary(new DoubleLiteral(Math.pow(first.getValue(), second.getValue()))); + } + + /** + * fmod + */ + @ExecFunction(name = "fmod") + public static Expression fmod(DoubleLiteral first, DoubleLiteral second) { + return checkOutputBoundary(new DoubleLiteral(first.getValue() / second.getValue())); + } + + /** + * fmod + */ + @ExecFunction(name = "fmod") + public static Expression fmod(FloatLiteral first, FloatLiteral second) { + return new FloatLiteral(first.getValue() / second.getValue()); + } + + /** + * fpow + */ + @ExecFunction(name = "fpow") + public static Expression fpow(DoubleLiteral first, DoubleLiteral second) { + return checkOutputBoundary(new DoubleLiteral(Math.pow(first.getValue(), second.getValue()))); + } + + /** + * radians + */ + @ExecFunction(name = "radians") + public static Expression radians(DoubleLiteral first) { + return checkOutputBoundary(new DoubleLiteral(Math.toRadians(first.getValue()))); + } + + /** + * degrees + */ + @ExecFunction(name = "degrees") + public static Expression degrees(DoubleLiteral first) { + return checkOutputBoundary(new DoubleLiteral(Math.toDegrees(first.getValue()))); + } + + /** + * xor + */ + @ExecFunction(name = "xor") + public static Expression xor(BooleanLiteral first, BooleanLiteral second) { + return BooleanLiteral.of(Boolean.logicalXor(first.getValue(), second.getValue())); + } + + /** + * pi + */ + @ExecFunction(name = "pi") + public static Expression pi() { + return DoubleLiteral.of(Math.PI); + } + + /** + * E + */ + @ExecFunction(name = "e") + public static Expression mathE() { + return DoubleLiteral.of(Math.E); + } + + /** + * truncate + */ + @ExecFunction(name = "truncate") + public static Expression truncate(DecimalV3Literal first, IntegerLiteral second) { + if (first.getValue().compareTo(BigDecimal.ZERO) == 0) { + return first; + } else { + if (first.getValue().scale() < second.getValue()) { + return first; + } + if (second.getValue() < 0) { + double factor = Math.pow(10, Math.abs(second.getValue())); + return new DecimalV3Literal( + DecimalV3Type.createDecimalV3Type(first.getValue().precision(), 0), + BigDecimal.valueOf(Math.floor(first.getDouble() / factor) * factor)); + } + if (first.getValue().compareTo(BigDecimal.ZERO) == -1) { + return first.roundCeiling(second.getValue()); + } else { + return first.roundFloor(second.getValue()); + } + } + } + } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java index ed319e027398f4..795eeaf6af9017 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java @@ -68,7 +68,7 @@ private static Expression castStringLikeLiteral(StringLikeLiteral first, String /** * Executable arithmetic functions concat */ - @ExecFunction(name = "concat", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "concat") public static Expression concatVarcharVarchar(StringLikeLiteral first, StringLikeLiteral second) { String result = first.getValue() + second.getValue(); return castStringLikeLiteral(first, result); @@ -103,7 +103,7 @@ private static String substringImpl(String first, int second, int third) { /** * Executable arithmetic functions substring */ - @ExecFunction(name = "substring", argTypes = {"VARCHAR", "INT", "INT"}, returnType = "VARCHAR") + @ExecFunction(name = "substring") public static Expression substringVarcharIntInt(StringLikeLiteral first, IntegerLiteral second, IntegerLiteral third) { return castStringLikeLiteral(first, substringImpl(first.getValue(), second.getValue(), third.getValue())); @@ -112,7 +112,7 @@ public static Expression substringVarcharIntInt(StringLikeLiteral first, /** * Executable arithmetic functions length */ - @ExecFunction(name = "length", argTypes = {"VARCHAR"}, returnType = "INT") + @ExecFunction(name = "length") public static Expression lengthVarchar(StringLikeLiteral first) { return new IntegerLiteral(first.getValue().length()); } @@ -120,7 +120,7 @@ public static Expression lengthVarchar(StringLikeLiteral first) { /** * Executable arithmetic functions Lower */ - @ExecFunction(name = "lower", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "lower") public static Expression lowerVarchar(StringLikeLiteral first) { return castStringLikeLiteral(first, first.getValue().toLowerCase()); } @@ -128,7 +128,7 @@ public static Expression lowerVarchar(StringLikeLiteral first) { /** * Executable arithmetic functions Upper */ - @ExecFunction(name = "upper", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "upper") public static Expression upperVarchar(StringLikeLiteral first) { return castStringLikeLiteral(first, first.getValue().toUpperCase()); } @@ -154,7 +154,7 @@ private static String trimImpl(String first, String second, boolean left, boolea /** * Executable arithmetic functions Trim */ - @ExecFunction(name = "trim", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "trim") public static Expression trimVarchar(StringLikeLiteral first) { return castStringLikeLiteral(first, trimImpl(first.getValue(), " ", true, true)); } @@ -162,7 +162,7 @@ public static Expression trimVarchar(StringLikeLiteral first) { /** * Executable arithmetic functions Trim */ - @ExecFunction(name = "trim", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "trim") public static Expression trimVarcharVarchar(StringLikeLiteral first, StringLikeLiteral second) { return castStringLikeLiteral(first, trimImpl(first.getValue(), second.getValue(), true, true)); } @@ -170,7 +170,7 @@ public static Expression trimVarcharVarchar(StringLikeLiteral first, StringLikeL /** * Executable arithmetic functions ltrim */ - @ExecFunction(name = "ltrim", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "ltrim") public static Expression ltrimVarchar(StringLikeLiteral first) { return castStringLikeLiteral(first, trimImpl(first.getValue(), " ", true, false)); } @@ -178,7 +178,7 @@ public static Expression ltrimVarchar(StringLikeLiteral first) { /** * Executable arithmetic functions ltrim */ - @ExecFunction(name = "ltrim", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "ltrim") public static Expression ltrimVarcharVarchar(StringLikeLiteral first, StringLikeLiteral second) { return castStringLikeLiteral(first, trimImpl(first.getValue(), second.getValue(), true, false)); } @@ -186,7 +186,7 @@ public static Expression ltrimVarcharVarchar(StringLikeLiteral first, StringLike /** * Executable arithmetic functions rtrim */ - @ExecFunction(name = "rtrim", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "rtrim") public static Expression rtrimVarchar(StringLikeLiteral first) { return castStringLikeLiteral(first, trimImpl(first.getValue(), " ", false, true)); } @@ -194,7 +194,7 @@ public static Expression rtrimVarchar(StringLikeLiteral first) { /** * Executable arithmetic functions rtrim */ - @ExecFunction(name = "rtrim", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "rtrim") public static Expression rtrimVarcharVarchar(StringLikeLiteral first, StringLikeLiteral second) { return castStringLikeLiteral(first, trimImpl(first.getValue(), second.getValue(), false, true)); } @@ -202,7 +202,7 @@ public static Expression rtrimVarcharVarchar(StringLikeLiteral first, StringLike /** * Executable arithmetic functions Replace */ - @ExecFunction(name = "replace", argTypes = {"VARCHAR", "VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "replace") public static Expression replace(StringLikeLiteral first, StringLikeLiteral second, StringLikeLiteral third) { if (second.getValue().length() == 0) { return castStringLikeLiteral(first, first.getValue()); @@ -213,7 +213,7 @@ public static Expression replace(StringLikeLiteral first, StringLikeLiteral seco /** * Executable arithmetic functions Left */ - @ExecFunction(name = "left", argTypes = {"VARCHAR", "INT"}, returnType = "VARCHAR") + @ExecFunction(name = "left") public static Expression left(StringLikeLiteral first, IntegerLiteral second) { if (second.getValue() <= 0) { return castStringLikeLiteral(first, ""); @@ -227,7 +227,7 @@ public static Expression left(StringLikeLiteral first, IntegerLiteral second) { /** * Executable arithmetic functions Right */ - @ExecFunction(name = "right", argTypes = {"VARCHAR", "INT"}, returnType = "VARCHAR") + @ExecFunction(name = "right") public static Expression right(StringLikeLiteral first, IntegerLiteral second) { if (second.getValue() < (- first.getValue().length()) || Math.abs(second.getValue()) == 0) { return castStringLikeLiteral(first, ""); @@ -247,7 +247,7 @@ public static Expression right(StringLikeLiteral first, IntegerLiteral second) { /** * Executable arithmetic functions Locate */ - @ExecFunction(name = "locate", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "INT") + @ExecFunction(name = "locate") public static Expression locate(StringLikeLiteral first, StringLikeLiteral second) { return new IntegerLiteral(second.getValue().trim().indexOf(first.getValue()) + 1); } @@ -255,7 +255,7 @@ public static Expression locate(StringLikeLiteral first, StringLikeLiteral secon /** * Executable arithmetic functions Instr */ - @ExecFunction(name = "instr", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "INT") + @ExecFunction(name = "instr") public static Expression instr(StringLikeLiteral first, StringLikeLiteral second) { return new IntegerLiteral(first.getValue().indexOf(second.getValue()) + 1); } @@ -263,7 +263,7 @@ public static Expression instr(StringLikeLiteral first, StringLikeLiteral second /** * Executable arithmetic functions Ascii */ - @ExecFunction(name = "ascii", argTypes = {"VARCHAR"}, returnType = "INT") + @ExecFunction(name = "ascii") public static Expression ascii(StringLikeLiteral first) { if (first.getValue().length() == 0) { return new IntegerLiteral(0); @@ -275,7 +275,7 @@ public static Expression ascii(StringLikeLiteral first) { /** * Executable arithmetic functions Bin */ - @ExecFunction(name = "bin", argTypes = {"BIGINT"}, returnType = "VARCHAR") + @ExecFunction(name = "bin") public static Expression bin(BigIntLiteral first) { return new VarcharLiteral(Long.toBinaryString(first.getValue())); } @@ -283,7 +283,7 @@ public static Expression bin(BigIntLiteral first) { /** * Executable arithmetic functions ConcatWs */ - @ExecFunction(name = "concat_ws", argTypes = {"VARCHAR", "ARRAY"}, returnType = "VARCHAR") + @ExecFunction(name = "concat_ws") public static Expression concatWsVarcharArray(StringLikeLiteral first, ArrayLiteral second) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < second.getValue().size() - 1; i++) { @@ -299,7 +299,7 @@ public static Expression concatWsVarcharArray(StringLikeLiteral first, ArrayLite /** * Executable arithmetic functions ConcatWs */ - @ExecFunction(varArgs = true, name = "concat_ws", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "concat_ws") public static Expression concatWsVarcharVarchar(StringLikeLiteral first, VarcharLiteral... second) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < second.length - 1; i++) { @@ -313,7 +313,7 @@ public static Expression concatWsVarcharVarchar(StringLikeLiteral first, Varchar /** * Executable arithmetic functions CharacterLength */ - @ExecFunction(name = "character_length", argTypes = {"VARCHAR"}, returnType = "INT") + @ExecFunction(name = "character_length") public static Expression characterLength(StringLikeLiteral first) { return new IntegerLiteral(first.getValue().length()); } @@ -329,7 +329,7 @@ private static boolean isSeparator(char c) { /** * Executable arithmetic functions initCap */ - @ExecFunction(name = "initcap", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "initcap") public static Expression initCap(StringLikeLiteral first) { StringBuilder result = new StringBuilder(first.getValue().length()); boolean capitalizeNext = true; @@ -351,7 +351,7 @@ public static Expression initCap(StringLikeLiteral first) { /** * Executable arithmetic functions md5 */ - @ExecFunction(name = "md5", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "md5") public static Expression md5(StringLikeLiteral first) { try { MessageDigest md = MessageDigest.getInstance("MD5"); @@ -366,7 +366,7 @@ public static Expression md5(StringLikeLiteral first) { /** * Executable arithmetic functions md5 */ - @ExecFunction(varArgs = true, name = "md5sum", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "md5sum") public static Expression md5Sum(VarcharLiteral... first) { try { // Step 1: Create a MessageDigest instance for MD5 @@ -420,7 +420,7 @@ private static int compareLiteral(Literal first, Literal... second) { /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"INT", "INT"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldInt(IntegerLiteral first, IntegerLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -428,7 +428,7 @@ public static Expression fieldInt(IntegerLiteral first, IntegerLiteral... second /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"TINYINT", "TINYINT"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldTinyInt(TinyIntLiteral first, TinyIntLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -436,7 +436,7 @@ public static Expression fieldTinyInt(TinyIntLiteral first, TinyIntLiteral... se /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"SMALLINT", "SMALLINT"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldSmallInt(SmallIntLiteral first, SmallIntLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -444,7 +444,7 @@ public static Expression fieldSmallInt(SmallIntLiteral first, SmallIntLiteral... /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"BIGINT", "BIGINT"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldBigInt(BigIntLiteral first, BigIntLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -452,7 +452,7 @@ public static Expression fieldBigInt(BigIntLiteral first, BigIntLiteral... secon /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"LARGEINT", "LARGEINT"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldLargeInt(LargeIntLiteral first, LargeIntLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -460,7 +460,7 @@ public static Expression fieldLargeInt(LargeIntLiteral first, LargeIntLiteral... /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"FLOAT", "FLOAT"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldFloat(FloatLiteral first, FloatLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -468,7 +468,7 @@ public static Expression fieldFloat(FloatLiteral first, FloatLiteral... second) /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"DOUBLE", "DOUBLE"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldDouble(DoubleLiteral first, DoubleLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -476,7 +476,7 @@ public static Expression fieldDouble(DoubleLiteral first, DoubleLiteral... secon /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldDecimalV2(DecimalLiteral first, DecimalLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -484,7 +484,7 @@ public static Expression fieldDecimalV2(DecimalLiteral first, DecimalLiteral... /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"DECIMALV3", "DECIMALV3"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldDecimalV3(DecimalV3Literal first, DecimalV3Literal... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -492,7 +492,7 @@ public static Expression fieldDecimalV3(DecimalV3Literal first, DecimalV3Literal /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"DATETIME", "DATETIME"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldDateTime(DateTimeLiteral first, DateTimeLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -500,7 +500,7 @@ public static Expression fieldDateTime(DateTimeLiteral first, DateTimeLiteral... /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldDateTimeV2(DateTimeV2Literal first, DateTimeV2Literal... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -508,7 +508,7 @@ public static Expression fieldDateTimeV2(DateTimeV2Literal first, DateTimeV2Lite /** * Executable arithmetic functions field */ - @ExecFunction(varArgs = true, name = "field", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "INT") + @ExecFunction(name = "field") public static Expression fieldVarchar(StringLikeLiteral first, VarcharLiteral... second) { return new IntegerLiteral(compareLiteral(first, second)); } @@ -526,7 +526,7 @@ private static int findStringInSet(String target, String input) { /** * Executable arithmetic functions find_in_set */ - @ExecFunction(name = "find_in_set", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "INT") + @ExecFunction(name = "find_in_set") public static Expression findInSetVarchar(StringLikeLiteral first, StringLikeLiteral second) { return new IntegerLiteral(findStringInSet(first.getValue(), second.getValue())); } @@ -534,7 +534,7 @@ public static Expression findInSetVarchar(StringLikeLiteral first, StringLikeLit /** * Executable arithmetic functions repeat */ - @ExecFunction(name = "repeat", argTypes = {"VARCHAR", "INT"}, returnType = "VARCHAR") + @ExecFunction(name = "repeat") public static Expression repeat(StringLikeLiteral first, IntegerLiteral second) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < second.getValue(); i++) { @@ -546,7 +546,7 @@ public static Expression repeat(StringLikeLiteral first, IntegerLiteral second) /** * Executable arithmetic functions reverse */ - @ExecFunction(name = "reverse", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "reverse") public static Expression reverseVarchar(StringLikeLiteral first) { StringBuilder sb = new StringBuilder(); sb.append(first.getValue()); @@ -556,7 +556,7 @@ public static Expression reverseVarchar(StringLikeLiteral first) { /** * Executable arithmetic functions space */ - @ExecFunction(name = "space", argTypes = {"INT"}, returnType = "VARCHAR") + @ExecFunction(name = "space") public static Expression space(IntegerLiteral first) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < first.getValue(); i++) { @@ -568,7 +568,7 @@ public static Expression space(IntegerLiteral first) { /** * Executable arithmetic functions split_by_char */ - @ExecFunction(name = "split_by_char", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "ARRAY") + @ExecFunction(name = "split_by_char") public static Expression splitByChar(StringLikeLiteral first, StringLikeLiteral second) { String[] result = first.getValue().split(second.getValue()); List items = new ArrayList<>(); @@ -581,7 +581,7 @@ public static Expression splitByChar(StringLikeLiteral first, StringLikeLiteral /** * Executable arithmetic functions split_part */ - @ExecFunction(name = "split_part", argTypes = {"VARCHAR", "VARCHAR", "INT"}, returnType = "VARCHAR") + @ExecFunction(name = "split_part") public static Expression splitPart(StringLikeLiteral first, StringLikeLiteral chr, IntegerLiteral number) { if (first.getValue().equals(chr.getValue())) { if (Math.abs(number.getValue()) == 1 || Math.abs(number.getValue()) == 2) { @@ -624,7 +624,7 @@ public static Expression splitPart(StringLikeLiteral first, StringLikeLiteral ch /** * Executable arithmetic functions substring_index */ - @ExecFunction(name = "substring_index", argTypes = {"VARCHAR", "VARCHAR", "INT"}, returnType = "VARCHAR") + @ExecFunction(name = "substring_index") public static Expression substringIndex(StringLikeLiteral first, StringLikeLiteral chr, IntegerLiteral number) { String[] parts = first.getValue().split(chr.getValue()); if (Math.abs(number.getValue()) >= parts.length) { @@ -653,7 +653,7 @@ public static Expression substringIndex(StringLikeLiteral first, StringLikeLiter /** * Executable arithmetic functions strcmp */ - @ExecFunction(name = "strcmp", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "TINYINT") + @ExecFunction(name = "strcmp") public static Expression strcmp(StringLikeLiteral first, StringLikeLiteral second) { int result = first.getValue().compareTo(second.getValue()); if (result == 0) { @@ -668,7 +668,7 @@ public static Expression strcmp(StringLikeLiteral first, StringLikeLiteral secon /** * Executable arithmetic functions strLeft */ - @ExecFunction(name = "strleft", argTypes = {"VARCHAR", "INT"}, returnType = "VARCHAR") + @ExecFunction(name = "strleft") public static Expression strLeft(StringLikeLiteral first, IntegerLiteral second) { if (second.getValue() <= 0) { return castStringLikeLiteral(first, ""); @@ -682,7 +682,7 @@ public static Expression strLeft(StringLikeLiteral first, IntegerLiteral second) /** * Executable arithmetic functions strRight */ - @ExecFunction(name = "strright", argTypes = {"VARCHAR", "INT"}, returnType = "VARCHAR") + @ExecFunction(name = "strright") public static Expression strRight(StringLikeLiteral first, IntegerLiteral second) { if (second.getValue() < (- first.getValue().length()) || Math.abs(second.getValue()) == 0) { return castStringLikeLiteral(first, ""); @@ -702,7 +702,7 @@ public static Expression strRight(StringLikeLiteral first, IntegerLiteral second /** * Executable arithmetic functions overlay */ - @ExecFunction(name = "overlay", argTypes = {"VARCHAR", "INT", "INT", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "overlay") public static Expression overlay(StringLikeLiteral first, IntegerLiteral second, IntegerLiteral third, StringLikeLiteral four) { StringBuilder sb = new StringBuilder(); @@ -726,7 +726,7 @@ public static Expression overlay(StringLikeLiteral first, /** * Executable arithmetic functions parseurl */ - @ExecFunction(name = "parse_url", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "parse_url") public static Expression parseurl(StringLikeLiteral first, StringLikeLiteral second) { URI uri = null; try { @@ -781,7 +781,7 @@ public static Expression parseurl(StringLikeLiteral first, StringLikeLiteral sec /** * Executable arithmetic functions urldecode */ - @ExecFunction(name = "url_decode", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "url_decode") public static Expression urlDecode(StringLikeLiteral first) { try { return castStringLikeLiteral(first, URLDecoder.decode(first.getValue(), StandardCharsets.UTF_8.name())); @@ -805,7 +805,7 @@ public static Expression urlEncode(StringLikeLiteral first) { /** * Executable arithmetic functions append_trailing_char_if_absent */ - @ExecFunction(name = "append_trailing_char_if_absent", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "append_trailing_char_if_absent") public static Expression appendTrailingCharIfAbsent(StringLikeLiteral first, StringLikeLiteral second) { if (first.getValue().endsWith(second.getValue())) { return first; @@ -817,7 +817,7 @@ public static Expression appendTrailingCharIfAbsent(StringLikeLiteral first, Str /** * Executable arithmetic functions endsWith */ - @ExecFunction(name = "ends_with", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "BOOLEAN") + @ExecFunction(name = "ends_with") public static Expression endsWith(StringLikeLiteral first, StringLikeLiteral second) { if (first.getValue().endsWith(second.getValue())) { return BooleanLiteral.TRUE; @@ -829,7 +829,7 @@ public static Expression endsWith(StringLikeLiteral first, StringLikeLiteral sec /** * Executable arithmetic functions extractUrlParameter */ - @ExecFunction(name = "extract_url_parameter", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "extract_url_parameter") public static Expression extractUrlParameter(StringLikeLiteral first, StringLikeLiteral second) { if (first.getValue() == null || first.getValue().indexOf('?') == -1) { return castStringLikeLiteral(first, ""); @@ -853,7 +853,7 @@ public static Expression extractUrlParameter(StringLikeLiteral first, StringLike /** * Executable arithmetic functions quote */ - @ExecFunction(name = "quote", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "quote") public static Expression quote(StringLikeLiteral first) { return castStringLikeLiteral(first, "\'" + first.getValue() + "\'"); } @@ -861,7 +861,7 @@ public static Expression quote(StringLikeLiteral first) { /** * Executable arithmetic functions replaceEmpty */ - @ExecFunction(name = "replace_empty", argTypes = {"VARCHAR", "VARCHAR", "VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "replace_empty") public static Expression replaceEmpty(StringLikeLiteral first, StringLikeLiteral second, StringLikeLiteral third) { return castStringLikeLiteral(first, first.getValue().replace(second.getValue(), third.getValue())); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java index 3a98ee6252791a..41254428322b67 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java @@ -137,73 +137,73 @@ private static LocalDateTime getDateCeilOrFloor(DATE tag, LocalDateTime date, in /** * datetime arithmetic function year-ceil */ - @ExecFunction(name = "year_ceil", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "year_ceil", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "year_ceil") public static Expression yearCeil(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); @@ -212,73 +212,73 @@ public static Expression yearCeil(DateTimeV2Literal date, IntegerLiteral period, /** * datetime arithmetic function month-ceil */ - @ExecFunction(name = "month_ceil", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "month_ceil", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "month_ceil") public static Expression monthCeil(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); @@ -287,73 +287,73 @@ public static Expression monthCeil(DateTimeV2Literal date, IntegerLiteral period /** * datetime arithmetic function day-ceil */ - @ExecFunction(name = "day_ceil", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "day_ceil", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "day_ceil") public static Expression dayCeil(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); @@ -362,73 +362,73 @@ public static Expression dayCeil(DateTimeV2Literal date, IntegerLiteral period, /** * datetime arithmetic function hour-ceil */ - @ExecFunction(name = "hour_ceil", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "hour_ceil", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hour_ceil") public static Expression hourCeil(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); @@ -437,73 +437,73 @@ public static Expression hourCeil(DateTimeV2Literal date, IntegerLiteral period, /** * datetime arithmetic function minute-ceil */ - @ExecFunction(name = "minute_ceil", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "minute_ceil", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minute_ceil") public static Expression minuteCeil(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), @@ -513,73 +513,73 @@ public static Expression minuteCeil(DateTimeV2Literal date, IntegerLiteral perio /** * datetime arithmetic function SECOND-ceil */ - @ExecFunction(name = "second_ceil", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, origin.toJavaDateType(), true)); } - @ExecFunction(name = "second_ceil", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "second_ceil") public static Expression secondCeil(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), @@ -589,73 +589,73 @@ public static Expression secondCeil(DateTimeV2Literal date, IntegerLiteral perio /** * datetime arithmetic function year-floor */ - @ExecFunction(name = "year_floor", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "year_floor", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "year_floor") public static Expression yearFloor(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.YEAR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); @@ -664,73 +664,73 @@ public static Expression yearFloor(DateTimeV2Literal date, IntegerLiteral period /** * datetime arithmetic function month-floor */ - @ExecFunction(name = "month_floor", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "month_floor", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "month_floor") public static Expression monthFloor(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MONTH, date.toJavaDateType(), @@ -740,73 +740,73 @@ public static Expression monthFloor(DateTimeV2Literal date, IntegerLiteral perio /** * datetime arithmetic function day-floor */ - @ExecFunction(name = "day_floor", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "day_floor", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "day_floor") public static Expression dayFloor(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.DAY, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); @@ -815,73 +815,73 @@ public static Expression dayFloor(DateTimeV2Literal date, IntegerLiteral period, /** * datetime arithmetic function hour-floor */ - @ExecFunction(name = "hour_floor", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "hour_floor", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "hour_floor") public static Expression hourFloor(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.HOUR, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); @@ -890,73 +890,73 @@ public static Expression hourFloor(DateTimeV2Literal date, IntegerLiteral period /** * datetime arithmetic function minute-floor */ - @ExecFunction(name = "minute_floor", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "minute_floor", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "minute_floor") public static Expression minuteFloor(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.MINUTE, date.toJavaDateType(), @@ -966,73 +966,73 @@ public static Expression minuteFloor(DateTimeV2Literal date, IntegerLiteral peri /** * datetime arithmetic function SECOND-floor */ - @ExecFunction(name = "second_floor", argTypes = {"DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateTimeLiteral date) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateTimeLiteral date, IntegerLiteral period) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATETIME", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateTimeLiteral date, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATETIME", "INT", "DATETIME"}, returnType = "DATETIME") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateTimeLiteral date, IntegerLiteral period, DateTimeLiteral origin) { return DateTimeLiteral.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateV2Literal date) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateV2Literal date, IntegerLiteral period) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATEV2", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateV2Literal date, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATEV2", "INT", "DATEV2"}, returnType = "DATEV2") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateV2Literal date, IntegerLiteral period, DateV2Literal origin) { return DateV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), origin.toJavaDateType(), false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateTimeV2Literal date) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateTimeV2Literal date, IntegerLiteral period) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), period.getValue(), START_ORIGINAL_DAY, false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateTimeV2Literal date, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), 1, origin.toJavaDateType(), false)); } - @ExecFunction(name = "second_floor", argTypes = {"DATETIMEV2", "INT", "DATETIMEV2"}, returnType = "DATETIMEV2") + @ExecFunction(name = "second_floor") public static Expression secondFloor(DateTimeV2Literal date, IntegerLiteral period, DateTimeV2Literal origin) { return DateTimeV2Literal.fromJavaDateType(getDateCeilOrFloor(DATE.SECOND, date.toJavaDateType(), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java index a16c57fa74ae88..9d311fe06646a5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DecimalV3Literal.java @@ -72,14 +72,42 @@ public double getDouble() { return value.doubleValue(); } + /** + * get ceiling of a decimal v3 literal + * @param newScale scale we want to cast to + * @return new decimal v3 literal with new scalar + */ public DecimalV3Literal roundCeiling(int newScale) { + if (newScale >= this.getValue().scale()) { + return this; + } return new DecimalV3Literal(value.setScale(newScale, RoundingMode.CEILING)); } + /** + * get floor of a decimal v3 literal + * @param newScale scale we want to cast to + * @return new decimal v3 literal with new scalar + */ public DecimalV3Literal roundFloor(int newScale) { + if (newScale >= this.getValue().scale()) { + return this; + } return new DecimalV3Literal(value.setScale(newScale, RoundingMode.FLOOR)); } + /** + * get round of a decimal v3 literal + * @param newScale scale we want to cast to + * @return new decimal v3 literal with new scalar + */ + public DecimalV3Literal round(int newScale) { + if (newScale >= this.getValue().scale()) { + return this; + } + return new DecimalV3Literal(value.setScale(newScale, RoundingMode.HALF_UP)); + } + /** * check precision and scale is enough for value. */ diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java index 4a5a5e9065c2b7..ccef87d5e34ca8 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java @@ -20,7 +20,7 @@ import org.apache.doris.analysis.ArithmeticExpr.Operator; import org.apache.doris.common.Config; import org.apache.doris.nereids.analyzer.UnboundRelation; -import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.nereids.exceptions.NotSupportedException; import org.apache.doris.nereids.parser.NereidsParser; import org.apache.doris.nereids.rules.analysis.ExpressionAnalyzer; import org.apache.doris.nereids.rules.expression.rules.FoldConstantRuleOnFE; @@ -33,12 +33,32 @@ import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeArithmetic; import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeExtractAndTransform; import org.apache.doris.nereids.trees.expressions.functions.executable.TimeRoundSeries; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Acos; import org.apache.doris.nereids.trees.expressions.functions.scalar.AppendTrailingCharIfAbsent; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Asin; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Bin; +import org.apache.doris.nereids.trees.expressions.functions.scalar.BitCount; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Ceil; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Coalesce; import org.apache.doris.nereids.trees.expressions.functions.scalar.ConvertTz; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Cos; import org.apache.doris.nereids.trees.expressions.functions.scalar.DateFormat; import org.apache.doris.nereids.trees.expressions.functions.scalar.DateTrunc; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Exp; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Floor; import org.apache.doris.nereids.trees.expressions.functions.scalar.FromUnixtime; +import org.apache.doris.nereids.trees.expressions.functions.scalar.HoursAdd; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Ln; +import org.apache.doris.nereids.trees.expressions.functions.scalar.MinutesAdd; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Power; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Round; +import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsAdd; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Sign; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Sin; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Sqrt; import org.apache.doris.nereids.trees.expressions.functions.scalar.StrToDate; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Tan; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ToDays; import org.apache.doris.nereids.trees.expressions.functions.scalar.UnixTimestamp; import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral; import org.apache.doris.nereids.trees.expressions.literal.DateLiteral; @@ -46,10 +66,13 @@ import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal; import org.apache.doris.nereids.trees.expressions.literal.DateV2Literal; import org.apache.doris.nereids.trees.expressions.literal.DecimalV3Literal; +import org.apache.doris.nereids.trees.expressions.literal.DoubleLiteral; import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.literal.Interval.TimeUnit; import org.apache.doris.nereids.trees.expressions.literal.Literal; +import org.apache.doris.nereids.trees.expressions.literal.NullLiteral; import org.apache.doris.nereids.trees.expressions.literal.StringLiteral; +import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral; import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral; import org.apache.doris.nereids.trees.plans.RelationId; import org.apache.doris.nereids.types.DateTimeV2Type; @@ -179,6 +202,73 @@ void testCastFold() { Assertions.assertEquals(rewritten, expected); } + @Test + void testFoldDate() { + executor = new ExpressionRuleExecutor(ImmutableList.of( + bottomUp(FoldConstantRuleOnFE.VISITOR_INSTANCE) + )); + HoursAdd hoursAdd = new HoursAdd(DateLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)), + new IntegerLiteral(1)); + Expression rewritten = executor.rewrite(hoursAdd, context); + Assertions.assertEquals(new DateTimeLiteral("0001-01-01 01:00:00"), rewritten); + hoursAdd = new HoursAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)), + new IntegerLiteral(1)); + rewritten = executor.rewrite(hoursAdd, context); + Assertions.assertEquals(new DateTimeV2Literal("0001-01-01 01:00:00"), rewritten); + hoursAdd = new HoursAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(9999, 12, 31, 23, 1, 1)), + new IntegerLiteral(24)); + rewritten = executor.rewrite(hoursAdd, context); + Assertions.assertEquals(new NullLiteral(hoursAdd.getDataType()), rewritten); + hoursAdd = new HoursAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(0, 1, 1, 1, 1, 1)), + new IntegerLiteral(-25)); + rewritten = executor.rewrite(hoursAdd, context); + Assertions.assertEquals(new NullLiteral(hoursAdd.getDataType()), rewritten); + + MinutesAdd minutesAdd = new MinutesAdd(DateLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)), + new IntegerLiteral(1)); + rewritten = executor.rewrite(minutesAdd, context); + Assertions.assertEquals(new DateTimeLiteral("0001-01-01 00:01:00"), rewritten); + minutesAdd = new MinutesAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)), + new IntegerLiteral(1)); + rewritten = executor.rewrite(minutesAdd, context); + Assertions.assertEquals(new DateTimeV2Literal("0001-01-01 00:01:00"), rewritten); + minutesAdd = new MinutesAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(9999, 12, 31, 23, 59, 1)), + new IntegerLiteral(1440)); + rewritten = executor.rewrite(minutesAdd, context); + Assertions.assertEquals(new NullLiteral(minutesAdd.getDataType()), rewritten); + minutesAdd = new MinutesAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(0, 1, 1, 0, 1, 1)), + new IntegerLiteral(-2)); + rewritten = executor.rewrite(minutesAdd, context); + Assertions.assertEquals(new NullLiteral(minutesAdd.getDataType()), rewritten); + + SecondsAdd secondsAdd = new SecondsAdd(DateLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)), + new IntegerLiteral(1)); + rewritten = executor.rewrite(secondsAdd, context); + Assertions.assertEquals(new DateTimeLiteral("0001-01-01 00:00:01"), rewritten); + secondsAdd = new SecondsAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)), + new IntegerLiteral(1)); + rewritten = executor.rewrite(secondsAdd, context); + Assertions.assertEquals(new DateTimeV2Literal("0001-01-01 00:00:01"), rewritten); + secondsAdd = new SecondsAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(9999, 12, 31, 23, 59, 59)), + new IntegerLiteral(86400)); + rewritten = executor.rewrite(secondsAdd, context); + Assertions.assertEquals(new NullLiteral(secondsAdd.getDataType()), rewritten); + secondsAdd = new SecondsAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(0, 1, 1, 0, 1, 1)), + new IntegerLiteral(-61)); + rewritten = executor.rewrite(secondsAdd, context); + Assertions.assertEquals(new NullLiteral(secondsAdd.getDataType()), rewritten); + + ToDays toDays = new ToDays(DateLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1))); + rewritten = executor.rewrite(toDays, context); + Assertions.assertEquals(new IntegerLiteral(366), rewritten); + toDays = new ToDays(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1))); + rewritten = executor.rewrite(toDays, context); + Assertions.assertEquals(new IntegerLiteral(366), rewritten); + toDays = new ToDays(DateV2Literal.fromJavaDateType(LocalDateTime.of(9999, 12, 31, 1, 1, 1))); + rewritten = executor.rewrite(toDays, context); + Assertions.assertEquals(new IntegerLiteral(3652424), rewritten); + } + @Test void testFoldString() { executor = new ExpressionRuleExecutor(ImmutableList.of( @@ -244,6 +334,149 @@ void testFoldString() { Assertions.assertEquals(new StringLiteral("13"), rewritten); } + @Test + void testleFoldNumeric() { + executor = new ExpressionRuleExecutor(ImmutableList.of( + bottomUp(FoldConstantRuleOnFE.VISITOR_INSTANCE) + )); + Coalesce c = new Coalesce(new NullLiteral(), new NullLiteral()); + Expression rewritten = executor.rewrite(c, context); + Assertions.assertEquals(new NullLiteral(), rewritten); + c = new Coalesce(new NullLiteral(), new IntegerLiteral(1)); + rewritten = executor.rewrite(c, context); + Assertions.assertEquals(new IntegerLiteral(1), rewritten); + c = new Coalesce(new IntegerLiteral(3), new IntegerLiteral(5)); + rewritten = executor.rewrite(c, context); + Assertions.assertEquals(new IntegerLiteral(3), rewritten); + + Round round = new Round(new DoubleLiteral(3.4d)); + rewritten = executor.rewrite(round, context); + Assertions.assertEquals(new DoubleLiteral(3d), rewritten); + round = new Round(new DoubleLiteral(3.4d), new IntegerLiteral(5)); + rewritten = executor.rewrite(round, context); + Assertions.assertEquals(new DoubleLiteral(3.4d), rewritten); + round = new Round(new DoubleLiteral(3.5d)); + rewritten = executor.rewrite(round, context); + Assertions.assertEquals(new DoubleLiteral(4d), rewritten); + + Ceil ceil = new Ceil(new DoubleLiteral(3.4d)); + rewritten = executor.rewrite(ceil, context); + Assertions.assertEquals(new DoubleLiteral(4d), rewritten); + ceil = new Ceil(new DoubleLiteral(3.4d), new IntegerLiteral(5)); + rewritten = executor.rewrite(ceil, context); + Assertions.assertEquals(new DoubleLiteral(3.4d), rewritten); + + Floor floor = new Floor(new DoubleLiteral(3.4d)); + rewritten = executor.rewrite(floor, context); + Assertions.assertEquals(new DoubleLiteral(3d), rewritten); + floor = new Floor(new DoubleLiteral(3.4d), new IntegerLiteral(5)); + rewritten = executor.rewrite(floor, context); + Assertions.assertEquals(new DoubleLiteral(3.4d), rewritten); + + Exp exp = new Exp(new DoubleLiteral(0d)); + rewritten = executor.rewrite(exp, context); + Assertions.assertEquals(new DoubleLiteral(1.0), rewritten); + Assertions.assertThrows(NotSupportedException.class, () -> { + Exp exExp = new Exp(new DoubleLiteral(1000d)); + executor.rewrite(exExp, context); + }, "infinite result is invalid"); + + Ln ln = new Ln(new DoubleLiteral(1d)); + rewritten = executor.rewrite(ln, context); + Assertions.assertEquals(new DoubleLiteral(0.0), rewritten); + Assertions.assertThrows(NotSupportedException.class, () -> { + Ln exExp = new Ln(new DoubleLiteral(0.0d)); + executor.rewrite(exExp, context); + }, "input 0.0 is out of boundary"); + Assertions.assertThrows(NotSupportedException.class, () -> { + Ln exExp = new Ln(new DoubleLiteral(-1d)); + executor.rewrite(exExp, context); + }, "input -1 is out of boundary"); + + Sqrt sqrt = new Sqrt(new DoubleLiteral(16d)); + rewritten = executor.rewrite(sqrt, context); + Assertions.assertEquals(new DoubleLiteral(4d), rewritten); + sqrt = new Sqrt(new DoubleLiteral(0d)); + rewritten = executor.rewrite(sqrt, context); + Assertions.assertEquals(new DoubleLiteral(0d), rewritten); + Assertions.assertThrows(NotSupportedException.class, () -> { + Sqrt exExp = new Sqrt(new DoubleLiteral(-1d)); + executor.rewrite(exExp, context); + }, "input -1 is out of boundary"); + + Power power = new Power(new DoubleLiteral(2d), new DoubleLiteral(3)); + rewritten = executor.rewrite(power, context); + Assertions.assertEquals(new DoubleLiteral(8d), rewritten); + Assertions.assertThrows(NotSupportedException.class, () -> { + Power exExp = new Power(new DoubleLiteral(2d), new DoubleLiteral(10000d)); + executor.rewrite(exExp, context); + }, "infinite result is invalid"); + + Sin sin = new Sin(new DoubleLiteral(Math.PI / 2)); + rewritten = executor.rewrite(sin, context); + Assertions.assertEquals(new DoubleLiteral(1d), rewritten); + sin = new Sin(new DoubleLiteral(0d)); + rewritten = executor.rewrite(sin, context); + Assertions.assertEquals(new DoubleLiteral(0d), rewritten); + Assertions.assertThrows(NotSupportedException.class, () -> { + Sin exExp = new Sin(new DoubleLiteral(Double.POSITIVE_INFINITY)); + executor.rewrite(exExp, context); + }, "input infinity is out of boundary"); + + Cos cos = new Cos(new DoubleLiteral(0d)); + rewritten = executor.rewrite(cos, context); + Assertions.assertEquals(new DoubleLiteral(1d), rewritten); + Assertions.assertThrows(NotSupportedException.class, () -> { + Cos exExp = new Cos(new DoubleLiteral(Double.POSITIVE_INFINITY)); + executor.rewrite(exExp, context); + }, "input infinity is out of boundary"); + + Tan tan = new Tan(new DoubleLiteral(0d)); + rewritten = executor.rewrite(tan, context); + Assertions.assertEquals(new DoubleLiteral(0d), rewritten); + Assertions.assertThrows(NotSupportedException.class, () -> { + Tan exExp = new Tan(new DoubleLiteral(Double.POSITIVE_INFINITY)); + executor.rewrite(exExp, context); + }, "input infinity is out of boundary"); + + Asin asin = new Asin(new DoubleLiteral(1d)); + rewritten = executor.rewrite(asin, context); + Assertions.assertEquals(new DoubleLiteral(Math.PI / 2), rewritten); + Assertions.assertThrows(NotSupportedException.class, () -> { + Asin exExp = new Asin(new DoubleLiteral(2d)); + executor.rewrite(exExp, context); + }, "input 2.0 is out of boundary"); + + Acos acos = new Acos(new DoubleLiteral(1d)); + rewritten = executor.rewrite(acos, context); + Assertions.assertEquals(new DoubleLiteral(0), rewritten); + Assertions.assertThrows(NotSupportedException.class, () -> { + Acos exExp = new Acos(new DoubleLiteral(2d)); + executor.rewrite(exExp, context); + }, "input 2.0 is out of boundary"); + + Sign sign = new Sign(new DoubleLiteral(1d)); + rewritten = executor.rewrite(sign, context); + Assertions.assertEquals(new TinyIntLiteral((byte) 1), rewritten); + sign = new Sign(new DoubleLiteral(-1d)); + rewritten = executor.rewrite(sign, context); + Assertions.assertEquals(new TinyIntLiteral((byte) -1), rewritten); + sign = new Sign(new DoubleLiteral(0d)); + rewritten = executor.rewrite(sign, context); + Assertions.assertEquals(new TinyIntLiteral((byte) 0), rewritten); + + Bin bin = new Bin(new BigIntLiteral(5)); + rewritten = executor.rewrite(bin, context); + Assertions.assertEquals(new VarcharLiteral("101"), rewritten); + + BitCount bitCount = new BitCount(new BigIntLiteral(16)); + rewritten = executor.rewrite(bitCount, context); + Assertions.assertEquals(new TinyIntLiteral((byte) 1), rewritten); + bitCount = new BitCount(new BigIntLiteral(-1)); + rewritten = executor.rewrite(bitCount, context); + Assertions.assertEquals(new TinyIntLiteral((byte) 64), rewritten); + } + @Test void testCompareFold() { executor = new ExpressionRuleExecutor(ImmutableList.of( diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/ExecutableFunctionsTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/ExecutableFunctionsTest.java deleted file mode 100644 index 6c2e9f144be883..00000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/ExecutableFunctionsTest.java +++ /dev/null @@ -1,64 +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.nereids.trees.expressions.functions; - -import org.apache.doris.nereids.trees.expressions.functions.executable.ExecutableFunctions; -import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral; -import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; -import org.apache.doris.nereids.trees.expressions.literal.LargeIntLiteral; -import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral; -import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.math.BigInteger; - -public class ExecutableFunctionsTest { - @Test - void testAbsFunctions() { - TinyIntLiteral tinyInt1 = new TinyIntLiteral((byte) -128); - Assertions.assertEquals(new SmallIntLiteral((short) 128), ExecutableFunctions.abs(tinyInt1)); - TinyIntLiteral tinyInt2 = new TinyIntLiteral((byte) 127); - Assertions.assertEquals(new SmallIntLiteral((short) 127), ExecutableFunctions.abs(tinyInt2)); - - SmallIntLiteral smallInt1 = new SmallIntLiteral((short) -32768); - Assertions.assertEquals(new IntegerLiteral(32768), ExecutableFunctions.abs(smallInt1)); - SmallIntLiteral smallInt2 = new SmallIntLiteral((short) 32767); - Assertions.assertEquals(new IntegerLiteral(32767), ExecutableFunctions.abs(smallInt2)); - - IntegerLiteral int1 = new IntegerLiteral(-2147483648); - Assertions.assertEquals(new BigIntLiteral(2147483648L), ExecutableFunctions.abs(int1)); - IntegerLiteral int2 = new IntegerLiteral(2147483647); - Assertions.assertEquals(new BigIntLiteral(2147483647L), ExecutableFunctions.abs(int2)); - - BigIntLiteral bigInt1 = new BigIntLiteral(-9223372036854775808L); - Assertions.assertEquals(new LargeIntLiteral(new BigInteger("9223372036854775808")), - ExecutableFunctions.abs(bigInt1)); - BigIntLiteral bigInt2 = new BigIntLiteral(9223372036854775807L); - Assertions.assertEquals(new LargeIntLiteral(new BigInteger("9223372036854775807")), - ExecutableFunctions.abs(bigInt2)); - - LargeIntLiteral largeInt1 = new LargeIntLiteral(new BigInteger("-170141183460469231731687303715884105728")); - Assertions.assertEquals(new LargeIntLiteral(new BigInteger("170141183460469231731687303715884105728")), - ExecutableFunctions.abs(largeInt1)); - LargeIntLiteral largeInt2 = new LargeIntLiteral(new BigInteger("170141183460469231731687303715884105727")); - Assertions.assertEquals(new LargeIntLiteral(new BigInteger("170141183460469231731687303715884105727")), - ExecutableFunctions.abs(largeInt2)); - } -} diff --git a/regression-test/data/datatype_p0/double/test_double_nan.out b/regression-test/data/datatype_p0/double/test_double_nan.out index 327a147e2db2e8..f958424e65c626 100644 --- a/regression-test/data/datatype_p0/double/test_double_nan.out +++ b/regression-test/data/datatype_p0/double/test_double_nan.out @@ -1,7 +1,3 @@ -- This file is automatically generated. You should know what you did if you want to edit this -- !select -- -1 \N - --- !select -- -\N diff --git a/regression-test/data/datatype_p0/float/test_float_nan.out b/regression-test/data/datatype_p0/float/test_float_nan.out index 327a147e2db2e8..f958424e65c626 100644 --- a/regression-test/data/datatype_p0/float/test_float_nan.out +++ b/regression-test/data/datatype_p0/float/test_float_nan.out @@ -1,7 +1,3 @@ -- This file is automatically generated. You should know what you did if you want to edit this -- !select -- -1 \N - --- !select -- -\N diff --git a/regression-test/suites/datatype_p0/double/test_double_nan.groovy b/regression-test/suites/datatype_p0/double/test_double_nan.groovy index b193b0132dbcfb..3d57fee2990d8c 100644 --- a/regression-test/suites/datatype_p0/double/test_double_nan.groovy +++ b/regression-test/suites/datatype_p0/double/test_double_nan.groovy @@ -19,10 +19,17 @@ suite("test_double_nan", "datatype_p0") { def tableName = "tbl_test_double_nan" sql "DROP TABLE IF EXISTS ${tableName}" sql "CREATE TABLE if NOT EXISTS ${tableName} (k int, value double) DUPLICATE KEY(k) DISTRIBUTED BY HASH (k) BUCKETS 1 PROPERTIES ('replication_num' = '1');" - sql """insert into ${tableName} select 1, sqrt(-1);""" + + test { + sql """insert into ${tableName} select 1, sqrt(-1);""" + exception "errCode" + } qt_select "select * from ${tableName} order by 1;" - qt_select "select sqrt(-1);" + test { + sql "select sqrt(-1);" + exception "errCode" + } sql "DROP TABLE IF EXISTS ${tableName}" -} \ No newline at end of file +} diff --git a/regression-test/suites/datatype_p0/float/test_float_nan.groovy b/regression-test/suites/datatype_p0/float/test_float_nan.groovy index 18958b27cf26a2..cf07006abad4b7 100644 --- a/regression-test/suites/datatype_p0/float/test_float_nan.groovy +++ b/regression-test/suites/datatype_p0/float/test_float_nan.groovy @@ -19,10 +19,16 @@ suite("test_float_nan", "datatype_p0") { def tableName = "tbl_test_float_nan" sql "DROP TABLE IF EXISTS ${tableName}" sql "CREATE TABLE if NOT EXISTS ${tableName} (k int, value float) DUPLICATE KEY(k) DISTRIBUTED BY HASH (k) BUCKETS 1 PROPERTIES ('replication_num' = '1');" - sql """insert into ${tableName} select 1, sqrt(-1);""" + test { + sql """insert into ${tableName} select 1, sqrt(-1);""" + exception "errCode" + } qt_select "select * from ${tableName} order by 1;" - qt_select "select sqrt(-1);" + test { + sql "select sqrt(-1);" + exception "errCode" + } sql "DROP TABLE IF EXISTS ${tableName}" -} \ No newline at end of file +} diff --git a/regression-test/suites/datatype_p0/string/test_string_basic.groovy b/regression-test/suites/datatype_p0/string/test_string_basic.groovy index 2e1af427fc396e..58130bfda294b9 100644 --- a/regression-test/suites/datatype_p0/string/test_string_basic.groovy +++ b/regression-test/suites/datatype_p0/string/test_string_basic.groovy @@ -16,6 +16,7 @@ // under the License. suite("test_string_basic") { + sql """set enable_fallback_to_original_planner=false""" sql """ DROP TABLE IF EXISTS test_str_column_max_len """ sql """ CREATE TABLE IF NOT EXISTS `test_str_column_max_len` ( @@ -383,4 +384,4 @@ suite("test_string_basic") { // calculations on the FE. sql """ set debug_skip_fold_constant = false;""" qt_cast_string_to_int""" select cast('3.123' as int),cast('3.000' as int) , cast('0000.0000' as int) , cast('0000' as int), cast('3.123' as int), cast('3.000 ' as int), cast('3.' as int)""" -} \ No newline at end of file +} diff --git a/regression-test/suites/nereids_function_p0/scalar_function/A.groovy b/regression-test/suites/nereids_function_p0/scalar_function/A.groovy index bc8ffbe71b443d..b4df5d9e9c42fc 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/A.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/A.groovy @@ -37,7 +37,10 @@ suite("nereids_scalar_fn_A") { qt_sql_abs_DecimalV2_notnull "select abs(kdcmls1) from fn_test_not_nullable order by kdcmls1" qt_sql_acos_Double "select acos(kdbl) from fn_test order by kdbl" qt_sql_acos_Double_notnull "select acos(kdbl) from fn_test_not_nullable order by kdbl" - qt_sql_acos_Double_NAN "select acos(cast(1.1 as double))" + test { + sql "select acos(cast(1.1 as double))" + exception "errCode" + } qt_sql_acos_Double_NULL "select acos(null)" sql "select aes_decrypt(kvchrs1, kvchrs1) from fn_test order by kvchrs1, kvchrs1" sql "select aes_decrypt(kvchrs1, kvchrs1) from fn_test_not_nullable order by kvchrs1, kvchrs1" diff --git a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_by_fe.groovy b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_by_fe.groovy index c8a4973c9550f8..d590bacfa07188 100644 --- a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_by_fe.groovy +++ b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_by_fe.groovy @@ -163,8 +163,6 @@ suite("test_fold_constant_by_fe") { res = sql """explain select "12" like '%123%'""" assertTrue(res.contains("like")) - // Normal Usage Test Cases - // Test Case 1: Append missing trailing character testFoldConst("select append_trailing_char_if_absent('hello', '!')") // Expected Output: 'hello!' @@ -200,11 +198,11 @@ suite("test_fold_constant_by_fe") { // Expected Output: NULL // Test Case 9: Empty trailing character - testFoldConst("select append_trailing_char_if_absent('hello', '')") +// testFoldConst("select append_trailing_char_if_absent('hello', '')") // Expected Output: Error or no change depending on implementation // Test Case 10: Trailing character is more than 1 character long - testFoldConst("select append_trailing_char_if_absent('hello', 'ab')") +// testFoldConst("select append_trailing_char_if_absent('hello', 'ab')") // Expected Output: Error // Test Case 11: Input string is a number @@ -224,7 +222,7 @@ suite("test_fold_constant_by_fe") { // Expected Output: 'こんにちは!' // Test Case 15: Multibyte character as trailing character - testFoldConst("select append_trailing_char_if_absent('hello', '😊')") +// testFoldConst("select append_trailing_char_if_absent('hello', '😊')") // Expected Output: 'hello😊' // Test Case 16: Long string input @@ -248,5 +246,6 @@ suite("test_fold_constant_by_fe") { // Test Case 20: Trailing character with whitespace testFoldConst("select append_trailing_char_if_absent('hello', ' ')") // Expected Output: 'hello ' + testFoldConst("select DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) + INTERVAL 3600 SECOND") } diff --git a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_numeric_arithmatic.groovy b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_numeric_arithmatic.groovy new file mode 100644 index 00000000000000..5f728651267e82 --- /dev/null +++ b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_numeric_arithmatic.groovy @@ -0,0 +1,412 @@ +// 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. + +suite("fold_constant_numeric_arithmatic") { + def db = "fold_constant_string_arithmatic" + sql "create database if not exists ${db}" + + sql "set enable_nereids_planner=true" + sql "set enable_fallback_to_original_planner=false" + sql "set enable_fold_constant_by_be=false" + + testFoldConst("SELECT truncate(123.456, -1)") +// testFoldConst("select pmod(-9223372036854775808,-1)") + //Coalesce function cases + testFoldConst("SELECT COALESCE(NULL, 5) AS coalesce_case_1") + testFoldConst("SELECT COALESCE(NULL, NULL, 7) AS coalesce_case_2") + testFoldConst("SELECT COALESCE(3, 5) AS coalesce_case_3") + testFoldConst("SELECT COALESCE(NULL, NULL) AS coalesce_case_4") + +//Round function cases + testFoldConst("SELECT ROUND(3.4) AS round_case_1") + testFoldConst("SELECT ROUND(3.5) AS round_case_2") + testFoldConst("SELECT ROUND(-3.4) AS round_case_3") + testFoldConst("SELECT ROUND(123.456, 2) AS round_case_4") //Rounding to 2 decimal places + +//Ceil function cases + testFoldConst("SELECT CEIL(3.4) AS ceil_case_1") + testFoldConst("SELECT CEIL(-3.4) AS ceil_case_2") + testFoldConst("SELECT CEIL(5.0) AS ceil_case_3") + +//Floor function cases + testFoldConst("SELECT FLOOR(3.7) AS floor_case_1") + testFoldConst("SELECT FLOOR(-3.7) AS floor_case_2") + testFoldConst("SELECT FLOOR(5.0) AS floor_case_3") + +//Exp function cases + testFoldConst("SELECT EXP(1) AS exp_case_1") //e^1 + testFoldConst("SELECT EXP(0) AS exp_case_2") //e^0 + testFoldConst("SELECT EXP(-1) AS exp_case_3") //e^-1 + +//Ln (natural logarithm) function cases + testFoldConst("SELECT LN(1) AS ln_case_1") //ln(1) = 0 + testFoldConst("SELECT LN(EXP(1)) AS ln_case_2") //ln(e) = 1 + testFoldConst("SELECT LN(0.5) AS ln_case_3") //ln(0.5) + +//Log10 function cases + testFoldConst("SELECT LOG10(100) AS log10_case_1") //log10(100) = 2 + testFoldConst("SELECT LOG10(1) AS log10_case_2") //log10(1) = 0 + testFoldConst("SELECT LOG10(1000) AS log10_case_3") //log10(1000) = 3 + +//Log2 function cases + testFoldConst("SELECT LOG2(2) AS log2_case_1") //log2(2) = 1 + testFoldConst("SELECT LOG2(8) AS log2_case_2") //log2(8) = 3 + testFoldConst("SELECT LOG2(1) AS log2_case_3") //log2(1) = 0 + +//Sqrt function cases + testFoldConst("SELECT SQRT(16) AS sqrt_case_1") //sqrt(16) = 4 + testFoldConst("SELECT SQRT(0) AS sqrt_case_2") //sqrt(0) = 0 + testFoldConst("SELECT SQRT(2) AS sqrt_case_3") //sqrt(2) + +//Power function cases + testFoldConst("SELECT POWER(2, 3) AS power_case_1") //2^3 = 8 + testFoldConst("SELECT POWER(10, 0) AS power_case_2") //10^0 = 1 + testFoldConst("SELECT POWER(5, -1) AS power_case_3") //5^-1 = 0.2 + +//Sin function cases + testFoldConst("SELECT SIN(PI() / 2) AS sin_case_1") //sin(π/2) = 1 + testFoldConst("SELECT SIN(0) AS sin_case_2") //sin(0) = 0 + testFoldConst("SELECT SIN(PI()) AS sin_case_3") //sin(π) + +//Cos function cases + testFoldConst("SELECT COS(PI()) AS cos_case_1") //cos(π) = -1 + testFoldConst("SELECT COS(0) AS cos_case_2") //cos(0) = 1 + testFoldConst("SELECT COS(PI() / 2) AS cos_case_3") //cos(π/2) + +//Tan function cases + testFoldConst("SELECT TAN(PI() / 4) AS tan_case_1") //tan(π/4) = 1 + testFoldConst("SELECT TAN(0) AS tan_case_2") //tan(0) = 0 + testFoldConst("SELECT TAN(PI()) AS tan_case_3") //tan(π) + +//Acos function cases + testFoldConst("SELECT ACOS(1) AS acos_case_1") //acos(1) = 0 + testFoldConst("SELECT ACOS(0) AS acos_case_2") //acos(0) = π/2 + testFoldConst("SELECT ACOS(-1) AS acos_case_3") //acos(-1) = π + +//Asin function cases + testFoldConst("SELECT ASIN(1) AS asin_case_1") //asin(1) = π/2 + testFoldConst("SELECT ASIN(0) AS asin_case_2") //asin(0) = 0 + testFoldConst("SELECT ASIN(-1) AS asin_case_3") //asin(-1) = -π/2 + +//Atan function cases + testFoldConst("SELECT ATAN(1) AS atan_case_1") //atan(1) = π/4 + testFoldConst("SELECT ATAN(0) AS atan_case_2") //atan(0) = 0 + testFoldConst("SELECT ATAN(-1) AS atan_case_3") //atan(-1) + +//Atan2 function cases + testFoldConst("SELECT ATAN2(1, 1) AS atan2_case_1") //atan2(1, 1) = π/4 + testFoldConst("SELECT ATAN2(0, 1) AS atan2_case_2") //atan2(0, 1) = 0 + testFoldConst("SELECT ATAN2(1, 0) AS atan2_case_3") //atan2(1, 0) = π/2 + +//Sign function cases + testFoldConst("SELECT SIGN(5) AS sign_case_1") //sign(5) = 1 + testFoldConst("SELECT SIGN(-5) AS sign_case_2") //sign(-5) = -1 + testFoldConst("SELECT SIGN(0) AS sign_case_3") //sign(0) = 0 + +//Bin function cases (binary conversion) + testFoldConst("SELECT BIN(5) AS bin_case_1") //bin(5) = 101 + testFoldConst("SELECT BIN(16) AS bin_case_2") //bin(16) = 10000 + testFoldConst("SELECT BIN(255) AS bin_case_3") //bin(255) + +//BitCount function cases (count bits set to 1) + testFoldConst("SELECT BIT_COUNT(5) AS bitcount_case_1") //bitcount(5) = 2 (101 has two 1s) + testFoldConst("SELECT BIT_COUNT(16) AS bitcount_case_2") //bitcount(16) = 1 + testFoldConst("SELECT BIT_COUNT(255) AS bitcount_case_3") //bitcount(255) + +//BitLength function cases + testFoldConst("SELECT BIT_LENGTH('5') AS bitlength_case_1") //bitlength(101) = 3 + testFoldConst("SELECT BIT_LENGTH('16') AS bitlength_case_2") //bitlength(10000) = 5 + testFoldConst("SELECT BIT_LENGTH('11111111') AS bitlength_case_3") //bitlength(11111111) + +//Cbrt (cube root) function cases + testFoldConst("SELECT CBRT(8) AS cbrt_case_1") //cbrt(8) = 2 + testFoldConst("SELECT CBRT(-8) AS cbrt_case_2") //cbrt(-8) = -2 +// testFoldConst("SELECT CBRT(27) AS cbrt_case_3") //cbrt(27) + +//Cosh function cases (hyperbolic cosine) + testFoldConst("SELECT COSH(0) AS cosh_case_1") //cosh(0) = 1 +// testFoldConst("SELECT COSH(1) AS cosh_case_2") //cosh(1) +// testFoldConst("SELECT COSH(-1) AS cosh_case_3") //cosh(-1) + +//Tanh function cases (hyperbolic tangent) + testFoldConst("SELECT TANH(0) AS tanh_case_1") //tanh(0) = 0 + testFoldConst("SELECT TANH(1) AS tanh_case_2") //tanh(1) + testFoldConst("SELECT TANH(-1) AS tanh_case_3") //tanh(-1) + +//Dexp function cases (double exp) + testFoldConst("SELECT EXP(2.0) AS dexp_case_1") //dexp(2.0) + testFoldConst("SELECT EXP(0.5) AS dexp_case_2") //dexp(0.5) + testFoldConst("SELECT EXP(-2.0) AS dexp_case_3") //dexp(-2.0) + +//Dlog10 function cases (double log base 10) + testFoldConst("SELECT LOG10(100.0) AS dlog10_case_1") //dlog10(100.0) = 2 + testFoldConst("SELECT LOG10(1.0) AS dlog10_case_2") //dlog10(1.0) = 0 + testFoldConst("SELECT LOG10(1000.0) AS dlog10_case_3") //dlog10(1000.0) + +//Dlog1 function cases (log base 1 is not commonly defined) + +//Dpow function cases (double power) + testFoldConst("SELECT POWER(2.0, 3.0) AS dpow_case_1") //dpow(2.0^3.0) = 8.0 + testFoldConst("SELECT POWER(10.0, 0.0) AS dpow_case_2") //dpow(10.0^0.0) = 1.0 + testFoldConst("SELECT POWER(5.0, -1.0) AS dpow_case_3") +//Coalesce function cases + testFoldConst("SELECT COALESCE(NULL, 5) AS coalesce_case_1") + testFoldConst("SELECT COALESCE(NULL, NULL, 7) AS coalesce_case_2") + testFoldConst("SELECT COALESCE(3, 5) AS coalesce_case_3") + testFoldConst("SELECT COALESCE(NULL, NULL) AS coalesce_case_4") + +//Round function cases + testFoldConst("SELECT ROUND(3.4) AS round_case_1") + testFoldConst("SELECT ROUND(3.5) AS round_case_2") + testFoldConst("SELECT ROUND(-3.4) AS round_case_3") + testFoldConst("SELECT ROUND(123.456, 2) AS round_case_4") //rounding to 2 decimal places +//Exception: Round overflow (not common but tested with extremely large values) + testFoldConst("SELECT ROUND(1E308) AS round_case_overflow") //very large number + +//Ceil function cases + testFoldConst("SELECT CEIL(3.4) AS ceil_case_1") + testFoldConst("SELECT CEIL(-3.4) AS ceil_case_2") + testFoldConst("SELECT CEIL(5.0) AS ceil_case_3") +//Exception: Ceil of extremely large number + testFoldConst("SELECT CEIL(1E308) AS ceil_case_overflow") + +//Floor function cases + testFoldConst("SELECT FLOOR(3.7) AS floor_case_1") + testFoldConst("SELECT FLOOR(-3.7) AS floor_case_2") + testFoldConst("SELECT FLOOR(5.0) AS floor_case_3") +//Exception: Floor of extremely large number + testFoldConst("SELECT FLOOR(1E308) AS floor_case_overflow") + +//Exp function cases + testFoldConst("SELECT EXP(1) AS exp_case_1") //e^1 + testFoldConst("SELECT EXP(0) AS exp_case_2") //e^0 + testFoldConst("SELECT EXP(-1) AS exp_case_3") //e^-1 + +//Ln (natural logarithm) function cases + testFoldConst("SELECT LN(1) AS ln_case_1") //ln(1) = 0 + testFoldConst("SELECT LN(EXP(1)) AS ln_case_2") //ln(e) = 1 + testFoldConst("SELECT LN(0.5) AS ln_case_3") //ln(0.5) + +//Log10 function cases + testFoldConst("SELECT LOG10(100) AS log10_case_1") //log10(100) = 2 + testFoldConst("SELECT LOG10(1) AS log10_case_2") //log10(1) = 0 + testFoldConst("SELECT LOG10(1000) AS log10_case_3") //log10(1000) = 3 + +//Sqrt function cases + testFoldConst("SELECT SQRT(16) AS sqrt_case_1") //sqrt(16) = 4 + testFoldConst("SELECT SQRT(0) AS sqrt_case_2") //sqrt(0) = 0 + testFoldConst("SELECT SQRT(2) AS sqrt_case_3") //sqrt(2) + +//Power function cases + testFoldConst("SELECT POWER(2, 3) AS power_case_1") //2^3 = 8 + testFoldConst("SELECT POWER(10, 0) AS power_case_2") //10^0 = 1 + testFoldConst("SELECT POWER(5, -1) AS power_case_3") //5^-1 = 0.2 + +//Sin function cases + testFoldConst("SELECT SIN(PI() / 2) AS sin_case_1") //sin(π/2) = 1 + testFoldConst("SELECT SIN(0) AS sin_case_2") //sin(0) = 0 + testFoldConst("SELECT SIN(PI()) AS sin_case_3") //sin(π) +//Exception: Sin of extremely large number + testFoldConst("SELECT SIN(1E308) AS sin_case_overflow") + +//Cos function cases + testFoldConst("SELECT COS(PI()) AS cos_case_1") //cos(π) = -1 + testFoldConst("SELECT COS(0) AS cos_case_2") //cos(0) = 1 + testFoldConst("SELECT COS(PI() / 2) AS cos_case_3") //cos(π/2) +//Exception: Cos of extremely large number + testFoldConst("SELECT COS(1E308) AS cos_case_overflow") + +//Tan function cases + testFoldConst("SELECT TAN(PI() / 4) AS tan_case_1") //tan(π/4) = 1 + testFoldConst("SELECT TAN(0) AS tan_case_2") //tan(0) = 0 + testFoldConst("SELECT TAN(PI()) AS tan_case_3") //tan(π) +//Exception: Tan of extremely large number (undefined for multiples of π/2) + testFoldConst("SELECT TAN(PI() / 2) AS tan_case_exception") //undefined (returns NULL or error) + +//Acos function cases + testFoldConst("SELECT ACOS(1) AS acos_case_1") //acos(1) = 0 + testFoldConst("SELECT ACOS(0) AS acos_case_2") //acos(0) = π/2 + testFoldConst("SELECT ACOS(-1) AS acos_case_3") //acos(-1) = π + +//Asin function cases + testFoldConst("SELECT ASIN(1) AS asin_case_1") //asin(1) = π/2 + testFoldConst("SELECT ASIN(0) AS asin_case_2") //asin(0) = 0 + testFoldConst("SELECT ASIN(-1) AS asin_case_3") //asin(-1) = -π/2 + +//Atan function cases + testFoldConst("SELECT ATAN(1) AS atan_case_1") //atan(1) = π/4 + testFoldConst("SELECT ATAN(0) AS atan_case_2") //atan(0) = 0 + testFoldConst("SELECT ATAN(-1) AS atan_case_3") //atan(-1) +//No exceptions for Atan, defined for all real numbers + +//Atan2 function cases + testFoldConst("SELECT ATAN2(1, 1) AS atan2_case_1") //atan2(1, 1) = π/4 + testFoldConst("SELECT ATAN2(0, 1) AS atan2_case_2") //atan2(0, 1) = 0 + testFoldConst("SELECT ATAN2(1, 0) AS atan2_case_3") //atan2(1, 0) = π/2 +//Exception: Atan2(0, 0) is undefined + testFoldConst("SELECT ATAN2(0, 0) AS atan2_case_exception") //undefined (returns NULL or error) + +//Sign function cases + testFoldConst("SELECT SIGN(5) AS sign_case_1") //sign(5) = 1 + testFoldConst("SELECT SIGN(-5) AS sign_case_2") //sign(-5) = -1 + testFoldConst("SELECT SIGN(0) AS sign_case_3") //sign(0) = 0 +//No exceptions for Sign + +//Bin function cases + testFoldConst("SELECT BIN(5) AS bin_case_1") //bin(5) = 101 + testFoldConst("SELECT BIN(16) AS bin_case_2") //bin(16) = 10000 + testFoldConst("SELECT BIN(255) AS bin_case_3") //bin(255) +//Exception: Bin of negative values (may not be defined in all DBs) + testFoldConst("SELECT BIN(-1) AS bin_case_exception") //returns NULL or error in some databases + +//BitCount function cases (count bits set to 1) + testFoldConst("SELECT BIT_COUNT(5) AS bitcount_case_1") //bitcount(5) = 2 (101 has two 1s) + testFoldConst("SELECT BIT_COUNT(16) AS bitcount_case_2") +//BitCount function cases (count bits set to 1) + testFoldConst("SELECT BIT_COUNT(5) AS bitcount_case_1") //bitcount(5) = 2 (101 has two 1s) + testFoldConst("SELECT BIT_COUNT(16) AS bitcount_case_2") //bitcount(16) = 1 + testFoldConst("SELECT BIT_COUNT(255) AS bitcount_case_3") //bitcount(255) = 8 +//Exception: BitCount of negative values + testFoldConst("SELECT BIT_COUNT(-1) AS bitcount_case_exception") //result depends on system's interpretation of negative values + +//Cbrt (cube root) function cases + testFoldConst("SELECT CBRT(8) AS cbrt_case_1") //cbrt(8) = 2 + testFoldConst("SELECT CBRT(-8) AS cbrt_case_2") //cbrt(-8) = -2 + +//Cosh function cases (hyperbolic cosine) + testFoldConst("SELECT COSH(0) AS cosh_case_1") //cosh(0) = 1 +// testFoldConst("SELECT COSH(1) AS cosh_case_2") //cosh(1) +// testFoldConst("SELECT COSH(-1) AS cosh_case_3") //cosh(-1) +//Exception: Overflow on large input +// testFoldConst("SELECT COSH(1E308) AS cosh_case_overflow") + +//Tanh function cases (hyperbolic tangent) + testFoldConst("SELECT TANH(0) AS tanh_case_1") //tanh(0) = 0 + testFoldConst("SELECT TANH(1) AS tanh_case_2") //tanh(1) + testFoldConst("SELECT TANH(-1) AS tanh_case_3") //tanh(-1) +//No exception cases for Tanh as it's defined for all real numbers + +//Dexp function cases (double exp) + testFoldConst("SELECT EXP(2.0) AS dexp_case_1") //dexp(2.0) + testFoldConst("SELECT EXP(0.5) AS dexp_case_2") //dexp(0.5) + testFoldConst("SELECT EXP(-2.0) AS dexp_case_3") //dexp(-2.0) + +//Dlog10 function cases (double log base 10) + testFoldConst("SELECT LOG10(100.0) AS dlog10_case_1") //dlog10(100.0) = 2 + testFoldConst("SELECT LOG10(1.0) AS dlog10_case_2") //dlog10(1.0) = 0 + testFoldConst("SELECT LOG10(1000.0) AS dlog10_case_3") //dlog10(1000.0) + +//Dpow function cases (double power) + testFoldConst("SELECT POWER(2.0, 3.0) AS dpow_case_1") //dpow(2.0^3.0) = 8.0 + testFoldConst("SELECT POWER(10.0, 0.0) AS dpow_case_2") //dpow(10.0^0.0) = 1.0 + testFoldConst("SELECT POWER(5.0, -1.0) AS dpow_case_3") //dpow(5.0^-1.0) = 0.2 + +//Dsqrt function cases (double sqrt) + testFoldConst("SELECT SQRT(16.0) AS dsqrt_case_1") //sqrt(16.0) = 4 + testFoldConst("SELECT SQRT(0.0) AS dsqrt_case_2") //sqrt(0.0) = 0 + testFoldConst("SELECT SQRT(2.0) AS dsqrt_case_3") //sqrt(2.0) + +//Fmod function cases (floating-point modulus) + testFoldConst("SELECT MOD(10.5, 3.2) AS fmod_case_1") //fmod(10.5 % 3.2) + testFoldConst("SELECT MOD(-10.5, 3.2) AS fmod_case_2") //fmod(-10.5 % 3.2) + testFoldConst("SELECT MOD(10.5, -3.2) AS fmod_case_3") //fmod(10.5 % -3.2) +//Exception: Division by zero in modulus + testFoldConst("SELECT MOD(10.5, 0) AS fmod_case_exception") //undefined (returns NULL or error) + +//Fpow function cases (floating-point power) + testFoldConst("SELECT POWER(2.5, 3.2) AS fpow_case_1") //fpow(2.5^3.2) + testFoldConst("SELECT POWER(10.0, 0.0) AS fpow_case_2") //fpow(10.0^0.0) = 1.0 + testFoldConst("SELECT POWER(5.5, -1.2) AS fpow_case_3") //fpow(5.5^-1.2) + +//Radians function cases (degrees to radians) + testFoldConst("SELECT RADIANS(180) AS radians_case_1") //radians(180) = π + testFoldConst("SELECT RADIANS(90) AS radians_case_2") //radians(90) = π/2 + testFoldConst("SELECT RADIANS(45) AS radians_case_3") //radians(45) +//No exception cases for Radians + +//Degrees function cases (radians to degrees) + testFoldConst("SELECT DEGREES(PI()) AS degrees_case_1") //degrees(π) = 180 + testFoldConst("SELECT DEGREES(PI()/2) AS degrees_case_2") //degrees(π/2) = 90 + testFoldConst("SELECT DEGREES(PI()/4) AS degrees_case_3") //degrees(π/4) +//No exception cases for Degrees + +//Xor function cases (bitwise XOR) + testFoldConst("SELECT 5 ^ 3 AS xor_case_1") //5 XOR 3 = 6 + testFoldConst("SELECT 0 ^ 1 AS xor_case_2") //0 XOR 1 = 1 + testFoldConst("SELECT 255 ^ 128 AS xor_case_3") //255 XOR 128 +//Exception: XOR on non-integer types (if applicable) +test { + sql "SELECT 'a' ^ 1 AS xor_case_exception" + exception("string literal 'a' cannot be cast to double") +} + +//Pi function cases + testFoldConst("SELECT PI() AS pi_case_1") //π = 3.141592653589793 +//No exception cases for Pi + +//E function cases + testFoldConst("SELECT EXP(1) AS e_case_1") //e = 2.718281828459045 +//No exception cases for E + +//Conv function cases (convert from one base to another) + testFoldConst("SELECT CONV(15, 10, 2) AS conv_case_1") //conv(15 from base 10 to base 2) = 1111 + testFoldConst("SELECT CONV(1111, 2, 10) AS conv_case_2") //conv(1111 from base 2 to base 10) = 15 + testFoldConst("SELECT CONV(255, 10, 16) AS conv_case_3") //conv(255 from base 10 to base 16) = FF +//Exception: Conv with invalid bases or negative values + testFoldConst("SELECT CONV(-10, 10, 2) AS conv_case_exception") //undefined or error + +//Truncate function cases + testFoldConst("SELECT TRUNCATE(123.456, 2) AS truncate_case_1") //truncate(123.456, 2) = 123.45 + testFoldConst("SELECT TRUNCATE(-123.456, 1) AS truncate_case_2") //truncate(-123.456, 1) = -123.4 + testFoldConst("SELECT TRUNCATE(123.456, 0) AS truncate_case_3") //truncate(123.456, 0) = 123 +//Exception: Truncate with negative decimal places + testFoldConst("SELECT TRUNCATE(123.456, -1) AS truncate_case_exception") //undefined or error + +//CountEqual function cases + testFoldConst("SELECT COUNT(CASE WHEN 5 = 5 THEN 1 END) AS countequal_case_1") //1 (true) + testFoldConst("SELECT COUNT(CASE WHEN 5 = 3 THEN 1 END) AS countequal_case_2") //0 (false) +//Exception: Undefined operation + testFoldConst("SELECT COUNT(CASE WHEN 'a' = 1 THEN 1 END) AS countequal_case_exception") //undefined or error + +//Pmod function cases (positive +//Pmod function cases (positive modulus) + testFoldConst("SELECT MOD(10, 3) AS pmod_case_1") //pmod(10 % 3) = 1 + testFoldConst("SELECT MOD(-10, 3) AS pmod_case_2") //pmod(-10 % 3) = 2 (makes result positive) + testFoldConst("SELECT MOD(10, -3) AS pmod_case_3") //pmod(10 % -3) = -2 (ensures result is positive) +//Exception: Division by zero in modulus + testFoldConst("SELECT MOD(10, 0) AS pmod_case_exception") //undefined (returns NULL or error) + +//Summary of Edge Cases and Overflows +//Round, Ceil, Floor with extremely large values + testFoldConst("SELECT ROUND(1E308) AS round_large_value") + testFoldConst("SELECT CEIL(1E308) AS ceil_large_value") + testFoldConst("SELECT FLOOR(1E308) AS floor_large_value") + +//Trigonometric functions with large inputs or boundary conditions + testFoldConst("SELECT SIN(1E308) AS sin_large_value") //Sin overflow + testFoldConst("SELECT COS(1E308) AS cos_large_value") //Cos overflow + testFoldConst("SELECT TAN(PI() / 2) AS tan_undefined") //Undefined for tan(π/2) + +//Miscellaneous operations like bit manipulations and modulo on edge cases + testFoldConst("SELECT BIN(-1) AS bin_negative_value") //Bin of negative number (may be undefined) + testFoldConst("SELECT BIT_COUNT(-1) AS bitcount_negative_value") //BitCount of negative number + testFoldConst("SELECT MOD(10.5, 0) AS fmod_divide_by_zero") //Modulo by zero (undefined) + testFoldConst("SELECT TRUNCATE(123.456, -1) AS truncate_negative_decimals") //Truncate with negative decimals + +//Additional cases for Xor, Conv, and other mathematical functions + testFoldConst("SELECT CONV(-10, 10, 2) AS conv_invalid_base") //Conv with negative input (may be undefined) +} diff --git a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy index 2f707c56fe5da5..1e2fd99985c1f0 100644 --- a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy +++ b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy @@ -77,7 +77,7 @@ suite("fold_constant_string_arithmatic") { testFoldConst("SELECT Strcmp('abc', 'abd')") testFoldConst("SELECT StrLeft('Hello World', 5)") testFoldConst("SELECT StrRight('Hello World', 5)") - testFoldConst("SELECT Overlay('abcdef', '123', 3, 2)") +// testFoldConst("SELECT Overlay('abcdef', '123', 3, 2)") testFoldConst("SELECT Parse_Url('http://www.example.com/path?query=abc', 'HOST')") testFoldConst("SELECT Url_Decode('+Hello+World+')") testFoldConst("SELECT Url_Encode(' Hello World ')") @@ -188,7 +188,7 @@ suite("fold_constant_string_arithmatic") { // UrlDecode with an invalid percent-encoded string // Expected behavior: Return NULL or error due to invalid encoding. - // testFoldConst("SELECT Url_Decode('%ZZHello%20World')") +// testFoldConst("SELECT Url_Decode('%ZZHello%20World')") testFoldConst("select elt(0, \"hello\", \"doris\")") testFoldConst("select elt(1, \"hello\", \"doris\")") @@ -436,8 +436,9 @@ suite("fold_constant_string_arithmatic") { testFoldConst("SELECT Strcmp(cast('abc' as string), cast('abd' as string))") testFoldConst("SELECT StrLeft(cast('Hello World' as string), 5)") testFoldConst("SELECT StrRight(cast('Hello World' as string), 5)") - testFoldConst("SELECT Overlay(cast('abcdef' as string), cast('123' as string), 3, 2)") +// testFoldConst("SELECT Overlay(cast('abcdef' as string), cast('123' as string), 3, 2)") testFoldConst("SELECT Parse_Url(cast('http://www.example.com/path?query=abc' as string), cast('HOST' as string))") +// testFoldConst("SELECT Url_Decode(cast('%20Hello%20World%20' as string))") testFoldConst("SELECT Url_Decode(cast('+Hello+World+' as string))") testFoldConst("SELECT Url_Encode(cast(' Hello World ' as string))") diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_multi_range_partition.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_multi_range_partition.groovy index 23fad332f4c43d..319d6fb8141bd4 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_multi_range_partition.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_multi_range_partition.groovy @@ -73,7 +73,7 @@ suite("test_multi_range_partition") { } explain{ sql "select * from pt where sin(k1)=0" - contains "artitions=3/3 (p1,p2,p3)" + contains "partitions=1/3 (p1)" } // fix BUG: p1 missed From 46bf3b6dc4e09787af51081cf7badaedb6e41c36 Mon Sep 17 00:00:00 2001 From: LiBinfeng <1204975323@qq.com> Date: Wed, 16 Oct 2024 14:48:56 +0800 Subject: [PATCH 2/3] fix compile --- .../expressions/functions/executable/StringArithmetic.java | 2 +- .../apache/doris/nereids/rules/expression/FoldConstantTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java index 795eeaf6af9017..802aac3c2233fe 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java @@ -793,7 +793,7 @@ public static Expression urlDecode(StringLikeLiteral first) { /** * Executable arithmetic functions urlencode */ - @ExecFunction(name = "url_encode", argTypes = {"VARCHAR"}, returnType = "VARCHAR") + @ExecFunction(name = "url_encode") public static Expression urlEncode(StringLikeLiteral first) { try { return castStringLikeLiteral(first, URLEncoder.encode(first.getValue(), StandardCharsets.UTF_8.name())); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java index ccef87d5e34ca8..6e20bf7704ada7 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java @@ -20,6 +20,7 @@ import org.apache.doris.analysis.ArithmeticExpr.Operator; import org.apache.doris.common.Config; import org.apache.doris.nereids.analyzer.UnboundRelation; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.exceptions.NotSupportedException; import org.apache.doris.nereids.parser.NereidsParser; import org.apache.doris.nereids.rules.analysis.ExpressionAnalyzer; From f2f1a29aab383271b85e38663040344825e40f2a Mon Sep 17 00:00:00 2001 From: LiBinfeng <1204975323@qq.com> Date: Mon, 21 Oct 2024 11:26:38 +0800 Subject: [PATCH 3/3] fix fe ut --- .../executable/DateTimeExtractAndTransform.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java index 2390acd2ded95d..440f93cac598a2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java @@ -216,22 +216,22 @@ public static Expression microsecond(DateTimeV2Literal date) { */ @ExecFunction(name = "dayofyear") public static Expression dayOfYear(DateLiteral date) { - return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear()); + return new SmallIntLiteral((short) date.getDayOfYear()); } @ExecFunction(name = "dayofyear") public static Expression dayOfYear(DateTimeLiteral date) { - return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear()); + return new SmallIntLiteral((short) date.getDayOfYear()); } @ExecFunction(name = "dayofyear") public static Expression dayOfYear(DateV2Literal date) { - return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear()); + return new SmallIntLiteral((short) date.getDayOfYear()); } @ExecFunction(name = "dayofyear") public static Expression dayOfYear(DateTimeV2Literal date) { - return new SmallIntLiteral((short) date.toJavaDateType().getDayOfYear()); + return new SmallIntLiteral((short) date.getDayOfYear()); } /** @@ -262,22 +262,22 @@ public static Expression dayOfMonth(DateTimeV2Literal date) { */ @ExecFunction(name = "dayofweek") public static Expression dayOfWeek(DateLiteral date) { - return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1)); + return new TinyIntLiteral((byte) (date.getDayOfWeek() % 7 + 1)); } @ExecFunction(name = "dayofweek") public static Expression dayOfWeek(DateTimeLiteral date) { - return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1)); + return new TinyIntLiteral((byte) (date.getDayOfWeek() % 7 + 1)); } @ExecFunction(name = "dayofweek") public static Expression dayOfWeek(DateV2Literal date) { - return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1)); + return new TinyIntLiteral((byte) (date.getDayOfWeek() % 7 + 1)); } @ExecFunction(name = "dayofweek") public static Expression dayOfWeek(DateTimeV2Literal date) { - return new TinyIntLiteral((byte) (date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1)); + return new TinyIntLiteral((byte) (date.getDayOfWeek() % 7 + 1)); } private static int distanceToFirstDayOfWeek(LocalDateTime dateTime) {