Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[Feat](nereids) support generated column#35284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
40ac111
[Feat](nereids) support generated column
feiniaofeiafei 71b1c8b
[Feat](nereids) support generated column
feiniaofeiafei 9bd1103
[Feat](nereids) support generated column
feiniaofeiafei ef0ef4a
[Feat](nereids) support generated column
feiniaofeiafei 0409c3f
[Feat](nereids) support generated column
feiniaofeiafei f2b99f5
[Feat](nereids) support generated column
feiniaofeiafei fe4ba69
[Feat](nereids) support generated column
feiniaofeiafei cff3c30
[Feat](nereids) support generated column
feiniaofeiafei ec1d9fc
[Feat](nereids) support generated column
feiniaofeiafei c80e0ad
[Feat](nereids) support generated column
feiniaofeiafei bfc1f5b
[Feat](nereids) support generated column
feiniaofeiafei 90fc7cf
[Feat](nereids) support generated column
feiniaofeiafei 1df666b
[Feat](nereids) support generated column
feiniaofeiafei c8a1a18
[Feat](nereids) support generated column
feiniaofeiafei 74faa45
[Feat](nereids) support generated column
feiniaofeiafei b373e55
[Feat](nereids) support generated column
feiniaofeiafei fc0efd8
[Feat](nereids) support generated column
feiniaofeiafei b02f4bc
[Feat](nereids) support generated column
feiniaofeiafei df1b9f4
[Feat](nereids) support generated column
feiniaofeiafei 49b90e8
[Feat](nereids) support generated column
feiniaofeiafei f636264
[Feat](nereids) support generated column
feiniaofeiafei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2 fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -115,6 +115,7 @@ AT: 'AT'; | ||
| AUTHORS: 'AUTHORS'; | ||
| AUTO: 'AUTO'; | ||
| AUTO_INCREMENT: 'AUTO_INCREMENT'; | ||
| ALWAYS: 'ALWAYS'; | ||
| BACKEND: 'BACKEND'; | ||
| BACKENDS: 'BACKENDS'; | ||
| BACKUP: 'BACKUP'; | ||
| @@ -276,6 +277,7 @@ FRONTENDS: 'FRONTENDS'; | ||
| FULL: 'FULL'; | ||
| FUNCTION: 'FUNCTION'; | ||
| FUNCTIONS: 'FUNCTIONS'; | ||
| GENERATED: 'GENERATED'; | ||
| GENERIC: 'GENERIC'; | ||
| GLOBAL: 'GLOBAL'; | ||
| GRANT: 'GRANT'; | ||
morrySnow marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
5 changes: 4 additions & 1 deletion
5 fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 88 additions & 2 deletions
90 fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -28,6 +28,7 @@ | ||
| import org.apache.doris.analysis.CreateMaterializedViewStmt; | ||
| import org.apache.doris.analysis.DropColumnClause; | ||
| import org.apache.doris.analysis.DropIndexClause; | ||
| import org.apache.doris.analysis.Expr; | ||
| import org.apache.doris.analysis.IndexDef; | ||
| import org.apache.doris.analysis.ModifyColumnClause; | ||
| import org.apache.doris.analysis.ModifyTablePropertiesClause; | ||
| @@ -42,6 +43,7 @@ | ||
| import org.apache.doris.catalog.DistributionInfo.DistributionInfoType; | ||
| import org.apache.doris.catalog.Env; | ||
| import org.apache.doris.catalog.EnvFactory; | ||
| import org.apache.doris.catalog.GeneratedColumnInfo; | ||
| import org.apache.doris.catalog.HashDistributionInfo; | ||
| import org.apache.doris.catalog.Index; | ||
| import org.apache.doris.catalog.KeysType; | ||
| @@ -377,6 +379,23 @@ private boolean processDropColumn(DropColumnClause alterClause, OlapTable olapTa | ||
| } | ||
| } | ||
| // generated column check | ||
| Map<String, Column> nameToColumn = new HashMap<>(); | ||
morrySnow marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| for (Column c : indexSchemaMap.get(baseIndexId)) { | ||
| nameToColumn.put(c.getName(), c); | ||
| } | ||
| if (null == targetIndexName) { | ||
| if (nameToColumn.containsKey(dropColName)) { | ||
| Column column = nameToColumn.get(dropColName); | ||
| Set<String> generatedColumnsThatReferToThis = column.getGeneratedColumnsThatReferToThis(); | ||
| if (!generatedColumnsThatReferToThis.isEmpty()) { | ||
| throw new DdlException( | ||
| "Column '" + dropColName + "' has a generated column dependency on :" | ||
| + generatedColumnsThatReferToThis); | ||
| } | ||
| } | ||
| } | ||
| Iterator<Index> it = indexes.iterator(); | ||
| while (it.hasNext()) { | ||
| Index index = it.next(); | ||
| @@ -403,6 +422,8 @@ private boolean processDropColumn(DropColumnClause alterClause, OlapTable olapTa | ||
| if (column.getName().equalsIgnoreCase(dropColName)) { | ||
| baseIter.remove(); | ||
| found = true; | ||
| // find generated column referred column | ||
| removeColumnWhenDropGeneratedColumn(column, nameToColumn); | ||
| break; | ||
| } | ||
| } | ||
| @@ -528,6 +549,7 @@ private boolean processModifyColumn(ModifyColumnClause alterClause, OlapTable ol | ||
| Map<Long, LinkedList<Column>> indexSchemaMap) throws DdlException { | ||
| Column modColumn = alterClause.getColumn(); | ||
| boolean lightSchemaChange = false; | ||
| if (KeysType.AGG_KEYS == olapTable.getKeysType()) { | ||
| if (modColumn.isKey() && null != modColumn.getAggregationType()) { | ||
| throw new DdlException("Can not assign aggregation method on key column: " + modColumn.getName()); | ||
| @@ -784,12 +806,15 @@ private void processReorderColumn(ReorderColumnsClause alterClause, OlapTable ol | ||
| if (targetIndexName == null) { | ||
| targetIndexName = baseIndexName; | ||
| } | ||
| long targetIndexId = olapTable.getIndexIdByName(targetIndexName); | ||
| LinkedList<Column> newSchema = new LinkedList<Column>(); | ||
| List<Column> targetIndexSchema = indexSchemaMap.get(targetIndexId); | ||
| // When rollup is specified, there is no need to check the order of generated columns. | ||
| // When rollup is not specified and the order of baseIndex needs to be modified, the order needs to be checked. | ||
| if (alterClause.getRollupName() == null) { | ||
| checkOrder(targetIndexSchema, orderedColNames); | ||
| } | ||
| // check and create new ordered column list | ||
| Set<String> colNameSet = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER); | ||
| for (String colName : orderedColNames) { | ||
| @@ -1004,6 +1029,10 @@ private boolean addColumnInternal(OlapTable olapTable, Column newColumn, ColumnP | ||
| } | ||
| } | ||
| if (newColumn.getGeneratedColumnInfo() != null) { | ||
| throw new DdlException("Not supporting alter table add generated columns."); | ||
| } | ||
| /* | ||
| * add new column to indexes. | ||
| * UNIQUE: | ||
| @@ -3194,4 +3223,61 @@ public boolean updateBinlogConfig(Database db, OlapTable olapTable, List<AlterCl | ||
| return false; | ||
| } | ||
| private void removeColumnWhenDropGeneratedColumn(Column dropColumn, Map<String, Column> nameToColumn) { | ||
| GeneratedColumnInfo generatedColumnInfo = dropColumn.getGeneratedColumnInfo(); | ||
| if (generatedColumnInfo == null) { | ||
| return; | ||
| } | ||
| String dropColName = dropColumn.getName(); | ||
| Expr expr = generatedColumnInfo.getExpr(); | ||
| Set<Expr> slotRefsInGeneratedExpr = new HashSet<>(); | ||
| expr.collect(e -> e instanceof SlotRef, slotRefsInGeneratedExpr); | ||
| for (Expr slotRef : slotRefsInGeneratedExpr) { | ||
| String name = ((SlotRef) slotRef).getColumnName(); | ||
| if (!nameToColumn.containsKey(name)) { | ||
| continue; | ||
| } | ||
| Column c = nameToColumn.get(name); | ||
| Set<String> sets = c.getGeneratedColumnsThatReferToThis(); | ||
| sets.remove(dropColName); | ||
| } | ||
| } | ||
| private void checkOrder(List<Column> targetIndexSchema, List<String> orderedColNames) throws DdlException { | ||
| Set<String> nameSet = new HashSet<>(); | ||
| for (Column column : targetIndexSchema) { | ||
| if (column.isVisible() && null == column.getGeneratedColumnInfo()) { | ||
| nameSet.add(column.getName()); | ||
| } | ||
| } | ||
| for (String colName : orderedColNames) { | ||
| Column oneCol = null; | ||
| for (Column column : targetIndexSchema) { | ||
| if (column.getName().equalsIgnoreCase(colName) && column.isVisible()) { | ||
| oneCol = column; | ||
| break; | ||
| } | ||
| } | ||
| if (oneCol == null) { | ||
| throw new DdlException("Column[" + colName + "] not exists"); | ||
| } | ||
| if (null == oneCol.getGeneratedColumnInfo()) { | ||
| continue; | ||
| } | ||
| Expr expr = oneCol.getGeneratedColumnInfo().getExpr(); | ||
| Set<Expr> slotRefsInGeneratedExpr = new HashSet<>(); | ||
| expr.collect(e -> e instanceof SlotRef, slotRefsInGeneratedExpr); | ||
| for (Expr slotRef : slotRefsInGeneratedExpr) { | ||
| String slotName = ((SlotRef) slotRef).getColumnName(); | ||
| if (!nameSet.contains(slotName)) { | ||
| throw new DdlException("The specified column order is incorrect, `" + colName | ||
| + "` should come after `" + slotName | ||
| + "`, because both of them are generated columns, and `" | ||
| + colName + "` refers to `" + slotName + "`."); | ||
| } | ||
| } | ||
| nameSet.add(colName); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.