Open agrawalreetika opened 2 months ago
Can you gather any information on:
1) What does the Iceberg community think we should do? What does the Spark reference implementation do? What do other interactive engines like Trino do? 2) Time travel is a feature that is called out in the SQL spec. What does the SQL spec say we should do?
As I checked Snapshot has schemaId associated to it. https://github.com/apache/iceberg/blob/main/api/src/main/java/org/apache/iceberg/Snapshot.java#L171
And I checked bit on the Iceberg side, it looks like Spark is taking schema based on the snapshotId https://github.com/apache/iceberg/blob/main/spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java#L188
Looks like in Trino is using schema based on snapshot while creating TableHandle - https://github.com/trinodb/trino/blob/master/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java#L454
So I thought In Presto also we can snapshotSchema instead of current Schema always? LMK if we should explore more around this?
I believe the SQL spec might specify we use the current schema. My understanding is:
1) Iceberg community believes it ought to be the schema of the snapshot 2) The SQL spec defines it to be the latest schema
I will check this later. If my understanding is correct, we would need to get to alignment on which spec to follow.
As I understand, if we consider reading a snapshot as snapshot reading in the scope of transaction isolation, then it should not be affected by the schema changes. We should always read the same data through a specified snapshot id in any situation. In this way, it makes sense to use the schema of the snapshot.
2 open questions on this for Presto Query behaviour -
When we are doing Time Travel, should we consider schema of the snapshot?
When we are Querying current Schema, do we consider the current schema or schema of the snapshot? -- This is to consider the case when schema evaluation has happened but there are no Data modification, so current table snapshot schema would point to the schema which was before schema evaluation when the snapshot was created.
So basically, my understanding is other engines are using Snapshot's schema whenever there is a time travel Query. Otherwise uses the current schema.
If there is any schema evaluation (Ex: add column, delete column), the schema for snapshots could be different. In the case of Time Travel, we are currently returning the current table schema instead of respective to a given Snapshot.
https://github.com/prestodb/presto/blob/master/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java#L769
https://github.com/prestodb/presto/blob/master/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java#L660
Your Environment
Expected Behavior
We should schema wrt to Snapshot instead of always selecting the current table schema
Current Behavior
Currently returning the current table schema instead of respective to a given Snapshot.
Possible Solution
Make changes to https://github.com/prestodb/presto/blob/master/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java#L660 get schema for a given snapshotId
Steps to Reproduce
Screenshots (if appropriate)
Context