[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
This commit is contained in:
@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user