This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new 73ff45380db [keyword](decimalv2) Add DecimalV2 keyword #26283 (#26319) 73ff45380db is described below commit 73ff45380dbcb8a766854254255e1af139c514c1 Author: Gabriel <gabrielleeb...@gmail.com> AuthorDate: Fri Nov 3 23:35:10 2023 +0800 [keyword](decimalv2) Add DecimalV2 keyword #26283 (#26319) --- be/src/exec/tablet_info.cpp | 11 +++-- .../java/org/apache/doris/catalog/ScalarType.java | 34 +++++++++++++ .../antlr4/org/apache/doris/nereids/DorisLexer.g4 | 1 + .../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 + fe/fe-core/src/main/cup/sql_parser.cup | 13 +++++ fe/fe-core/src/main/jflex/sql_scanner.flex | 1 + .../decimalv3/test_uniq_tab_decimalv2.out | 12 +++++ .../decimalv3/test_uniq_tab_decimalv2.groovy | 56 ++++++++++++++++++++++ 8 files changed, 126 insertions(+), 4 deletions(-) diff --git a/be/src/exec/tablet_info.cpp b/be/src/exec/tablet_info.cpp index 8df90973b05..6c3fed8f059 100644 --- a/be/src/exec/tablet_info.cpp +++ b/be/src/exec/tablet_info.cpp @@ -69,7 +69,7 @@ Status OlapTableSchemaParam::init(const POlapTableSchemaParam& pschema) { for (auto& col : pschema.partial_update_input_columns()) { _partial_update_input_columns.insert(col); } - std::unordered_map<std::pair<std::string, std::string>, SlotDescriptor*> slots_map; + std::unordered_map<std::pair<std::string, FieldType>, SlotDescriptor*> slots_map; _tuple_desc = _obj_pool.add(new TupleDescriptor(pschema.tuple_desc())); // When FE version is less than 2.0.3, But BE upgrade to 2.0.3, // the filed col_type in slot_desc is INVALID_TYPE default. @@ -81,7 +81,8 @@ Status OlapTableSchemaParam::init(const POlapTableSchemaParam& pschema) { _tuple_desc->add_slot(slot_desc); string data_type; EnumToString(TPrimitiveType, to_thrift(slot_desc->col_type()), data_type); - slots_map.emplace(std::make_pair(to_lower(slot_desc->col_name()), std::move(data_type)), + slots_map.emplace(std::make_pair(to_lower(slot_desc->col_name()), + TabletColumn::get_field_type_by_string(data_type)), slot_desc); } @@ -92,8 +93,10 @@ Status OlapTableSchemaParam::init(const POlapTableSchemaParam& pschema) { for (auto& pcolumn_desc : p_index.columns_desc()) { if (!_is_partial_update || _partial_update_input_columns.count(pcolumn_desc.name()) > 0) { - std::string col_type = has_invalid_type ? "INVALID_TYPE" : pcolumn_desc.type(); - auto it = slots_map.find(std::make_pair(to_lower(pcolumn_desc.name()), col_type)); + auto it = slots_map.find(std::make_pair( + to_lower(pcolumn_desc.name()), + TabletColumn::get_field_type_by_string( + has_invalid_type ? "INVALID_TYPE" : pcolumn_desc.type()))); if (it == std::end(slots_map)) { return Status::InternalError("unknown index column, column={}, type={}", pcolumn_desc.name(), pcolumn_desc.type()); diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java index 88c0023fba6..7e3b1b97f23 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java @@ -373,6 +373,40 @@ public class ScalarType extends Type { return type; } + public static ScalarType createDecimalV2Type() { + Preconditions.checkState(!Config.disable_decimalv2, "DecimalV2 is disable in fe.conf!"); + return DEFAULT_DECIMALV2; + } + + public static ScalarType createDecimalV2Type(int precision) { + Preconditions.checkState(!Config.disable_decimalv2, "DecimalV2 is disable in fe.conf!"); + return createDecimalV2Type(precision, DEFAULT_SCALE); + } + + public static ScalarType createDecimalV2Type(int precision, int scale) { + Preconditions.checkState(!Config.disable_decimalv2, "DecimalV2 is disable in fe.conf!"); + ScalarType type = new ScalarType(PrimitiveType.DECIMALV2); + type.precision = precision; + type.scale = scale; + return type; + } + + public static ScalarType createDecimalV2Type(String precisionStr) { + Preconditions.checkState(!Config.disable_decimalv2, "DecimalV2 is disable in fe.conf!"); + ScalarType type = new ScalarType(PrimitiveType.DECIMALV2); + type.precisionStr = precisionStr; + type.scaleStr = null; + return type; + } + + public static ScalarType createDecimalV2Type(String precisionStr, String scaleStr) { + Preconditions.checkState(!Config.disable_decimalv2, "DecimalV2 is disable in fe.conf!"); + ScalarType type = new ScalarType(PrimitiveType.DECIMALV2); + type.precisionStr = precisionStr; + type.scaleStr = scaleStr; + return type; + } + public static PrimitiveType getSuitableDecimalType(int precision, boolean decimalV2) { if (decimalV2 && !Config.enable_decimal_conversion) { return PrimitiveType.DECIMALV2; diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 index 90e52ee7e0d..90ca7c39496 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 @@ -191,6 +191,7 @@ DAY: 'DAY'; DAYS_ADD: 'DAYS_ADD'; DAYS_SUB: 'DAYS_SUB'; DECIMAL: 'DECIMAL'; +DECIMALV2: 'DECIMALV2'; DECIMALV3: 'DECIMALV3'; DECOMMISSION: 'DECOMMISSION'; DEFAULT: 'DEFAULT'; diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 893fddc0ffe..7a24767e127 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -490,6 +490,7 @@ primitiveColType: | type=VARCHAR | type=CHAR | type=DECIMAL + | type=DECIMALV2 | type=DECIMALV3 | type=ALL ; @@ -610,6 +611,7 @@ nonReserved | DAYS_ADD | DAYS_SUB | DECIMAL + | DECIMALV2 | DECIMALV3 | DEFERRED | DEMAND diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup index d25b39234a9..d246b141fa4 100644 --- a/fe/fe-core/src/main/cup/sql_parser.cup +++ b/fe/fe-core/src/main/cup/sql_parser.cup @@ -328,6 +328,7 @@ terminal String KW_DATEV2, KW_DAY, KW_DECIMAL, + KW_DECIMALV2, KW_DECIMALV3, KW_DECOMMISSION, KW_DEFAULT, @@ -6285,6 +6286,16 @@ type ::= {: RESULT = ScalarType.createDecimalV3Type(precision); :} | KW_DECIMALV3 LPAREN ident_or_text:precision COMMA ident_or_text:scale RPAREN {: RESULT = ScalarType.createDecimalV3Type(precision, scale); :} + | KW_DECIMALV2 LPAREN INTEGER_LITERAL:precision RPAREN + {: RESULT = ScalarType.createDecimalV2Type(precision.intValue()); :} + | KW_DECIMALV2 LPAREN INTEGER_LITERAL:precision COMMA INTEGER_LITERAL:scale RPAREN + {: RESULT = ScalarType.createDecimalV2Type(precision.intValue(), scale.intValue()); :} + | KW_DECIMALV2 + {: RESULT = ScalarType.createDecimalV2Type(); :} + | KW_DECIMALV2 LPAREN ident_or_text:precision RPAREN + {: RESULT = ScalarType.createDecimalV2Type(precision); :} + | KW_DECIMALV2 LPAREN ident_or_text:precision COMMA ident_or_text:scale RPAREN + {: RESULT = ScalarType.createDecimalV2Type(precision, scale); :} | KW_HLL {: ScalarType type = ScalarType.createHllType(); RESULT = type; @@ -7402,6 +7413,8 @@ keyword ::= {: RESULT = id; :} | KW_DEMAND:id {: RESULT = id; :} + | KW_DECIMALV2:id + {: RESULT = id; :} | KW_DECIMALV3:id {: RESULT = id; :} | KW_DIAGNOSE:id diff --git a/fe/fe-core/src/main/jflex/sql_scanner.flex b/fe/fe-core/src/main/jflex/sql_scanner.flex index c3fed9394de..0e72b45992b 100644 --- a/fe/fe-core/src/main/jflex/sql_scanner.flex +++ b/fe/fe-core/src/main/jflex/sql_scanner.flex @@ -178,6 +178,7 @@ import org.apache.doris.qe.SqlModeHelper; keywordMap.put("time", new Integer(SqlParserSymbols.KW_TIME)); keywordMap.put("day", new Integer(SqlParserSymbols.KW_DAY)); keywordMap.put("decimal", new Integer(SqlParserSymbols.KW_DECIMAL)); + keywordMap.put("decimalv2", new Integer(SqlParserSymbols.KW_DECIMALV2)); keywordMap.put("decimalv3", new Integer(SqlParserSymbols.KW_DECIMALV3)); keywordMap.put("decommission", new Integer(SqlParserSymbols.KW_DECOMMISSION)); keywordMap.put("default", new Integer(SqlParserSymbols.KW_DEFAULT)); diff --git a/regression-test/data/datatype_p0/decimalv3/test_uniq_tab_decimalv2.out b/regression-test/data/datatype_p0/decimalv3/test_uniq_tab_decimalv2.out new file mode 100644 index 00000000000..b81aa904c67 --- /dev/null +++ b/regression-test/data/datatype_p0/decimalv3/test_uniq_tab_decimalv2.out @@ -0,0 +1,12 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_all -- +\N \N \N \N +1.10000 1.20000 1.30000 1.40000 +2.10000 1.20000 1.30000 1.40000 + +-- !select_pred_decimal32_key -- +1.10000 1.20000 1.30000 1.40000 + +-- !select_pred_decimal32_key -- +1.10000 1.20000 1.30000 1.40000 + diff --git a/regression-test/suites/datatype_p0/decimalv3/test_uniq_tab_decimalv2.groovy b/regression-test/suites/datatype_p0/decimalv3/test_uniq_tab_decimalv2.groovy new file mode 100644 index 00000000000..90efdd3a216 --- /dev/null +++ b/regression-test/suites/datatype_p0/decimalv3/test_uniq_tab_decimalv2.groovy @@ -0,0 +1,56 @@ +// 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("test_uniq_tab_decimalv2") { + + def table1 = "test_uniq_tab_decimalv2" + + sql "drop table if exists ${table1}" + + sql """ + CREATE TABLE IF NOT EXISTS `${table1}` ( + `decimal_key1` decimalv2(8, 5) NULL COMMENT "", + `decimal_key2` decimalv2(16, 5) NULL COMMENT "", + `decimal_value1` decimalv2(8, 5) NULL COMMENT "", + `decimal_value2` decimalv2(16, 5) NULL COMMENT "", + ) ENGINE=OLAP + UNIQUE KEY(`decimal_key1`, `decimal_key2`) + COMMENT "OLAP" + DISTRIBUTED BY HASH(`decimal_key1`, `decimal_key2`) BUCKETS 8 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "in_memory" = "false", + "storage_format" = "V2" + ) + """ + + sql """insert into ${table1} values(1.1,1.2,1.3,1.4), + (1.1,1.2,1.3,1.4), + (1.1,1.2,1.3,1.4), + (1.1,1.2,1.3,1.4), + (1.1,1.2,1.3,1.4), + (2.1,1.2,1.3,1.4), + (2.1,1.2,1.3,1.4), + (2.1,1.2,1.3,1.4), + (NULL, NULL, NULL, NULL) + """ + qt_select_all "select * from ${table1} order by decimal_key1" + + qt_select_pred_decimal32_key "select * from ${table1} where decimal_key1 = 1.1 order by decimal_key1" + qt_select_pred_decimal32_key "select * from ${table1} where decimal_key1 < 1.1111111111111111111 order by decimal_key1" + sql "drop table if exists ${table1}" +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org