Skip to content

Commit

Permalink
support FE schema change
Browse files Browse the repository at this point in the history
  • Loading branch information
eldenmoon committed Jun 30, 2023
1 parent d9c02e8 commit e0f16fe
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,17 @@ private boolean addColumnInternal(OlapTable olapTable, Column newColumn, ColumnP
* ADD COLUMN k1 int to rollup1,
* ADD COLUMN k1 int to rollup2
* So that k1 will be added to base index 'twice', and we just ignore this repeat adding.
*
*/
private void checkAndAddColumn(List<Column> modIndexSchema, Column newColumn, ColumnPosition columnPos,
Set<String> newColNameSet, boolean isBaseIndex, int newColumnUniqueId)
Set<String> newColNameSet, boolean isBaseIndex,
int newColumnUniqueId)
throws DdlException {
int posIndex = -1;
int lastVisibleIdx = -1;
String newColName = newColumn.getName();
boolean hasPos = (columnPos != null && !columnPos.isFirst());
Column parentColumn = null;
for (int i = 0; i < modIndexSchema.size(); i++) {
Column col = modIndexSchema.get(i);
if (col.getName().equalsIgnoreCase(newColName)) {
Expand Down Expand Up @@ -1124,13 +1127,22 @@ private void checkAndAddColumn(List<Column> modIndexSchema, Column newColumn, Co
posIndex = i;
}
}
// Find target parent column
if (newColumn.getParentUniqueId() > 0 && col.getUniqueId() == newColumn.getParentUniqueId()) {
parentColumn = col;
}
}

// check if lastCol was found
if (hasPos && posIndex == -1) {
throw new DdlException("Column[" + columnPos.getLastCol() + "] does not found");
}

if (hasPos && newColumn.getParentUniqueId() > 0) {
throw new DdlException("Column[" + columnPos.getLastCol() + "] pos confilict");
}


// check if add to first
if (columnPos != null && columnPos.isFirst()) {
posIndex = -1;
Expand All @@ -1140,6 +1152,21 @@ private void checkAndAddColumn(List<Column> modIndexSchema, Column newColumn, Co
// newColumn may add to baseIndex or rollups, so we need copy before change UniqueId
Column toAddColumn = new Column(newColumn);
toAddColumn.setUniqueId(newColumnUniqueId);

// Not the target index
if (newColumn.getParentUniqueId() > 0 && parentColumn == null) {
LOG.debug("Not the target index, parentColUniqueId {}", newColumn.getParentUniqueId());
return;
}

// Directly add new sub column to this parent column, and ignore the reset operations
if (parentColumn != null) {
parentColumn.addChildrenColumn(toAddColumn);
LOG.debug("newSubColumn setUniqueId({}), modIndexSchema:{}, parentColum:{}",
newColumnUniqueId, modIndexSchema, parentColumn.getName());
return;
}

if (hasPos) {
modIndexSchema.add(posIndex + 1, toAddColumn);
} else if (toAddColumn.isKey()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public String getValue() {
private DefaultValue defaultValue;
private String comment;
private boolean visible;
private int parentUniqueId = -1;
private int uniqueId = -1;

public ColumnDef(String name, TypeDef typeDef) {
this(name, typeDef, false, null, false, false, DefaultValue.NOT_SET, "");
Expand Down Expand Up @@ -227,6 +229,22 @@ public void setGenericAggregationArguments(List<TypeDef> genericAggregationArgum
this.genericAggregationArguments = genericAggregationArguments;
}

public void setParentUniqueId(int colUniqueId) {
this.parentUniqueId = colUniqueId;
}

public int getParentUniqueId() {
return this.parentUniqueId;
}

public void setUniqueId(int colUniqueId) {
this.uniqueId = colUniqueId;
}

public int getUniqueId() {
return this.uniqueId;
}

public boolean isKey() {
return isKey;
}
Expand Down Expand Up @@ -517,9 +535,13 @@ public Column toColumn() {
type = Expr.createAggStateType(genericAggregationName, typeList, nullableList);
}

return new Column(name, type, isKey, aggregateType, isAllowNull, isAutoInc, defaultValue.value, comment,
Column col = new Column(name, type, isKey, aggregateType, isAllowNull, isAutoInc, defaultValue.value, comment,
visible, defaultValue.defaultValueExprDef, Column.COLUMN_UNIQUE_ID_INIT_VALUE, defaultValue.getValue(),
genericAggregationName, typeList, nullableList);
if (parentUniqueId > 0) {
col.setParentUniqueId(parentUniqueId);
}
return col;
}

@Override
Expand Down
13 changes: 12 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public class Column implements Writable, GsonPostProcessable {

private boolean isCompoundKey = false;

// Not persist this field since it's volatile
private int parentColUniqueId = -1;

public Column() {
this.name = "";
this.type = Type.NULL;
Expand Down Expand Up @@ -272,7 +275,7 @@ public List<Column> getChildren() {
return children;
}

private void addChildrenColumn(Column column) {
public void addChildrenColumn(Column column) {
this.children.add(column);
}

Expand Down Expand Up @@ -894,6 +897,14 @@ public int getUniqueId() {
return this.uniqueId;
}

public void setParentUniqueId(int colUniqueId) {
this.parentColUniqueId = colUniqueId;
}

public int getParentUniqueId() {
return this.parentColUniqueId;
}

public void setIndexFlag(TColumn tColumn, OlapTable olapTable) {
List<Index> indexes = olapTable.getIndexes();
for (Index index : indexes) {
Expand Down
Loading

0 comments on commit e0f16fe

Please sign in to comment.