This is an automated email from the ASF dual-hosted git repository.
w41ter 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 1cb2fd50e9b [fix](column) Math default value showed incorrectly
(#47655)
1cb2fd50e9b is described below
commit 1cb2fd50e9b0d9210709c9727f346dc9ca066afe
Author: Uniqueyou <[email protected]>
AuthorDate: Wed Feb 12 14:13:07 2025 +0800
[fix](column) Math default value showed incorrectly (#47655)
before
```
mysql> CREATE TABLE IF NOT EXISTS t
-> (
-> k TINYINT,
-> v1 DOUBLE NOT NULL DEFAULT E,
-> v2 INT
-> )
-> UNIQUE KEY(K)
-> DISTRIBUTED BY HASH(k)
-> PROPERTIES("replication_num" = "1");
Query OK, 0 rows affected (0.02 sec)
mysql> show create table t\G
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`k` tinyint NULL,
`v1` double NOT NULL DEFAULT 2.718281828459045,
`v2` int NULL
) ENGINE=OLAP
UNIQUE KEY(`k`)
DISTRIBUTED BY HASH(`k`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
1 row in set (0.00 sec)
```
now
```
mysql> show create table t\G
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`k` tinyint NULL,
`v1` double NOT NULL DEFAULT E,
`v2` int NULL
) ENGINE=OLAP
UNIQUE KEY(`k`)
DISTRIBUTED BY HASH(`k`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
1 row in set (0.00 sec)
```
---
.../main/java/org/apache/doris/catalog/Column.java | 5 +-
.../plans/commands/ShowCreateTableCommandTest.java | 60 ++++++++++++++++++++++
2 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
index fa7c7feb7f0..b2678558dff 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
@@ -997,14 +997,15 @@ public class Column implements GsonPostProcessable {
if (isAutoInc) {
sb.append(" AUTO_INCREMENT(").append(autoIncInitValue).append(")");
}
- if (defaultValue != null && getDataType() != PrimitiveType.HLL &&
getDataType() != PrimitiveType.BITMAP) {
+ if (defaultValue != null && getDataType() != PrimitiveType.HLL &&
getDataType() != PrimitiveType.BITMAP
+ && getDataType() != PrimitiveType.DOUBLE) {
if (defaultValueExprDef != null) {
sb.append(" DEFAULT ").append(defaultValue).append("");
} else {
sb.append(" DEFAULT \"").append(defaultValue).append("\"");
}
}
- if (getDataType() == PrimitiveType.BITMAP && defaultValue != null) {
+ if ((getDataType() == PrimitiveType.BITMAP || getDataType() ==
PrimitiveType.DOUBLE) && defaultValue != null) {
if (defaultValueExprDef != null) {
sb.append(" DEFAULT
").append(defaultValueExprDef.getExprName()).append("");
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateTableCommandTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateTableCommandTest.java
new file mode 100644
index 00000000000..c966cc24361
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateTableCommandTest.java
@@ -0,0 +1,60 @@
+// 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.
+
+package org.apache.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.nereids.parser.NereidsParser;
+import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.qe.ShowResultSet;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class ShowCreateTableCommandTest extends TestWithFeService {
+ @Override
+ protected void runBeforeAll() throws Exception {
+ createDatabase("test");
+ connectContext.setDatabase("test");
+ }
+
+ @Override
+ public void createTable(String sql) throws Exception {
+ LogicalPlan plan = new NereidsParser().parseSingle(sql);
+ Assertions.assertTrue(plan instanceof CreateTableCommand);
+ ((CreateTableCommand) plan).run(connectContext, null);
+ }
+
+ @Test
+ public void testCreateTableDefaultValueMath() throws Exception {
+ // test
+ String sql = "create table if not exists test.tbl\n" + "(k1 int, k2
double default E, k3 double default PI)\n"
+ + "distributed by hash(k1) buckets 1\n"
+ + "properties('replication_num' = '1'); ";
+ createTable(sql);
+ ShowCreateTableCommand showCreateTableCommand = new
ShowCreateTableCommand(new TableNameInfo("test", "tbl"),
+ false);
+ ShowResultSet result = showCreateTableCommand.doRun(connectContext,
null);
+ String resultStr =
result.getResultRows().stream().flatMap(List::stream).collect(Collectors.joining("
"));
+ Assertions.assertTrue(resultStr.contains("`k2` double NULL DEFAULT
E"));
+ Assertions.assertTrue(resultStr.contains("`k3` double NULL DEFAULT
PI"));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]