This is an automated email from the ASF dual-hosted git repository.
starocean999 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 e3bbba82cf [Fix](planner) fix to_date failed in create table as select
(#23613)
e3bbba82cf is described below
commit e3bbba82cf5b2b4b1d0efa60234f46cf290caad0
Author: LiBinfeng <[email protected]>
AuthorDate: Fri Sep 1 17:28:40 2023 +0800
[Fix](planner) fix to_date failed in create table as select (#23613)
Problem:
when create table as select using to_date function, it would failed
Example:
create table test_to_date properties('replication_num' = '1') as select
to_date('20230816') as datev2;
Reason:
after release version 2.0, datev1 is disabled, but to_date function
signature does not upgrade, so it failed when checking return type of to_date
Solved:
when getfunction, forbidden to_date with return type date_v1, datetime v1
also changed to datetime v2 and decimal v2 changed to decimal v3
---
.../doris/analysis/CreateTableAsSelectStmt.java | 20 ++++++++++++++++++++
regression-test/suites/ddl_p0/test_ctas.groovy | 8 ++++++++
2 files changed, 28 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java
index 942c3cce70..d9e507445e 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java
@@ -17,6 +17,9 @@
package org.apache.doris.analysis;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.Config;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
@@ -82,6 +85,23 @@ public class CreateTableAsSelectStmt extends DdlStmt {
queryStmt.getResultExprs().get(i).getSrcSlotRef().getColumn()
.setIsAllowNull(outputs.get(i).isNullable());
}
+ if (Config.enable_date_conversion) {
+ if (queryStmt.getResultExprs().get(i).getType() == Type.DATE) {
+ Expr castExpr =
queryStmt.getResultExprs().get(i).castTo(Type.DATEV2);
+ queryStmt.getResultExprs().set(i, castExpr);
+ }
+ if (queryStmt.getResultExprs().get(i).getType() ==
Type.DATETIME) {
+ Expr castExpr =
queryStmt.getResultExprs().get(i).castTo(Type.DATETIMEV2);
+ queryStmt.getResultExprs().set(i, castExpr);
+ }
+ }
+ if (Config.enable_decimal_conversion &&
queryStmt.getResultExprs().get(i).getType().isDecimalV2()) {
+ int precision =
queryStmt.getResultExprs().get(i).getType().getPrecision();
+ int scalar =
queryStmt.getResultExprs().get(i).getType().getDecimalDigits();
+ Expr castExpr = queryStmt.getResultExprs().get(i)
+ .castTo(ScalarType.createDecimalV3Type(precision,
scalar));
+ queryStmt.getResultExprs().set(i, castExpr);
+ }
}
ArrayList<Expr> resultExprs = getQueryStmt().getResultExprs();
if (columnNames != null && columnNames.size() != resultExprs.size()) {
diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy
b/regression-test/suites/ddl_p0/test_ctas.groovy
index 7c093aa479..1617e71c11 100644
--- a/regression-test/suites/ddl_p0/test_ctas.groovy
+++ b/regression-test/suites/ddl_p0/test_ctas.groovy
@@ -234,10 +234,18 @@ suite("test_ctas") {
String desc = sql 'desc c'
assertTrue(desc.contains('Yes'))
+ sql '''create table test_date_v2
+ properties (
+ "replication_num"="1"
+ ) as select to_date('20250829');
+ '''
+ desc = sql 'desc test_date_v2'
+ assertTrue(desc.contains('Yes'))
} finally {
sql 'drop table a'
sql 'drop table b'
sql 'drop table c'
+ sql 'drop table test_date_v2'
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]