Skip to content

Conversation

@PingLiuPing
Copy link
Collaborator

Add Iceberg partition path utility for partition path naming.
Introduces IcebergPartitionPath, a utility class that converts partition keys to
their string representations for use in Iceberg partition directory paths.
The implementation follows the behavior of the Apache Iceberg Java library.

@netlify
Copy link

netlify bot commented Nov 7, 2025

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 2dee873
🔍 Latest deploy log https://app.netlify.com/projects/meta-velox/deploys/690fb485febddc0008c9ef93

@meta-cla meta-cla 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 Nov 7, 2025
std::string toPartitionString(int32_t value, const TypePtr& type)
const override;

/// Converts a Timestamp partition key to its string representation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Converts a Timestamp partition key to its string representation.

This sentence is redundant. Consider dropping.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks


namespace facebook::velox::connector::hive::iceberg {

constexpr int32_t kEpochYear = 1970;
Copy link
Contributor

Choose a reason for hiding this comment

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

move this into the only function where it is used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks.

if (type->isDate()) {
return DATE()->toString(value);
}
return folly::to<std::string>(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: fmt::to_string

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks.

}
}

std::string IcebergPartitionPath::toPartitionString(
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps, add a check for transform type. I assume it must be kIdentity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are right

EXPECT_EQ(
test(
TransformType::kIdentity,
StringView("\x48\x65\x6c\x6c\x6f"),
Copy link
Contributor

Choose a reason for hiding this comment

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

consider adding helper method testVarbinary that takes a single std::string argument. This will make code shorter and easier to read and allow testing long strings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the suggestion.


TEST(IcebergPartitionPathTest, identityTimestamp) {
EXPECT_EQ(
test(TransformType::kIdentity, Timestamp(0, 0), TIMESTAMP()),
Copy link
Contributor

Choose a reason for hiding this comment

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

add testTimestamp helper method that takes a single Timestamp argument

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks.


TEST(IcebergPartitionPathTest, truncateString) {
EXPECT_EQ(
test(TransformType::kTruncate, StringView("abc"), VARCHAR()), "abc");
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume tranform type doesn't matter here. The results would be the same for kIdentity and kTruncate. If so, consider adding a helper method testString(std::string) which converts string using kIdentity and kTruncate, assert that results are the same and returns that result.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks.
I added a helper function testString.

namespace {

template <typename T>
std::string test(TransformType transform, T value, const TypePtr& type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are not testing anything here, let's rename to something like toPath.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks.

@PingLiuPing PingLiuPing force-pushed the lp_iceberg_partition_path branch from 219ec2a to 2dee873 Compare November 8, 2025 21:22
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

Development

Successfully merging this pull request may close these issues.

2 participants