From bc9c36f55962ea7e1a1eedbcd15271b1495af149 Mon Sep 17 00:00:00 2001 From: eldenmoon <15605149486@163.com> Date: Fri, 13 Sep 2024 14:12:06 +0800 Subject: [PATCH] support light schema change --- fe/fe-core/src/main/cup/sql_parser.cup | 22 +++++++++++++++++++ .../doris/alter/SchemaChangeHandler.java | 5 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup index 29a05856ff3b8e5..98d770d5f9cb4eb 100644 --- a/fe/fe-core/src/main/cup/sql_parser.cup +++ b/fe/fe-core/src/main/cup/sql_parser.cup @@ -43,6 +43,7 @@ import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; import org.apache.doris.catalog.ArrayType; +import org.apache.doris.catalog.ComplexVariantType; import org.apache.doris.catalog.GeneratedColumnInfo; import org.apache.doris.catalog.MapType; import org.apache.doris.catalog.StructField; @@ -814,7 +815,9 @@ nonterminal Expr function_call_expr, array_expr, map_expr; nonterminal ArrayLiteral array_literal; nonterminal MapLiteral map_literal; nonterminal StructField struct_field; +nonterminal StructField variant_field; nonterminal ArrayList struct_field_list; +nonterminal ArrayList variant_field_list; nonterminal StructLiteral struct_literal; nonterminal AnalyticWindow opt_window_clause; nonterminal AnalyticWindow.Type window_type; @@ -6884,6 +6887,8 @@ type ::= {: RESULT = new MapType(key_type,value_type); :} | KW_STRUCT LESSTHAN struct_field_list:fields GREATERTHAN {: RESULT = new StructType(fields); :} + | KW_VARIANT LESSTHAN variant_field_list:fields GREATERTHAN + {: RESULT = new ComplexVariantType(fields); :} | KW_CHAR LPAREN INTEGER_LITERAL:len RPAREN {: ScalarType type = ScalarType.createCharType(len.intValue()); RESULT = type; @@ -7199,6 +7204,23 @@ struct_field_list ::= :} ; +variant_field ::= + ident:name COLON type:type opt_comment:comment + {: RESULT = new StructField(name, type, comment, true); :} + ; + +variant_field_list ::= + variant_field:field + {: + RESULT = Lists.newArrayList(field); + :} + | variant_field_list:fields COMMA struct_field:field + {: + fields.add(field); + RESULT = fields; + :} + ; + struct_literal ::= LBRACE expr_list:list RBRACE {: diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java index 3051d37527f1075..ae9e2a2c48f37e1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java @@ -611,8 +611,9 @@ private boolean processModifyColumn(ModifyColumnClause alterClause, OlapTable ol if (!col.equals(modColumn)) { typeChanged = true; // TODO:the case where columnPos is not empty has not been considered - if (columnPos == null && col.getDataType() == PrimitiveType.VARCHAR - && modColumn.getDataType() == PrimitiveType.VARCHAR) { + if (columnPos == null && (col.getDataType() == PrimitiveType.VARCHAR + && modColumn.getDataType() == PrimitiveType.VARCHAR) + || (col.getDataType().isVariantType() && modColumn.getDataType().isVariantType())) { col.checkSchemaChangeAllowed(modColumn); lightSchemaChange = olapTable.getEnableLightSchemaChange(); }