This is an automated email from the ASF dual-hosted git repository.
gabriellee 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 dd8bcc831c6 [keyword](decimalv2) Add DecimalV2 keyword (#26283)
dd8bcc831c6 is described below
commit dd8bcc831c6a97355c7dcce1684eec6596f7a03a
Author: Gabriel <[email protected]>
AuthorDate: Thu Nov 2 16:27:12 2023 +0800
[keyword](decimalv2) Add DecimalV2 keyword (#26283)
---
be/src/exec/tablet_info.cpp | 10 ++--
.../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, 125 insertions(+), 4 deletions(-)
diff --git a/be/src/exec/tablet_info.cpp b/be/src/exec/tablet_info.cpp
index 9a24771edc0..00ec0c2e581 100644
--- a/be/src/exec/tablet_info.cpp
+++ b/be/src/exec/tablet_info.cpp
@@ -130,7 +130,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()));
for (auto& p_slot_desc : pschema.slot_descs()) {
@@ -138,7 +138,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);
}
@@ -149,8 +150,9 @@ 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) {
- auto it = slots_map.find(
- std::make_pair(to_lower(pcolumn_desc.name()),
pcolumn_desc.type()));
+ auto it = slots_map.find(std::make_pair(
+ to_lower(pcolumn_desc.name()),
+
TabletColumn::get_field_type_by_string(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 bd937b4d0c5..3bd7f7a7e0b 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
@@ -381,6 +381,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 83c7b9dd95c..6bfc38d7611 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
@@ -193,6 +193,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 271834940d2..8a1896a3d0c 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
@@ -748,6 +748,7 @@ primitiveColType:
| type=VARCHAR
| type=CHAR
| type=DECIMAL
+ | type=DECIMALV2
| type=DECIMALV3
| type=IPV4
| type=IPV6
@@ -884,6 +885,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 479c9fd9c4f..9775b3c96d5 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -332,6 +332,7 @@ terminal String
KW_DATEV1,
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;
@@ -7426,6 +7437,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 e58c76a2354..3bb65206470 100644
--- a/fe/fe-core/src/main/jflex/sql_scanner.flex
+++ b/fe/fe-core/src/main/jflex/sql_scanner.flex
@@ -182,6 +182,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: [email protected]
For additional commands, e-mail: [email protected]