[fix](Nereids) create table should check column name format (#30421)

This commit is contained in:
morrySnow
2024-01-29 10:55:22 +08:00
committed by yiguolei
parent 5a13c7596a
commit dcfccde3d1
3 changed files with 44 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.nereids.NereidsPlanner;
import org.apache.doris.nereids.analyzer.UnboundResultSink;
import org.apache.doris.nereids.analyzer.UnboundTableSink;
import org.apache.doris.nereids.annotation.Developing;
import org.apache.doris.nereids.exceptions.AnalysisException;
@ -96,7 +97,7 @@ public class CreateTableCommand extends Command implements ForwardWithSync {
LogicalPlan query = ctasQuery.get();
List<String> ctasCols = createTableInfo.getCtasColumns();
NereidsPlanner planner = new NereidsPlanner(ctx.getStatementContext());
Plan plan = planner.plan(query, PhysicalProperties.ANY, ExplainLevel.NONE);
Plan plan = planner.plan(new UnboundResultSink<>(query), PhysicalProperties.ANY, ExplainLevel.NONE);
if (ctasCols == null) {
// we should analyze the plan firstly to get the columns' name.
ctasCols = plan.getOutput().stream().map(NamedExpression::getName).collect(Collectors.toList());

View File

@ -24,6 +24,7 @@ import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.FeNameFormat;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.types.ArrayType;
import org.apache.doris.nereids.types.BigIntType;
@ -181,6 +182,11 @@ public class ColumnDefinition {
* validate column definition and analyze
*/
public void validate(boolean isOlap, Set<String> keysSet, boolean isEnableMergeOnWrite, KeysType keysType) {
try {
FeNameFormat.checkColumnName(name);
} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e);
}
validateDataType(type.toCatalogDataType());
type = updateCharacterTypeLength(type);
if (type.isArrayType()) {