Skip to content

Transforming timestamp to date should produce date #279

Closed

Description

@rdblue

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.

Activity

  1. added
    good first issue
    on Jul 13, 2019
  2. electrum commented on Jul 17, 2019

    @electrum
    Contributor

    Should day also not support the date type, since that would be an identity transform?

  3. rdblue commented on Jul 17, 2019

    @rdblue
    ContributorAuthor

    You're probably right, although there shouldn't be a difference between the two in practice, once strict projection for dates is added.

  4. timmylicheng commented on Jul 22, 2019

    @timmylicheng
    Contributor

    What are suggested ways to validate backward compatibility?

  5. waterlx commented on Aug 8, 2019

    @waterlx
    Contributor

    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?

  6. electrum commented on Aug 8, 2019

    @electrum
    Contributor

    Use java.time.LocalDate. The older java.util.Date actually represents an instant.

  7. rdblue commented on Aug 8, 2019

    @rdblue
    ContributorAuthor

    @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.

  8. manishmalhotrawork commented on Aug 12, 2019

    @manishmalhotrawork
    Contributor

    @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.

    @waterlx are you working on this issue ?

  9. rdblue commented on Aug 12, 2019

    @rdblue
    ContributorAuthor

    @manishmalhotrawork, only the day transform should return a date. Years, months, and hours should continue returning ordinals like before.

  10. waterlx commented on Aug 14, 2019

    @waterlx
    Contributor

    @rdblue, regarding

    @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

  11. rdblue commented on Aug 14, 2019

    @rdblue
    ContributorAuthor

    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.

  12. manishmalhotrawork commented on Aug 16, 2019

    @manishmalhotrawork
    Contributor

    @rdblue

    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)

    1. 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. ?

  13. rdblue commented on Aug 16, 2019

    @rdblue
    ContributorAuthor

    Yes, I think both should return DateType

  14. waterlx commented on Aug 17, 2019

    @waterlx
    Contributor

    Thanks for the clarification, Ryan! I am drafting the patch.

  15. manishmalhotrawork commented on Aug 18, 2019

    @manishmalhotrawork
    Contributor

    @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.

  16. manishmalhotrawork commented on Aug 19, 2019

    @manishmalhotrawork
    Contributor

    @rdblue quick questions.

    1. 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())

    1. 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?

  17. rdblue commented on Aug 20, 2019

    @rdblue
    ContributorAuthor

    can you point me to any other test-case or code path, where [getResultType] is being used can be verified.

    There might not be one. Thanks for adding tests!

    If we are returning DateType.get for Days why not for Month/Year as well

    The values for those aren't stored as dates. For example, 1990 is stored as 20.

    Anything specific I need to test/validate if this change impacts the metadata tables?

    Existing tests should cover it. The change should automatically update the Spark representation as well. Just fix any test failures, if there are any.

  18. manishmalhotrawork commented on Aug 30, 2019

    @manishmalhotrawork
    Contributor

    @rdblue , wondering if this issue is resolved by the #424 ?

  19. rdblue commented on Aug 30, 2019

    @rdblue
    ContributorAuthor

    Yep. Thank you!

  20. waterlx commented on Sep 3, 2019

    @waterlx
    Contributor

    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!

  21. rdblue commented on Sep 3, 2019

    @rdblue
    ContributorAuthor

    @waterlx, I think you're right. We should update that line. Do you want to open a PR?

  22. waterlx commented on Sep 4, 2019

    @waterlx
    Contributor

    Hi @rdblue , would you please review PR #447 at your most convenience? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions