forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix](planner) Fix decimal precision and scale wrong when create tabl…
…e like (apache#25802) Use field datatype such as decimal(10, 0) to create table like. Because the scale is 0, the precision and scale will lost when create table like done. this will fix the bug. **Before fix, create table with following SQL**: CREATE TABLE IF NOT EXISTS db_test.table_test ( `name` varchar COMMENT "1m size", `id` SMALLINT COMMENT "[-32768, 32767]", `timestamp0` decimal null comment "c0", `timestamp1` decimal(38, 0) null comment "c1" ) DISTRIBUTED BY HASH(`id`) BUCKETS 1 PROPERTIES ('replication_num' = '1'); **and Then run** CREATE TABLE db_test.table_test_like LIKE db_test.table_test SHOW CREATE TABLE db_test.table_test_like; the field `timestamp1` will be decimal(9, 0), it's wrong. this will fix it.
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- This file is automatically generated. You should know what you did if you want to edit this | ||
-- !desc_create_table -- | ||
decimal_test DUP_KEYS name VARCHAR(*) VARCHAR(*) Yes true \N true | ||
id SMALLINT SMALLINT Yes false \N NONE true | ||
timestamp0 DECIMAL DECIMALV3(9, 0) Yes false \N NONE true | ||
timestamp1 DECIMAL DECIMALV3(10, 0) Yes false \N NONE true | ||
timestamp2 DECIMAL(10, 1) DECIMALV3(10, 1) Yes false \N NONE true | ||
timestamp3 DECIMAL DECIMALV3(10, 0) Yes false \N NONE true | ||
timestamp4 DECIMAL(10, 1) DECIMALV3(10, 1) Yes false \N NONE true | ||
|
||
-- !desc_create_table_like -- | ||
decimal_test_like DUP_KEYS name VARCHAR(*) VARCHAR(*) Yes true \N true | ||
id SMALLINT SMALLINT Yes false \N NONE true | ||
timestamp0 DECIMAL DECIMALV3(9, 0) Yes false \N NONE true | ||
timestamp1 DECIMAL DECIMALV3(10, 0) Yes false \N NONE true | ||
timestamp2 DECIMAL(10, 1) DECIMALV3(10, 1) Yes false \N NONE true | ||
timestamp3 DECIMAL DECIMALV3(10, 0) Yes false \N NONE true | ||
timestamp4 DECIMAL(10, 1) DECIMALV3(10, 1) Yes false \N NONE true | ||
|
||
-- !select_table_like -- | ||
test1 1 123456789 1234567891 123456789.0 1234567891 123456789.0 | ||
|
50 changes: 50 additions & 0 deletions
50
regression-test/suites/ddl_p0/test_create_table_like.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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. | ||
|
||
// this suite is for creating table with timestamp datatype in defferent | ||
// case. For example: 'year' and 'Year' datatype should also be valid in definition | ||
|
||
|
||
suite("test_create_table_like") { | ||
|
||
sql """DROP TABLE IF EXISTS decimal_test""" | ||
sql """CREATE TABLE decimal_test | ||
( | ||
`name` varchar COMMENT "1m size", | ||
`id` SMALLINT COMMENT "[-32768, 32767]", | ||
`timestamp0` decimal null comment "c0", | ||
`timestamp1` decimal(10, 0) null comment "c1", | ||
`timestamp2` decimal(10, 1) null comment "c2", | ||
`timestamp3` decimalv3(10, 0) null comment "c3", | ||
`timestamp4` decimalv3(10, 1) null comment "c4", | ||
) | ||
DISTRIBUTED BY HASH(`id`) BUCKETS 1 | ||
PROPERTIES ('replication_num' = '1')""" | ||
qt_desc_create_table """desc decimal_test all""" | ||
|
||
sql """DROP TABLE IF EXISTS decimal_test_like""" | ||
sql """CREATE TABLE decimal_test_like LIKE decimal_test""" | ||
|
||
qt_desc_create_table_like """desc decimal_test_like all""" | ||
|
||
|
||
sql """INSERT INTO decimal_test_like | ||
(`name`, `id`, `timestamp0`, `timestamp1`, `timestamp2`, `timestamp3`, `timestamp4`) | ||
VALUES ("test1", 1, 123456789, 1234567891, 123456789, 1234567891, 123456789)""" | ||
|
||
qt_select_table_like """select * from decimal_test_like""" | ||
} |