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 440cf526c8 [fix](type compatibility) fix unsigned int type
compatibility problem (#17427)
440cf526c8 is described below
commit 440cf526c8249fd61c0d5f4d290ff2ba9190a2a4
Author: ZhangYu0123 <[email protected]>
AuthorDate: Tue Mar 7 08:55:38 2023 +0800
[fix](type compatibility) fix unsigned int type compatibility problem
(#17427)
Fix unsigned int type compatibility value scope problem.
When defining columns, map UNSIGNED INT to BIGINT for compatibility.
The problems are as follows:
It is not consistent with this doc
image
We support the unsigned int type to be compatible with mysql types, but the
unsigned int type is created as the int at the time of definition. This will
cause numerical overflow.
---
fe/fe-core/src/main/cup/sql_parser.cup | 5 +-
.../unsigned/test_unsigned_int_compatibility.out | 18 +++++++
.../test_unsigned_int_compatibility.groovy | 55 ++++++++++++++++++++++
3 files changed, 76 insertions(+), 2 deletions(-)
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index e252a8dd70..939729e55d 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -5744,6 +5744,9 @@ type ::=
{: RESULT = Type.SMALLINT; :}
| opt_signed_unsigned KW_INT opt_field_length
{: RESULT = Type.INT; :}
+ // This is just for MySQL compatibility now.
+ | KW_UNSIGNED KW_INT opt_field_length
+ {: RESULT = Type.BIGINT; :}
| KW_BIGINT opt_field_length
{: RESULT = Type.BIGINT; :}
| KW_LARGEINT opt_field_length
@@ -5848,8 +5851,6 @@ opt_signed_unsigned ::=
{: RESULT = true; :}
| KW_SIGNED
{: RESULT = true; :}
- | KW_UNSIGNED
- {: RESULT = false; :}
;
type_def ::=
diff --git
a/regression-test/data/types_p0/unsigned/test_unsigned_int_compatibility.out
b/regression-test/data/types_p0/unsigned/test_unsigned_int_compatibility.out
new file mode 100644
index 0000000000..0f8cd0f99b
--- /dev/null
+++ b/regression-test/data/types_p0/unsigned/test_unsigned_int_compatibility.out
@@ -0,0 +1,18 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !desc_tb --
+user_id LARGEINT No true \N
+city VARCHAR(20) Yes true \N
+value1 BIGINT Yes false \N REPLACE
+
+-- !select_tb --
+1 Beijing 21474836478
+
+-- !desc_tb --
+user_id LARGEINT No true \N
+city VARCHAR(20) Yes true \N
+value1 BIGINT Yes false \N REPLACE
+value2 BIGINT Yes false \N REPLACE
+
+-- !select_tb --
+1 Beijing 21474836478 \N
+2 Beijing 21474836478 21474836478
diff --git
a/regression-test/suites/types_p0/unsigned/test_unsigned_int_compatibility.groovy
b/regression-test/suites/types_p0/unsigned/test_unsigned_int_compatibility.groovy
new file mode 100644
index 0000000000..1a4681a206
--- /dev/null
+++
b/regression-test/suites/types_p0/unsigned/test_unsigned_int_compatibility.groovy
@@ -0,0 +1,55 @@
+// 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_unsigned_int_compatibility") {
+ def tableName = "test_unsigned_int_compatibility"
+
+ sql """DROP TABLE IF EXISTS ${tableName}"""
+ sql """
+ CREATE TABLE IF NOT EXISTS ${tableName} (
+ `user_id` LARGEINT NOT NULL COMMENT "用户id",
+ `city` VARCHAR(20) COMMENT "用户所在城市",
+ `value1` UNSIGNED INT COMMENT "value2"
+ )
+ UNIQUE KEY(`user_id`, `city`)
+ DISTRIBUTED BY HASH(`user_id`)
+ PROPERTIES (
+ "replication_num" = "1" ,
+ "light_schema_change" = "true"
+ );
+ """
+ qt_desc_tb "DESC ${tableName}"
+
+ sql """
+ INSERT INTO ${tableName} VALUES
+ (1, 'Beijing', 21474836478);
+ """
+ qt_select_tb "SELECT * FROM ${tableName}"
+
+ sql """
+ ALTER table ${tableName} ADD COLUMN value2 UNSIGNED INT;
+ """
+ qt_desc_tb "DESC ${tableName}"
+
+ sql """
+ INSERT INTO ${tableName} VALUES
+ (2, 'Beijing', 21474836478, 21474836478);
+ """
+ qt_select_tb "SELECT * FROM ${tableName} order by user_id"
+
+ sql "DROP TABLE ${tableName}"
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]