Skip to content

[Kernel][Clustering #4] add withClusteringColumn api - #4327

Merged
vkorukanti merged 9 commits into
delta-io:masterfrom
KaiqiJinWow:stack/add_cluster_api
Apr 4, 2025
Merged

[Kernel][Clustering #4] add withClusteringColumn api#4327
vkorukanti merged 9 commits into
delta-io:masterfrom
KaiqiJinWow:stack/add_cluster_api

Conversation

@KaiqiJinWow

@KaiqiJinWow KaiqiJinWow commented Mar 26, 2025

Copy link
Copy Markdown
Collaborator

Which Delta project/connector is this regarding?

  • Spark
  • Standalone
  • Flink
  • Kernel
  • Other (fill in here)

Description

Split the main PR #4265 for faster review

This PR implement the withClusteringColumn API in kernel to support table creation as a clustered table.

It contains steps below,

  1. withClusteringColumn takes logicalColumns as input
  2. validation (column exist and cannot present together with partitionColumns)
  3. Update the protocol to include clustering writer feature
  4. convert the logical column name to physical column names to create a metadataDomain
  5. Add the domainMetadata to domainMetadatasAdded.

How was this patch tested?

Does this PR introduce any user-facing changes?

@KaiqiJinWow
KaiqiJinWow force-pushed the stack/add_cluster_api branch 4 times, most recently from 5078c57 to 992276f Compare March 27, 2025 01:55
Comment thread kernel/kernel-api/src/main/java/io/delta/kernel/internal/util/SchemaUtils.java Outdated
Comment on lines +50 to +55
createTxn(
engine,
tablePath,
isNewTable = true,
testPartitionSchema,
clusteringCols = List(new Column("PART1"), new Column("part3")))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we use the createEmptyTable utility?

verifyWrittenContent(tablePath, testPartitionSchema, expData)
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

negative cases where data files with no stats for the clustering columns are added?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

case where invalid clustering column is provided?

@KaiqiJinWow
KaiqiJinWow force-pushed the stack/add_cluster_api branch 2 times, most recently from 5ae3e47 to 0c62a1b Compare April 3, 2025 00:22
@KaiqiJinWow
KaiqiJinWow force-pushed the stack/add_cluster_api branch from b70e55e to 9223241 Compare April 3, 2025 04:29
@KaiqiJinWow KaiqiJinWow changed the title [Kernel][Clustering #5] add withClusteringColumn api [Kernel][Clustering #4] add withClusteringColumn api Apr 3, 2025
Comment thread kernel/kernel-api/src/main/java/io/delta/kernel/internal/TransactionImpl.java Outdated

/**
* Get the domain metadata for the clustering columns. If column mapping is enabled, pass the list
* of physical names assigned; otherwise, use the logical column names.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this comment still relevant?
`If column mapping is enabled, pass the list

  • of physical names assigned; otherwise, use the logical column names.`

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, different type of column name passed dependent on column mapping is enabled or not.

@raveeram-db raveeram-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM except for a few nits!

@vkorukanti vkorukanti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Schema changes PR just went it, once rebased please check if we need to add any validations on schema changes on clsutering columns. To merge this, we could make a change in this PR to block schema changes when the table has clsutering columns. And followup with a new PR to support the schema change with clustering columns.

Comment thread kernel/kernel-api/src/main/java/io/delta/kernel/internal/util/SchemaUtils.java Outdated

@vkorukanti vkorukanti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment on lines +373 to +376
throw new KernelException(
format(
"Cannot update schema for table with clustering columns %s",
clusteringColumns.get()));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just say not yet supported

.add("c", StringType.STRING, true, currentSchema.get("c").getMetadata)
.add("a", StringType.STRING, true, currentSchema.get("a").getMetadata)

assertSchemaEvolutionFails[IllegalArgumentException](

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we are throwing KernelException here, how come we are expecting illegal argument exception?

@vkorukanti
vkorukanti merged commit b5b5f6f into delta-io:master Apr 4, 2025

@allisonport-db allisonport-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good 1 comment for clarity

}

/**
* Verify the clustering columns exists in the table schema.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you update these docs that it converts to physical name please? At least I think that's what's happening right?

huan233usc pushed a commit to huan233usc/delta that referenced this pull request Apr 11, 2025
<!--
Thanks for sending a pull request!  Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://github.com/delta-io/delta/blob/master/CONTRIBUTING.md
2. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]
Your PR title ...'.
  3. Be sure to keep the PR description updated to reflect all changes.
  4. Please write your PR title to summarize what this PR proposes.
5. If possible, provide a concise example to reproduce the issue for a
faster review.
6. If applicable, include the corresponding issue number in the PR title
and link it in the body.
-->

#### Which Delta project/connector is this regarding?
<!--
Please add the component selected below to the beginning of the pull
request title
For example: [Spark] Title of my pull request
-->

- [ ] Spark
- [ ] Standalone
- [ ] Flink
- [x] Kernel
- [ ] Other (fill in here)

## Description

<!--
- Describe what this PR changes.
- Describe why we need the change.

If this PR resolves an issue be sure to include "Resolves #XXX" to
correctly link and close the issue upon merge.
-->

Split the main PR delta-io#4265 for faster
review

This PR implement the `withClusteringColumn` API in kernel to support
table creation as a clustered table.

It contains steps below,

1. withClusteringColumn takes logicalColumns as input
2. validation (column exist and cannot present together with
partitionColumns)
3. Update the protocol to include `clustering` writer feature
4. convert the logical column name to physical column names to create a
metadataDomain
5. Add the domainMetadata to domainMetadatasAdded.

## How was this patch tested?

<!--
If tests were added, say they were added here. Please make sure to test
the changes thoroughly including negative and positive cases if
possible.
If the changes were tested in any way other than unit tests, please
clarify how you tested step by step (ideally copy and paste-able, so
that other reviewers can test and check, and descendants can verify in
the future).
If the changes were not tested, please explain why.
-->

## Does this PR introduce _any_ user-facing changes?

<!--
If yes, please clarify the previous behavior and the change this PR
proposes - provide the console output, description and/or an example to
show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change
compared to the released Delta Lake versions or within the unreleased
branches such as master.
If no, write 'No'.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants