Skip to content

Commit

Permalink
support light schema change
Browse files Browse the repository at this point in the history
  • Loading branch information
eldenmoon committed Sep 13, 2024
1 parent 0e0eb12 commit bc9c36f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
22 changes: 22 additions & 0 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<StructField> struct_field_list;
nonterminal ArrayList<StructField> variant_field_list;
nonterminal StructLiteral struct_literal;
nonterminal AnalyticWindow opt_window_clause;
nonterminal AnalyticWindow.Type window_type;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit bc9c36f

Please sign in to comment.