[fix](planner) Fix decimal precision and scale wrong when create table like (#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.
This commit is contained in:
JingDas
2023-11-01 16:11:43 +08:00
committed by GitHub
parent 4644191fd0
commit 1770224322
4 changed files with 83 additions and 1 deletions

View File

@ -735,7 +735,7 @@ public class Column implements Writable, GsonPostProcessable {
int scale = sType.getScalarScale();
int precision = sType.getScalarPrecision();
// not default
if (scale > 0 && precision != 9) {
if (!sType.isDefaultDecimal()) {
sb.append("(").append(precision).append(", ").append(scale)
.append(")");
}