You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Transforming timestamp to date should produce date #279
The output type of transforming a timestamp to a date Transforms.day(Types.TimestampType.withZone() is an integer, but should be a date. That way, it will be formatted as a date in metadata tables.
When this is updated, we need to validate backward compatibility with existing tables.
Hi @rdblue please correct me if I am wrong:
I am not sure if Transforms.day() is the function to transfer timestamps to date, it is to produce Dates.DAY or Timestamp.DAY (either is Transform) from Types.DateType or Types.TimestampType. By this issue, are you proposing a new method in Transforms which returns Transform<T, java.util.Date> from Types.DateType or Types.TimestampType?
@waterlx, the day transform reports that its return type is IntegerType.get(), but it should be DateType.get(). Both are stored as integers but the transform actually produces the internal value that represents a date: the number of days from the unix epoch.
Changing the return type to date should be safe and would cause engines that support the metadata tables to format the values correctly as dates instead of as integers.
@timmylicheng, the compatibility checks just need to verify that older tables that are partitioned by day can still be read. It's just a matter of writing a table with the current master, making this change and reading with the new library. We don't expect any exceptions while reading or filtering after the update.
@rdblue if Im not missing, in this case org.apache.iceberg.transforms.Timestamps will implement Transform<Long, Date> and org.apache.iceberg.transforms.Dates will implement Transform<Integer, Date>.
and internally these classes will use Date object for various transformation like apply , toHumanString.
@manishmalhotrawork, only the day transform should return a date. Years, months, and hours should continue returning ordinals like before.
so you mean that we are supposed to keep org.apache.iceberg.transforms.Timestamps as it is (as Transform<Long, Integer>) and keep org.apache.iceberg.transforms.Dates as it is (as Transform<Integer, Integer>), so as not to change the return of Transforms.year(), month() and hour()? Do you propose to only change the output of Transforms.day() to Transform<T, Date>? Do I get it right?
@manishmalhotrawork yes, I am working on this issue. But please feel free to go ahead to share your thoughts or upload patches, I am new to iceberg
Sorry for the confusion. I'm talking about the Iceberg date type, Types.DateType.get(). The transform implementation is still going to return a Java Integer because that's how dates are represented in Iceberg metadata: the number of days from the Unix epoch.
This change would primarily just update getResultType and return DateType.get() when the granularity is ChronoUnit.DAYS. That will cause the partition tuple's field type to be a date, which should also cause the metadata table to display formatted dates instead of the day ordinal in Spark.
This change would primarily just update getResultType and return DateType.get() when the granularity is ChronoUnit.DAYS.
this is bit more clear now. thanks !
so this will change ( if granularity is Days)
Dates.getResultType
public Type getResultType(Type sourceType) {
return Types.IntegerType.get();
}
and what about Timestamps.getResultType , does it also needs to return Types.DateType.get() , as that can also be needed to print datetime in metadata table. ?
@rdblue thanks for the answer.
Just saw messages, before that I also drafted the patch, waiting for internal approval. @waterlx I can push, and then you can also review? Or otherwise please let me know.
while validating my changes, didn't see that transfor.getResultType is being used apart from PartitionSpec.partitionType().
can you point me to any other test-case or code path, where its being used can be verified.
( though Im adding test-cases to validate Days.getResultType() and Timestamps.getResultType())
If we are returning DateType.get for Days why not for Month/Year as well. As for those types as well it will return Integer/day ordinal?
That will cause the partition tuple's field type to be a date, which should also cause the metadata table to display formatted dates instead of the day ordinal in Spark.
I believe metadata table referenced here is related to #252? Anything specific I need to test/validate if this change impacts the metadata tables?
Hi @rdblue , I am not sure if the table of "partition transforms" on the doc needs to update to reflect this change. The row of "day" of the table. Would you please advice? Thanks!
Activity
electrum commentedon Jul 17, 2019
Should
dayalso not support thedatetype, since that would be an identity transform?rdblue commentedon Jul 17, 2019
You're probably right, although there shouldn't be a difference between the two in practice, once strict projection for dates is added.
timmylicheng commentedon Jul 22, 2019
What are suggested ways to validate backward compatibility?
waterlx commentedon Aug 8, 2019
Hi @rdblue please correct me if I am wrong:
I am not sure if Transforms.day() is the function to transfer timestamps to date, it is to produce Dates.DAY or Timestamp.DAY (either is Transform) from Types.DateType or Types.TimestampType. By this issue, are you proposing a new method in Transforms which returns Transform<T, java.util.Date> from Types.DateType or Types.TimestampType?
electrum commentedon Aug 8, 2019
Use
java.time.LocalDate. The olderjava.util.Dateactually represents an instant.rdblue commentedon Aug 8, 2019
@waterlx, the day transform reports that its return type is
IntegerType.get(), but it should beDateType.get(). Both are stored as integers but the transform actually produces the internal value that represents a date: the number of days from the unix epoch.Changing the return type to date should be safe and would cause engines that support the metadata tables to format the values correctly as dates instead of as integers.
@timmylicheng, the compatibility checks just need to verify that older tables that are partitioned by day can still be read. It's just a matter of writing a table with the current master, making this change and reading with the new library. We don't expect any exceptions while reading or filtering after the update.
manishmalhotrawork commentedon Aug 12, 2019
@rdblue if Im not missing, in this case
org.apache.iceberg.transforms.Timestampswill implementTransform<Long, Date>andorg.apache.iceberg.transforms.Dateswill implementTransform<Integer, Date>.and internally these classes will use Date object for various transformation like
apply,toHumanString.@waterlx are you working on this issue ?
rdblue commentedon Aug 12, 2019
@manishmalhotrawork, only the
daytransform should return a date. Years, months, and hours should continue returning ordinals like before.waterlx commentedon Aug 14, 2019
@rdblue, regarding
so you mean that we are supposed to keep
org.apache.iceberg.transforms.Timestampsas it is (asTransform<Long, Integer>) and keeporg.apache.iceberg.transforms.Datesas it is (asTransform<Integer, Integer>), so as not to change the return ofTransforms.year(), month() and hour()? Do you propose to only change the output of Transforms.day() toTransform<T, Date>? Do I get it right?@manishmalhotrawork yes, I am working on this issue. But please feel free to go ahead to share your thoughts or upload patches, I am new to iceberg
rdblue commentedon Aug 14, 2019
Sorry for the confusion. I'm talking about the Iceberg date type,
Types.DateType.get(). The transform implementation is still going to return a JavaIntegerbecause that's how dates are represented in Iceberg metadata: the number of days from the Unix epoch.This change would primarily just update
getResultTypeand returnDateType.get()when the granularity isChronoUnit.DAYS. That will cause the partition tuple's field type to be a date, which should also cause the metadata table to display formatted dates instead of the day ordinal in Spark.manishmalhotrawork commentedon Aug 16, 2019
@rdblue
this is bit more clear now. thanks !
so this will change ( if granularity is Days)
Dates.getResultTypeand what about
Timestamps.getResultType, does it also needs to returnTypes.DateType.get(), as that can also be needed to print datetime in metadata table. ?rdblue commentedon Aug 16, 2019
Yes, I think both should return
DateTypewaterlx commentedon Aug 17, 2019
Thanks for the clarification, Ryan! I am drafting the patch.
manishmalhotrawork commentedon Aug 18, 2019
@rdblue thanks for the answer.
Just saw messages, before that I also drafted the patch, waiting for internal approval.
@waterlx I can push, and then you can also review? Or otherwise please let me know.
manishmalhotrawork commentedon Aug 19, 2019
@rdblue quick questions.
PartitionSpec.partitionType().can you point me to any other test-case or code path, where its being used can be verified.
( though Im adding test-cases to validate
Days.getResultType()andTimestamps.getResultType())If we are returning DateType.get for Days why not for Month/Year as well. As for those types as well it will return Integer/day ordinal?
I believe metadata table referenced here is related to #252? Anything specific I need to test/validate if this change impacts the metadata tables?
rdblue commentedon Aug 20, 2019
There might not be one. Thanks for adding tests!
The values for those aren't stored as dates. For example, 1990 is stored as 20.
Existing tests should cover it. The change should automatically update the Spark representation as well. Just fix any test failures, if there are any.
manishmalhotrawork commentedon Aug 30, 2019
@rdblue , wondering if this issue is resolved by the #424 ?
rdblue commentedon Aug 30, 2019
Yep. Thank you!
waterlx commentedon Sep 3, 2019
Hi @rdblue , I am not sure if the table of "partition transforms" on the doc needs to update to reflect this change. The row of "day" of the table. Would you please advice? Thanks!
rdblue commentedon Sep 3, 2019
@waterlx, I think you're right. We should update that line. Do you want to open a PR?
waterlx commentedon Sep 4, 2019
Hi @rdblue , would you please review PR #447 at your most convenience? Thanks!