Skip to content

Conversation

@HappenLee
Copy link
Contributor

5 alter operation be supported:

  • RENAME
  • ADD COLUMN
  • DROP COLUMN
  • MODIFY COLUMN
  • REORDER COLUMN

Fix #4697

Types of changes

What types of changes does your code introduce to Doris?
Put an x in the boxes that apply

  • [] Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] Documentation Update (if none of the other choices apply)
  • [] Code refactor (Modify the code structure, format the code, etc...)

Checklist

Put an x in 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.

  • I have create an issue on (Fix #ISSUE), and have described the bug/feature there in detail
  • Compiling and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • If this change need a document change, I have updated the document
  • Any dependent changes have been merged

case MYSQL:
case ELASTICSEARCH:
processAlterExternalTable(stmt, table, db);
break;
Copy link
Contributor

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)
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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。

Copy link
Contributor Author

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.

@wuyunfeng wuyunfeng added the area/sql Issues or PRs related to SQL label Oct 10, 2020
@wuyunfeng wuyunfeng linked an issue Oct 10, 2020 that may be closed by this pull request
14 tasks
@wuyunfeng
Copy link
Member

This PR can also be applied with Elasticsearch external table. This is so good

@wuyunfeng wuyunfeng added area/doris-on-es Issues or PRs related to Doris on ElasticSearch kind/datasource Issuses or PRs for external datasource area/schema-change Issues or PRs related to schema change labels Oct 10, 2020
}
}

private void processRename(Database db, Table table, List<AlterClause> alterClauses) throws DdlException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void processRename(Database db, Table table, List<AlterClause> alterClauses) throws DdlException {
private void processRenameAlterOperation(Database db, Table table, List<AlterClause> alterClauses) throws DdlException {

Copy link
Contributor Author

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;
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {

Copy link
Contributor Author

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.

Copy link
Member

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{
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use GSON

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@morningman morningman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@morningman morningman added the approved Indicates a PR has been approved by one committer. label Oct 23, 2020
@morningman morningman merged commit f89b660 into apache:master Oct 25, 2020
caoyang10 pushed a commit to caoyang10/incubator-doris that referenced this pull request Oct 29, 2020
* Support Alter Table Clause For External Table
5 alter operation be supported:

* RENAME
* ADD COLUMN
* DROP COLUMN
* MODIFY COLUMN
* REORDER COLUMN
@yangzhg yangzhg mentioned this pull request Feb 9, 2021
Gabriel39 added a commit to Gabriel39/incubator-doris that referenced this pull request Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. area/doris-on-es Issues or PRs related to Doris on ElasticSearch area/schema-change Issues or PRs related to schema change area/sql Issues or PRs related to SQL kind/datasource Issuses or PRs for external datasource

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proposal] Support Alter Table Clause For External Table(Eg:ODBC table, ES table).

3 participants