Skip to content

[HUDI-6671] Support 'alter table add partition' sql#9408

Merged
danny0405 merged 4 commits intoapache:masterfrom
wecharyu:HUDI-6671
Aug 28, 2023
Merged

[HUDI-6671] Support 'alter table add partition' sql#9408
danny0405 merged 4 commits intoapache:masterfrom
wecharyu:HUDI-6671

Conversation

@wecharyu
Copy link
Contributor

@wecharyu wecharyu commented Aug 9, 2023

Change Logs

Hoodie does not support 'add partition' sql now, so we can not get partitions added by 'add partition' command.
In this patch, we implement add partition in Hoodie side:

  1. add new command AlterHoodieTableAddPartitionCommand
  2. add new unit test TestAlterTableAddPartition

Impact

No

Risk level (write none, low medium or high below)

Low

Documentation Update

Describe any necessary documentation update if there is any new feature, config, or user-facing change

  • The config description must be updated if new configs are added or the default value of the configs are changed
  • Any new feature or user-facing change requires updating the Hudi website. Please create a Jira ticket, attach the
    ticket number here and follow the instruction to make
    changes to the website.

Contributor's checklist

  • Read through contributor's guide
  • Change Logs and Impact were stated clearly
  • Adequate tests were added if applicable
  • CI passed

}
if (enableHiveStylePartitioning) {
partitionColumn + "=" + encodedPartitionValue
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why removing the handling of hive style partitioning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not remove it, just reuse the common implementation of makePartitionPath which will handle hive style and url encode.

override def run(sparkSession: SparkSession): Seq[Row] = {
val fullTableName = s"${tableIdentifier.database}.${tableIdentifier.table}"
logInfo(s"start execute alter table add partition command for $fullTableName")

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we check the existence of the table itself ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spark analysis will throw exception if table does not exist, so we do not need check it here.

class TestAlterTableAddPartition extends HoodieSparkSqlTestBase {

test("Add partition for non-partitioned table") {
val tableName = generateTableName
Copy link
Contributor

Choose a reason for hiding this comment

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

Use function withTable to clean it


override def run(sparkSession: SparkSession): Seq[Row] = {
val fullTableName = s"${tableIdentifier.database}.${tableIdentifier.table}"
logInfo(s"start execute alter table add partition command for $fullTableName")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can directly use tableIdentifier here since it already override the toString method(which is formatted)


// Sync new partitions in batch, enable ignoreIfExists to avoid sync failure.
val batchSize = sparkSession.sparkContext.conf.getInt("spark.sql.addPartitionInBatch.size", 100)
parts.toIterator.grouped(batchSize).foreach { batch =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we try catch here? Looks CreateHoodieTableCommand catch exception if syncing to HMS occurs error.

Copy link
Contributor

Choose a reason for hiding this comment

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

ping @danny0405 any thoughts for this? I see some commands catch the exception and only print warning(like CreateHoodieTableCommand), and some commands throw the exception out(like DropHoodieTableCommand, CreateHoodieTableAsSelectCommand)
Looks we don't have any standards whether throw exceptions if syncing to HMS occurs error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have no preference, if we throw exception for hive sync, will the table created be cleaned ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Like CreateHoodieTableAsSelectCommand, it would clean the created table, but some commands don't guarantee this.

Will print warning for AddPartitionCommand, looks it quite difficult to rollback partitions added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense to add a warning log, otherwise the exception will be displayed in client while we succeed add partition folder actually.

@wecharyu
Copy link
Contributor Author

@hudi-bot run azure

@danny0405 danny0405 self-assigned this Aug 22, 2023
@danny0405 danny0405 added the area:sql SQL interfaces label Aug 22, 2023
@wecharyu
Copy link
Contributor Author

@hudi-bot run azure

@wecharyu
Copy link
Contributor Author

@hudi-bot run azure

1 similar comment
@wecharyu
Copy link
Contributor Author

@hudi-bot run azure

@hudi-bot
Copy link
Collaborator

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

@danny0405 danny0405 merged commit 6e84cfe into apache:master Aug 28, 2023
leosanqing pushed a commit to leosanqing/hudi that referenced this pull request Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sql SQL interfaces

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants