[fix](planner) Failed to create table with CTAS when multiple varchar type filed as key (#18814)
Add restricton for converting varchar/char to string type, only fields that is string type and not in key desc could be convert to string type now.
This commit is contained in:
@ -43,6 +43,7 @@ import org.apache.doris.analysis.DropDbStmt;
|
||||
import org.apache.doris.analysis.DropPartitionClause;
|
||||
import org.apache.doris.analysis.DropTableStmt;
|
||||
import org.apache.doris.analysis.Expr;
|
||||
import org.apache.doris.analysis.FunctionCallExpr;
|
||||
import org.apache.doris.analysis.HashDistributionDesc;
|
||||
import org.apache.doris.analysis.KeysDesc;
|
||||
import org.apache.doris.analysis.LinkDbStmt;
|
||||
@ -1221,6 +1222,7 @@ public class InternalCatalog implements CatalogIf<Database> {
|
||||
List<String> columnNames = stmt.getColumnNames();
|
||||
CreateTableStmt createTableStmt = stmt.getCreateTableStmt();
|
||||
QueryStmt queryStmt = stmt.getQueryStmt();
|
||||
KeysDesc keysDesc = createTableStmt.getKeysDesc();
|
||||
ArrayList<Expr> resultExprs = queryStmt.getResultExprs();
|
||||
ArrayList<String> colLabels = queryStmt.getColLabels();
|
||||
int size = resultExprs.size();
|
||||
@ -1242,7 +1244,11 @@ public class InternalCatalog implements CatalogIf<Database> {
|
||||
TypeDef typeDef;
|
||||
Expr resultExpr = resultExprs.get(i);
|
||||
Type resultType = resultExpr.getType();
|
||||
if (resultType.isStringType()) {
|
||||
if (resultExpr instanceof FunctionCallExpr
|
||||
&& resultExpr.getType().getPrimitiveType().equals(PrimitiveType.VARCHAR)) {
|
||||
resultType = ScalarType.createVarchar(65533);
|
||||
}
|
||||
if (resultType.isStringType() && (keysDesc == null || !keysDesc.containsCol(name))) {
|
||||
// Use String for varchar/char/string type,
|
||||
// to avoid char-length-vs-byte-length issue.
|
||||
typeDef = new TypeDef(ScalarType.createStringType());
|
||||
|
||||
Reference in New Issue
Block a user