Skip to content

feat: Support TimestampNs and TimestampTzNs` in bucket transform #1150

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

Merged
merged 5 commits into from
Apr 2, 2025

Conversation

jonathanc-n
Copy link
Contributor

@jonathanc-n jonathanc-n commented Mar 31, 2025

Which issue does this PR close?

What changes are included in this PR?

Add bucket transforms for TimestampNs and TimestampTzNs`

Are these changes tested?

Unit tests

liurenjie1024
liurenjie1024 previously approved these changes Apr 1, 2025
Copy link
Contributor

@liurenjie1024 liurenjie1024 left a comment

Choose a reason for hiding this comment

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

Thanks @jonathanc-n for this pr, LGTM!

kevinjqliu
kevinjqliu previously approved these changes Apr 1, 2025
Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -167,6 +167,16 @@ impl TransformFunction for Bucket {
.downcast_ref::<arrow_array::TimestampMicrosecondArray>()
.unwrap()
.unary(|v| self.bucket_timestamp(v)),
DataType::Time64(TimeUnit::Nanosecond) => input
Copy link
Contributor

Choose a reason for hiding this comment

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

in pyiceberg, TimestampNanoType in converted to micros precision before bucketing. This is to ensure that TimestampType and TimestampNanoType are transformed to the same value

https://github.com/apache/iceberg-python/blob/4d4714a46241d0d89519a2a605dbce27b713a60e/pyiceberg/transforms.py#L322-L340

I think we should add a test to ensure this here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, It wasn't performing this conversion. The test is added

@kevinjqliu
Copy link
Contributor

@Fokko FYI new transform function we can use for apache/iceberg-python#1833

@jonathanc-n jonathanc-n dismissed stale reviews from kevinjqliu and liurenjie1024 via 54d001b April 1, 2025 20:31
kevinjqliu
kevinjqliu previously approved these changes Apr 1, 2025
Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

LGTM!

.as_any()
.downcast_ref::<arrow_array::Time64NanosecondArray>()
.unwrap()
.unary(|v| self.bucket_time(v / 1000)),
Copy link
Contributor

Choose a reason for hiding this comment

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

there was an issue with rounding when performing division for the hour transform (#1146)
but since we're dividing by 1000, i dont think the same issue applies here

.transform_literal(&Datum::timestamp_nanos(ns_value))
.unwrap()
.unwrap(),
Datum::int(79)
Copy link
Contributor

Choose a reason for hiding this comment

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

hm, since we're using the same time (1510871468000000) here
should the bucket value for bucket(100) transform be the same for this test and the test above (test_timestamptz_literal)?

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 I applied the conversion to the transform_literal as well

Copy link
Contributor

@ZENOTME ZENOTME left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @jonathanc-n

Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

LGTM thanks for adding the additional checks

Copy link
Contributor

@liurenjie1024 liurenjie1024 left a comment

Choose a reason for hiding this comment

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

Thanks @jonathanc-n for fixing this, and @kevinjqliu for the review

@liurenjie1024 liurenjie1024 merged commit f17dd4d into apache:main Apr 2, 2025
17 checks passed
@jonathanc-n jonathanc-n deleted the add-ts branch April 2, 2025 21:58
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.

Introduce TimestampNs, TimestampTzNs support for Bucket transforms
4 participants