-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Support Alter Table Clause For External Table #4699
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
Conversation
| case MYSQL: | ||
| case ELASTICSEARCH: | ||
| processAlterExternalTable(stmt, table, db); | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use return instead of break is more clear
| /* | ||
| * entry function. handle alter ops for external table | ||
| */ | ||
| public void process(List<AlterClause> alterClauses, Database db, Table externalTable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processExternalTable is more clear
|
|
||
| List<Column> modIndexSchema = externalTable.getBaseSchema(); | ||
| addColumnInternal(externalTable, column, columnPos, modIndexSchema, newColNameSet); | ||
| externalTable.setNewFullSchema(modIndexSchema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not set new schema to externalTable here directly.
The other alter clause may throw exception and the entire alter operation will fail, and you have to rollback all changes to the table.
A correct way to to modify a "copied" schema of external table, and set the new schema at the end of all alter clauses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it is a problem。I will set the new schema at the end of alter external table.
| LOG.info("rename table[{}] to {}", tableName, newTableName); | ||
| } | ||
|
|
||
| public void reflushTable(Database db, Table table) throws DdlException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good way to alter external table.
You write 2 edit logs here, which will make this operation non-atomic。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,to make sure it is atomic. We may need add a new OperationType in edit log.
|
This PR can also be applied with |
| } | ||
| } | ||
|
|
||
| private void processRename(Database db, Table table, List<AlterClause> alterClauses) throws DdlException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private void processRename(Database db, Table table, List<AlterClause> alterClauses) throws DdlException { | |
| private void processRenameAlterOperation(Database db, Table table, List<AlterClause> alterClauses) throws DdlException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wuyunfeng hi,yunfeng. I just want keep the function name same to the olaptable alter function name.
| public static final short OP_DROP_RESOURCE = 277; | ||
|
|
||
| // alter external table | ||
| public static final short OP_REFRESH_EXTERNAL_TABLE_SCHEMA = 280; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just puzzled with the refresh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK,I will change the name of this operationType
| indexSchemaMap, newColNameSet); | ||
| } | ||
|
|
||
| private void processAddColumn(AddColumnClause alterClause, Table externalTable, List<Column> newSchema) throws DdlException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private void processAddColumn(AddColumnClause alterClause, Table externalTable, List<Column> newSchema) throws DdlException { | |
| private void processAddCol{Alter}Operation(AddColumnClause alterClause, Table externalTable, List<Column> newSchema) throws DdlException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi,yunfeng. I just want keep the function name same to the olaptable alter function name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's ok
5 alter operation be supported: * RENAME * ADD COLUMN * DROP COLUMN * MODIFY COLUMN * REORDER COLUMN
1. copy old schema to new schema before external table schema change 2. add new operation of OP_REFRESH_EXTERNAL_TABLE_SCHEMA
| } | ||
| } | ||
|
|
||
| public void refreshTableSchemaWithLock(String tableName, List<Column> newSchema, boolean isReplay) throws DdlException{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the param isReplay seems always true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, so I will del it.
| public class RefreshExternalTableInfo implements Writable { | ||
| public static final Logger LOG = LoggerFactory.getLogger(RefreshExternalTableInfo.class); | ||
|
|
||
| private String dbName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use GSON
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, Firstly I try use GSON to do serialization. But failed when I need to deserialize the newSchema. It seems Column cause the problem.
| LOG.info("rename table[{}] to {}", tableName, newTableName); | ||
| } | ||
|
|
||
| public void renameTable(Database db, Table table, TableRenameClause tableRenameClause) throws DdlException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is just same as renameTable above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but the param is different. one is the olaptable, this is table
morningman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Support Alter Table Clause For External Table 5 alter operation be supported: * RENAME * ADD COLUMN * DROP COLUMN * MODIFY COLUMN * REORDER COLUMN
5 alter operation be supported:
Fix #4697
Types of changes
What types of changes does your code introduce to Doris?
Put an
xin the boxes that applyChecklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.