Skip to content

Extend Iceberg metadata with SortOrder #317

Closed

Description

@aokolnychyi

Here is a short summary of the discussion on the dev list:

  • Iceberg should allow users to define a sort order in its metadata that applies to partitions.
  • We should never assume the sort order is actually applied to all files in the table, as that would require rewriting data immediately when we change the sort order.
  • Sort orders might evolve and change over time. When this happens, existing files will not be rewritten. Query engines should follow the updated sort order during subsequent writes. As a result, files within a table or partition can be sorted differently at a given point in time.
  • We should be able to define a sort order even for unpartitioned tables, as opposed to current Spark tables that allow a sort order only for bucketed tables.
  • SortOrder should be separate from PartitionSpec.
  • SortOrder will rely on transformations to define complex sort orders.
  • Files will be annotated with sort_order_id instead of sort_columns. We keep the question of file_ordinal open for now.
  • To begin with, we will support asc/desc natural sort orders (UTF8 ordering for Strings).

Activity

  1. aokolnychyi commented on Jul 29, 2019

    @aokolnychyi
    ContributorAuthor

    I'll submit a PR soon

  2. added this to the Row-level Delete milestone on Aug 7, 2019
  3. waterlx commented on Oct 21, 2019

    @waterlx
    Contributor

    Hi @aokolnychyi are you still working on the PR?
    By the way, regarding

    Sort orders might evolve and change over time. When this happens, existing files will not be rewritten. Query engines should follow the updated sort order during subsequent writes. As a result, files within a table or partition can be sorted differently at a given point in time.

    In terms of "changing sort order", do we only support adding new sort order, while it is prohibited to change existing sort orders (especially when they are tied by some data files)?
    If it is allowed to change an existing sort order, we could run into problems when visiting the old data files tied to it, right?

  4. aokolnychyi commented on Oct 21, 2019

    @aokolnychyi
    ContributorAuthor

    @waterlx I have started working on this, but then got distracted by our internal milestones. I hope to submit a PR by the end of this week.

    I think it makes sense to follow the same approach as we currently follow for partition spec evolution: we can keep a list of sort orders with their ids in the metadata and files will be annotated with sort_order_id. That way, we can always reconstruct the correct sort order for a file.

  5. waterlx commented on Oct 23, 2019

    @waterlx
    Contributor

    @aokolnychyi , thanks for sharing the progress!
    I did not make myself clear. Yes, we could change the sort order for partitions. But regarding the individual sort order in the list of sort order in the metadata, is it allowed to change one of them? Say we have a sort order with id =1, sorting on source_column_id = 1 with ascending order, is it supported that it is updated to descending order? Shall we prohibit such kind of change, as it could run into problem when an existing data file is tied it, right? The data file is written with ascending order, but sort order id 1 it tied with says that it is the descending order.
    Shall we only add new sort orders but could not change any existing ones?

  6. aokolnychyi commented on Oct 29, 2019

    @aokolnychyi
    ContributorAuthor

    @waterlx I agree that sort orders should be immutable. If we change the sort order for a table, we should produce a new sort order with a fresh id.

  7. prodeezy commented on Apr 8, 2020

    @prodeezy
    Contributor

    @aokolnychyi good stuff!

    Maybe this is out of scope for a first cut implementation, but should we also add an API for SortOrder evolution? Something like UpdateSortOrder? So that changes to sort order can be validated, controlled & audited within this API. This API can be accessed using Table.updateSortOrder() maybe?

  8. aokolnychyi commented on Sep 4, 2020

    @aokolnychyi
    ContributorAuthor

    Main PR: #1373

  9. rdblue commented on Oct 28, 2020

    @rdblue
    Contributor

    This was implemented in #1373.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions