This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 5b9b6c9065 [WIP](decimalv3) WIP (#11443) 5b9b6c9065 is described below commit 5b9b6c9065914383d6be4989d9b76c9ce31d8b91 Author: Gabriel <gabrielleeb...@gmail.com> AuthorDate: Wed Aug 3 11:21:36 2022 +0800 [WIP](decimalv3) WIP (#11443) * [feature-WIP](decimalv3) fix some bugs of decimalv3 --- be/src/vec/functions/function_binary_arithmetic.h | 10 ++++++--- .../apache/doris/analysis/FunctionCallExpr.java | 24 ++++++++++++++++++++++ .../java/org/apache/doris/catalog/ScalarType.java | 2 +- .../analysis/CreateTableAsSelectStmtTest.java | 22 ++++++++++++++------ 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/be/src/vec/functions/function_binary_arithmetic.h b/be/src/vec/functions/function_binary_arithmetic.h index 982871220a..6f07fa9f73 100644 --- a/be/src/vec/functions/function_binary_arithmetic.h +++ b/be/src/vec/functions/function_binary_arithmetic.h @@ -746,8 +746,13 @@ private: typename ResultDataType::FieldType scale_a; typename ResultDataType::FieldType scale_b; - // TODO(Gabriel): precision and scale need to be processed for decimalv3, now we just - // keep the same behavior as before + if constexpr (OpTraits::is_division && IsDataTypeDecimal<RightDataType>) { + if (config::enable_decimalv3) { + scale_a = type_right.get_scale_multiplier(); + scale_b = 1; + return std::make_tuple(type, scale_a, scale_b); + } + } scale_a = type.scale_factor_for(type_left, OpTraits::is_multiply); scale_b = type.scale_factor_for(type_right, OpTraits::is_multiply || OpTraits::is_division); return std::make_tuple(type, scale_a, scale_b); @@ -930,7 +935,6 @@ public: using ResultDataType = typename BinaryOperationTraits<Operation, LeftDataType, RightDataType>::ResultDataType; - if constexpr (!std::is_same_v<ResultDataType, InvalidType>) { auto column_result = ConstOrVectorAdapter<LeftDataType, RightDataType, Operation, is_to_null_type>:: diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index ad9b2feb7a..692a0f6d7f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -1066,6 +1066,11 @@ public class FunctionCallExpr extends Expr { if (!argTypes[i].matchesType(args[ix]) && Config.enable_date_conversion && !argTypes[i].isDateType() && (args[ix].isDate() || args[ix].isDatetime())) { uncheckedCastChild(ScalarType.getDefaultDateType(args[ix]), i); + } else if (!argTypes[i].matchesType(args[ix]) && Config.enable_decimalv3 + && Config.enable_decimal_conversion + && argTypes[i].isDecimalV3() && args[ix].isDecimalV2()) { + uncheckedCastChild(ScalarType.createDecimalV3Type(argTypes[i].getPrecision(), + ((ScalarType) argTypes[i]).getScalarScale()), i); } else if (!argTypes[i].matchesType(args[ix]) && !( argTypes[i].isDateType() && args[ix].isDateType())) { uncheckedCastChild(args[ix], i); @@ -1130,19 +1135,38 @@ public class FunctionCallExpr extends Expr { } } + if (this.type.isDecimalV2() && Config.enable_decimal_conversion && Config.enable_decimalv3 + && fn.getArgs().length == childTypes.length) { + boolean implicitCastToDecimalV3 = false; + for (int i = 0; i < fn.getArgs().length; i++) { + implicitCastToDecimalV3 = Type.canCastTo(childTypes[i], fn.getArgs()[i]); + if (implicitCastToDecimalV3) { + break; + } + } + if (implicitCastToDecimalV3) { + this.type = ScalarType.createDecimalV3Type(fn.getReturnType().getPrecision(), + ((ScalarType) fn.getReturnType()).getScalarScale()); + fn.setReturnType(this.type); + } + } + if (this.type.isDecimalV3()) { // DECIMAL need to pass precision and scale to be if (DECIMAL_FUNCTION_SET.contains(fn.getFunctionName().getFunction()) && (this.type.isDecimalV2() || this.type.isDecimalV3())) { if (DECIMAL_SAME_TYPE_SET.contains(fnName.getFunction())) { this.type = argTypes[0]; + fn.setReturnType(this.type); } else if (DECIMAL_WIDER_TYPE_SET.contains(fnName.getFunction())) { this.type = ScalarType.createDecimalV3Type(ScalarType.MAX_DECIMAL128_PRECISION, ((ScalarType) argTypes[0]).getScalarScale()); + fn.setReturnType(this.type); } else if (STDDEV_FUNCTION_SET.contains(fnName.getFunction())) { // for all stddev function, use decimal(38,9) as computing result this.type = ScalarType.createDecimalV3Type(ScalarType.MAX_DECIMAL128_PRECISION, STDDEV_DECIMAL_SCALE); + fn.setReturnType(this.type); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java index 5421e51b03..d5896e90bf 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java @@ -437,7 +437,7 @@ public class ScalarType extends Type { * create a wider decimal type. */ public static ScalarType createWiderDecimalV3Type(int precision, int scale) { - ScalarType type = new ScalarType(PrimitiveType.DECIMALV2); + ScalarType type = new ScalarType(getSuitableDecimalType(precision, false)); if (precision <= MAX_DECIMAL32_PRECISION) { type.precision = MAX_DECIMAL32_PRECISION; } else if (precision <= MAX_DECIMAL64_PRECISION) { diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java index 88151b9c65..44cde9ec1a 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java @@ -18,6 +18,7 @@ package org.apache.doris.analysis; import org.apache.doris.common.AnalysisException; +import org.apache.doris.common.Config; import org.apache.doris.common.ExceptionChecker; import org.apache.doris.qe.ShowResultSet; import org.apache.doris.utframe.TestWithFeService; @@ -72,12 +73,21 @@ public class CreateTableAsSelectStmtTest extends TestWithFeService { "create table `test`.`select_decimal_table_1` PROPERTIES(\"replication_num\" = \"1\") " + "as select sum(amount_decimal) from `test`.`decimal_table`"; createTableAsSelect(selectFromDecimal1); - Assertions.assertEquals( - "CREATE TABLE `select_decimal_table_1` (\n" + " `_col0` decimal(27, 9) NULL\n" + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`_col0`)\n" + "COMMENT 'OLAP'\n" + "DISTRIBUTED BY HASH(`_col0`) BUCKETS 10\n" - + "PROPERTIES (\n" + "\"replication_allocation\" = \"tag.location.default: 1\",\n" - + "\"in_memory\" = \"false\",\n" + "\"storage_format\" = \"V2\"\n" + ")", - showCreateTableByName("select_decimal_table_1").getResultRows().get(0).get(1)); + if (Config.enable_decimal_conversion && Config.enable_decimalv3) { + Assertions.assertEquals( + "CREATE TABLE `select_decimal_table_1` (\n" + " `_col0` decimal(38, 2) NULL\n" + ") ENGINE=OLAP\n" + + "DUPLICATE KEY(`_col0`)\n" + "COMMENT 'OLAP'\n" + "DISTRIBUTED BY HASH(`_col0`) BUCKETS 10\n" + + "PROPERTIES (\n" + "\"replication_allocation\" = \"tag.location.default: 1\",\n" + + "\"in_memory\" = \"false\",\n" + "\"storage_format\" = \"V2\"\n" + ")", + showCreateTableByName("select_decimal_table_1").getResultRows().get(0).get(1)); + } else { + Assertions.assertEquals( + "CREATE TABLE `select_decimal_table_1` (\n" + " `_col0` decimal(27, 9) NULL\n" + ") ENGINE=OLAP\n" + + "DUPLICATE KEY(`_col0`)\n" + "COMMENT 'OLAP'\n" + "DISTRIBUTED BY HASH(`_col0`) BUCKETS 10\n" + + "PROPERTIES (\n" + "\"replication_allocation\" = \"tag.location.default: 1\",\n" + + "\"in_memory\" = \"false\",\n" + "\"storage_format\" = \"V2\"\n" + ")", + showCreateTableByName("select_decimal_table_1").getResultRows().get(0).get(1)); + } } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org