Skip to content
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

feat: Support to specify partition key order in TableWrite operator #12355

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JkSelf
Copy link
Collaborator

@JkSelf JkSelf commented Feb 17, 2025

Fix apache/incubator-gluten#8663

The HiveDataSink generates partition directories based on the partition index derived from the input RowVector. Currently, the partition index is constructed by traversing the RowVector to determine if a column is partitioned. This approach can lead to a mismatch in partition key order if it differs from the order in the RowVector. For instance, if the input RowVector is (a, b, c) and the partition key is set as (b, a), Velox will create directories as(a={}/b={})based on the existing logic. This does not align with Spark's partition directory format, which would be (b={}/a={}). To address this, we have introduced a partitionKey parameter in the HiveInsertTableHandle. This allows us to generate the partition index according to the specified partitionKey order, ensuring alignment with the user's desired partition key sequence.

@JkSelf JkSelf requested a review from majetideepak as a code owner February 17, 2025 08:59
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 17, 2025
Copy link

netlify bot commented Feb 17, 2025

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit fd74b97
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/67b6a7f895c1340008ad642e

@JkSelf
Copy link
Collaborator Author

JkSelf commented Feb 17, 2025

@majetideepak Can you help to review this PR? Thanks for your help.

@@ -300,6 +306,7 @@ class HiveInsertTableHandle : public ConnectorInsertTableHandle {
const std::unordered_map<std::string, std::string> serdeParameters_;
const std::shared_ptr<dwio::common::WriterOptions> writerOptions_;
const bool ensureFiles_;
const std::vector<std::string> partitionKeys_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this used? I don't think Velox needs to be aware of these, it's not Velox who is creating the directories.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Yuhta Thanks for your review.

The HiveDataSink generates partition directories based on the partition index derived from the input RowVector. Currently, the partition index is constructed by traversing the RowVector to determine if a column is partitioned. This approach can lead to a mismatch in partition key order if it differs from the order in the RowVector. For instance, if the input RowVector is (a, b, c) and the partition key is set as (b, a), Velox will create directories as (a={}/b={}) based on the existing logic. This does not align with Spark's partition directory format, which would be (b={}/a={}). To address this, we have introduced a partitionKey parameter in the HiveInsertTableHandle. This allows us to generate the partition index according to the specified partitionKey order, ensuring alignment with the user's desired partition key sequence.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, can we rename this method to partitionKeyOrder()? And comment that if specified, we use this order, otherwise we use the column order

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Yuhta Yes. Updated the method name to partitionKeyOrder(). And also added the related comments.

@@ -300,6 +306,7 @@ class HiveInsertTableHandle : public ConnectorInsertTableHandle {
const std::unordered_map<std::string, std::string> serdeParameters_;
const std::shared_ptr<dwio::common::WriterOptions> writerOptions_;
const bool ensureFiles_;
const std::vector<std::string> partitionKeys_;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see, can we rename this method to partitionKeyOrder()? And comment that if specified, we use this order, otherwise we use the column order

@JkSelf
Copy link
Collaborator Author

JkSelf commented Feb 19, 2025

@Yuhta I have resolved all your comments. Can you help to review again? Thanks.

@majetideepak
Copy link
Collaborator

@JkSelf There are build failures. Can you take a look?

if (partitionKeyOrder_.size() > 0) {
// Ensure the partitionKeyOrder contains all the partition keys in
// inputColumns_.
std::string partitionKeyNames;
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to also check there is no repetition. Something like

folly::F14FastSet<std::string> partitionKeyNames(partitionKeyOrder_.begin(), partitionKeyOrder_.end());
//...
VELOX_CHECK(partitionKeyNames.erase(inputColumn->name()) == 1);
//...
VELOX_CHECK(partitionKeyNames.empty());

Also in Presto we have convention to put all partitioning columns at the beginning of the RowVector in the right order. Is there anything in Spark preventing us from doing so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Yuhta There is no such convention in Spark to put the partition columns at the beginning of the input columns.

@JkSelf
Copy link
Collaborator Author

JkSelf commented Feb 20, 2025

@Yuhta @majetideepak Can you help to review again? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
4 participants