This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 0dd532f487c branch-2.1:[fix](nereids)Support negative partition range 
value and negative column default value. (#48297) (#48480)
0dd532f487c is described below

commit 0dd532f487c59e19ba1a46bfedd2b73d684ae527
Author: James <lijib...@selectdb.com>
AuthorDate: Sat Mar 1 09:08:57 2025 +0800

    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
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |   4 +-
 .../doris/nereids/parser/LogicalPlanBuilder.java   |  15 +++++-
 .../partition_p0/test_negative_partition_value.out | Bin 0 -> 375 bytes
 .../test_negative_default_column_value.out         | Bin 0 -> 143 bytes
 .../test_negative_partition_value.groovy           |  58 +++++++++++++++++++++
 .../test_negative_default_column_value.groovy      |  32 ++++++++++++
 6 files changed, 106 insertions(+), 3 deletions(-)

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 2e6430a595b..02f268255b9 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
@@ -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
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index b1f32c324e2..30aa9d7e457 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -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()));
diff --git 
a/regression-test/data/partition_p0/test_negative_partition_value.out 
b/regression-test/data/partition_p0/test_negative_partition_value.out
new file mode 100644
index 00000000000..5e48414e286
Binary files /dev/null and 
b/regression-test/data/partition_p0/test_negative_partition_value.out differ
diff --git 
a/regression-test/data/table_p0/test_negative_default_column_value.out 
b/regression-test/data/table_p0/test_negative_default_column_value.out
new file mode 100644
index 00000000000..282deb8acdf
Binary files /dev/null and 
b/regression-test/data/table_p0/test_negative_default_column_value.out differ
diff --git 
a/regression-test/suites/partition_p0/test_negative_partition_value.groovy 
b/regression-test/suites/partition_p0/test_negative_partition_value.groovy
new file mode 100644
index 00000000000..cc453925268
--- /dev/null
+++ b/regression-test/suites/partition_p0/test_negative_partition_value.groovy
@@ -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"
+}
diff --git 
a/regression-test/suites/table_p0/test_negative_default_column_value.groovy 
b/regression-test/suites/table_p0/test_negative_default_column_value.groovy
new file mode 100644
index 00000000000..6711fa4761f
--- /dev/null
+++ b/regression-test/suites/table_p0/test_negative_default_column_value.groovy
@@ -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"
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to