This is an automated email from the ASF dual-hosted git repository. lihaopeng pushed a commit to branch vectorized in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
commit acb63c749cff8b323cf9efca8cf47ddb171aecd0 Author: Pxl <952130...@qq.com> AuthorDate: Mon Jan 10 10:52:44 2022 +0800 [Vectorized] [Function] Support do not fold constant at vectorized (#7668) --- .../org/apache/doris/analysis/ArithmeticExpr.java | 30 ++++++++++ .../java/org/apache/doris/rewrite/FEFunctions.java | 64 ++++++++++++++++++++-- 2 files changed, 88 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java index 50012b7..79a1ffa 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java @@ -267,6 +267,33 @@ public class ArithmeticExpr extends Expr { } } + private boolean castIfHaveSameType(Type t1, Type t2, Type target) throws AnalysisException { + if (t1 == target || t2 == target) { + castChild(target, 0); + castChild(target, 1); + return true; + } + return false; + } + + private void castUpperInteger(Type t1, Type t2) throws AnalysisException { + if (!t1.isIntegerType() || !t2.isIntegerType()) { + return; + } + if (castIfHaveSameType(t1, t2, Type.BIGINT)) { + return; + } + if (castIfHaveSameType(t1, t2, Type.INT)) { + return; + } + if (castIfHaveSameType(t1, t2, Type.SMALLINT)) { + return; + } + if (castIfHaveSameType(t1, t2, Type.TINYINT)) { + return; + } + } + @Override public void analyzeImpl(Analyzer analyzer) throws AnalysisException { if (VectorizedUtil.isVectorized()) { @@ -320,6 +347,9 @@ public class ArithmeticExpr extends Expr { if (t1.isDecimalV2() || t2.isDecimalV2()) { castBinaryOp(findCommonType(t1, t2)); } + if (isConstant()) { + castUpperInteger(t1, t2); + } case MOD: if (t1.isDecimalV2() || t2.isDecimalV2()) { castBinaryOp(findCommonType(t1, t2)); diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java index 26ca3f7..0bcbfb6 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java +++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java @@ -350,12 +350,30 @@ public class FEFunctions { * Arithmetic function */ - @FEFunction(name = "add", argTypes = { "BIGINT", "BIGINT" }, returnType = "BIGINT") + @FEFunction(name = "add", argTypes = { "TINYINT", "TINYINT" }, returnType = "SMALLINT") + public static IntLiteral addTinyint(LiteralExpr first, LiteralExpr second) throws AnalysisException { + long result = Math.addExact(first.getLongValue(), second.getLongValue()); + return new IntLiteral(result, Type.SMALLINT); + } + + @FEFunction(name = "add", argTypes = { "SMALLINT", "SMALLINT" }, returnType = "INT") + public static IntLiteral addSmallint(LiteralExpr first, LiteralExpr second) throws AnalysisException { + long result = Math.addExact(first.getLongValue(), second.getLongValue()); + return new IntLiteral(result, Type.INT); + } + + @FEFunction(name = "add", argTypes = { "INT", "INT" }, returnType = "BIGINT") public static IntLiteral addInt(LiteralExpr first, LiteralExpr second) throws AnalysisException { long result = Math.addExact(first.getLongValue(), second.getLongValue()); return new IntLiteral(result, Type.BIGINT); } + @FEFunction(name = "add", argTypes = { "BIGINT", "BIGINT" }, returnType = "BIGINT") + public static IntLiteral addBigint(LiteralExpr first, LiteralExpr second) throws AnalysisException { + long result = Math.addExact(first.getLongValue(), second.getLongValue()); + return new IntLiteral(result, Type.BIGINT); + } + @FEFunction(name = "add", argTypes = { "DOUBLE", "DOUBLE" }, returnType = "DOUBLE") public static FloatLiteral addDouble(LiteralExpr first, LiteralExpr second) throws AnalysisException { double result = first.getDoubleValue() + second.getDoubleValue(); @@ -379,12 +397,30 @@ public class FEFunctions { return new LargeIntLiteral(result.toString()); } - @FEFunction(name = "subtract", argTypes = { "BIGINT", "BIGINT" }, returnType = "BIGINT") + @FEFunction(name = "subtract", argTypes = { "TINYINT", "TINYINT" }, returnType = "SMALLINT") + public static IntLiteral subtractTinyint(LiteralExpr first, LiteralExpr second) throws AnalysisException { + long result = Math.subtractExact(first.getLongValue(), second.getLongValue()); + return new IntLiteral(result, Type.SMALLINT); + } + + @FEFunction(name = "subtract", argTypes = { "SMALLINT", "SMALLINT" }, returnType = "INT") + public static IntLiteral subtractSmallint(LiteralExpr first, LiteralExpr second) throws AnalysisException { + long result = Math.subtractExact(first.getLongValue(), second.getLongValue()); + return new IntLiteral(result, Type.INT); + } + + @FEFunction(name = "subtract", argTypes = { "INT", "INT" }, returnType = "BIGINT") public static IntLiteral subtractInt(LiteralExpr first, LiteralExpr second) throws AnalysisException { long result = Math.subtractExact(first.getLongValue(), second.getLongValue()); return new IntLiteral(result, Type.BIGINT); } + @FEFunction(name = "subtract", argTypes = { "BIGINT", "BIGINT" }, returnType = "BIGINT") + public static IntLiteral subtractBigint(LiteralExpr first, LiteralExpr second) throws AnalysisException { + long result = Math.subtractExact(first.getLongValue(), second.getLongValue()); + return new IntLiteral(result, Type.BIGINT); + } + @FEFunction(name = "subtract", argTypes = { "DOUBLE", "DOUBLE" }, returnType = "DOUBLE") public static FloatLiteral subtractDouble(LiteralExpr first, LiteralExpr second) throws AnalysisException { double result = first.getDoubleValue() - second.getDoubleValue(); @@ -408,11 +444,27 @@ public class FEFunctions { return new LargeIntLiteral(result.toString()); } - @FEFunction(name = "multiply", argTypes = { "BIGINT", "BIGINT" }, returnType = "BIGINT") + @FEFunction(name = "multiply", argTypes = { "TINYINT", "TINYINT" }, returnType = "SMALLINT") + public static IntLiteral multiplyTinyint(LiteralExpr first, LiteralExpr second) throws AnalysisException { + long result = Math.multiplyExact(first.getLongValue(), second.getLongValue()); + return new IntLiteral(result, Type.SMALLINT); + } + + @FEFunction(name = "multiply", argTypes = { "SMALLINT", "SMALLINT" }, returnType = "INT") + public static IntLiteral multiplySmallint(LiteralExpr first, LiteralExpr second) throws AnalysisException { + long result = Math.multiplyExact(first.getLongValue(), second.getLongValue()); + return new IntLiteral(result, Type.INT); + } + + @FEFunction(name = "multiply", argTypes = { "INT", "INT" }, returnType = "BIGINT") public static IntLiteral multiplyInt(LiteralExpr first, LiteralExpr second) throws AnalysisException { - long left = first.getLongValue(); - long right = second.getLongValue(); - long result = Math.multiplyExact(left, right); + long result = Math.multiplyExact(first.getLongValue(), second.getLongValue()); + return new IntLiteral(result, Type.BIGINT); + } + + @FEFunction(name = "multiply", argTypes = { "BIGINT", "BIGINT" }, returnType = "BIGINT") + public static IntLiteral multiplyBigint(LiteralExpr first, LiteralExpr second) throws AnalysisException { + long result = Math.multiplyExact(first.getLongValue(), second.getLongValue()); return new IntLiteral(result, Type.BIGINT); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org