branch-2.1:[fix](nereids)Support negative partition range value and negative column default value. (#48297) (#48480)

backport: https://github.com/apache/doris/pull/48297
This commit is contained in:
James
2025-03-01 09:08:57 +08:00
committed by GitHub
parent 4979d70612
commit 0dd532f487
6 changed files with 156 additions and 3 deletions

View File

@ -1296,7 +1296,7 @@ columnDef
(aggType=aggTypeDef)?
((NOT)? NULL)?
(AUTO_INCREMENT (LEFT_PAREN autoIncInitValue=number RIGHT_PAREN)?)?
(DEFAULT (nullValue=NULL | INTEGER_VALUE | DECIMAL_VALUE | BITMAP_EMPTY | stringValue=STRING_LITERAL
(DEFAULT (nullValue=NULL | SUBTRACT? INTEGER_VALUE | SUBTRACT? DECIMAL_VALUE | BITMAP_EMPTY | stringValue=STRING_LITERAL
| CURRENT_DATE | defaultTimestamp=CURRENT_TIMESTAMP (LEFT_PAREN defaultValuePrecision=number RIGHT_PAREN)?))?
(ON UPDATE CURRENT_TIMESTAMP (LEFT_PAREN onUpdateValuePrecision=number RIGHT_PAREN)?)?
(COMMENT comment=STRING_LITERAL)?
@ -1340,7 +1340,7 @@ partitionValueList
;
partitionValueDef
: INTEGER_VALUE | STRING_LITERAL | MAXVALUE | NULL
: SUBTRACT? INTEGER_VALUE | STRING_LITERAL | MAXVALUE | NULL
;
rollupDefs

View File

@ -2745,7 +2745,17 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
Optional<DefaultValue> onUpdateDefaultValue = Optional.empty();
if (ctx.DEFAULT() != null) {
if (ctx.INTEGER_VALUE() != null) {
defaultValue = Optional.of(new DefaultValue(ctx.INTEGER_VALUE().getText()));
if (ctx.SUBTRACT() == null) {
defaultValue = Optional.of(new DefaultValue(ctx.INTEGER_VALUE().getText()));
} else {
defaultValue = Optional.of(new DefaultValue("-" + ctx.INTEGER_VALUE().getText()));
}
} else if (ctx.DECIMAL_VALUE() != null) {
if (ctx.SUBTRACT() == null) {
defaultValue = Optional.of(new DefaultValue(ctx.DECIMAL_VALUE().getText()));
} else {
defaultValue = Optional.of(new DefaultValue("-" + ctx.DECIMAL_VALUE().getText()));
}
} else if (ctx.stringValue != null) {
defaultValue = Optional.of(new DefaultValue(toStringValue(ctx.stringValue.getText())));
} else if (ctx.nullValue != null) {
@ -2890,6 +2900,9 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
@Override
public Expression visitPartitionValueDef(PartitionValueDefContext ctx) {
if (ctx.INTEGER_VALUE() != null) {
if (ctx.SUBTRACT() != null) {
return Literal.of("-" + ctx.INTEGER_VALUE().getText());
}
return Literal.of(ctx.INTEGER_VALUE().getText());
} else if (ctx.STRING_LITERAL() != null) {
return Literal.of(toStringValue(ctx.STRING_LITERAL().getText()));

View File

@ -0,0 +1,45 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !range1 --
-33 -33
-32 -32
-1 -1
1 1
2 2
16 16
17 17
32 32
33 33
63 63
-- !range2 --
-33 -33
-- !range3 --
-32 -32
-1 -1
-- !range4 --
1 1
2 2
-- !range5 --
16 16
17 17
-- !range6 --
32 32
33 33
63 63
-- !list1 --
-1 -1
1 1
2 2
-- !list2 --
1 1
2 2
-- !list3 --
-1 -1

View File

@ -0,0 +1,5 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !col1 --
1 -1 -10.010000000
2 2 2.200000000

View File

@ -0,0 +1,58 @@
// 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_negative_partition_value", "p0") {
sql "drop table if exists test_negative_partition_value_range"
sql """CREATE TABLE test_negative_partition_value_range
(a VARCHAR(5) NOT NULL,
b TINYINT NOT NULL)
ENGINE=olap UNIQUE KEY(a,b)
PARTITION BY RANGE(b) (
PARTITION p__32 VALUES LESS THAN (-32),
PARTITION p_0 VALUES LESS THAN (0),
PARTITION p_16 VALUES LESS THAN (16),
PARTITION p_32 VALUES LESS THAN (32),
PARTITION p_64 VALUES LESS THAN (64)
)
DISTRIBUTED BY HASH (a) BUCKETS 1 PROPERTIES('replication_num' = '1')
"""
sql """insert into test_negative_partition_value_range values ("1", 1), ("2", 2), ("16", 16), ("17", 17), ("32", 32), ("33", 33), ("63", 63), ("-1", -1), ("-32", -32), ("-33", -33) """
qt_range1 "select * from test_negative_partition_value_range order by b"
qt_range2 "select * from test_negative_partition_value_range partition(p__32) order by b"
qt_range3 "select * from test_negative_partition_value_range partition(p_0) order by b"
qt_range4 "select * from test_negative_partition_value_range partition(p_16) order by b"
qt_range5 "select * from test_negative_partition_value_range partition(p_32) order by b"
qt_range6 "select * from test_negative_partition_value_range partition(p_64) order by b"
sql "drop table if exists test_negative_partition_value_list"
sql """CREATE TABLE test_negative_partition_value_list
(a VARCHAR(5) NOT NULL,
b TINYINT NOT NULL)
ENGINE=olap
UNIQUE KEY(a,b)
PARTITION BY LIST(b) (
PARTITION p1 VALUES IN ("1","2","3","4"),
PARTITION p2 VALUES IN ("-1","-2","-3","-4")
)
DISTRIBUTED BY HASH (a) BUCKETS 1 PROPERTIES('replication_num' = '1')
"""
sql """insert into test_negative_partition_value_list values ("1", 1), ("2", 2), ("-1", -1)"""
qt_list1 "select * from test_negative_partition_value_list order by b"
qt_list2 "select * from test_negative_partition_value_list partition(p1) order by b"
qt_list3 "select * from test_negative_partition_value_list partition(p2) order by b"
}

View File

@ -0,0 +1,32 @@
// 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_negative_default_column_value", "p0") {
sql "drop table if exists test_negative_default_column_value"
sql """CREATE TABLE test_negative_default_column_value
(col1 int NOT NULL,
col2 int NULL default -1,
col3 decimal NULL default -10.01
)
ENGINE=olap
UNIQUE KEY(col1)
DISTRIBUTED BY HASH (col1) BUCKETS 1 PROPERTIES('replication_num' = '1')
"""
sql """insert into test_negative_default_column_value (col1) values (1)"""
sql """insert into test_negative_default_column_value values (2, 2, 2.2)"""
qt_col1 "select * from test_negative_default_column_value order by col1"
}