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
Exceptions thrown when column pruning metadata tables from partitioned Iceberg tables #1735
This does not occur if you make the table within the same Iceberg Version (0.9.0 or 0.9.1). A different error occurs if you attempt to prune within the data_file construct itself.
val df = spark.read.format("iceberg").load("file:///Users/russellspitzer/Temp/OldIcebergTable#all_entries").select("data_file.file_path").show
20/11/06 11:45:42 ERROR Executor: Exception in task 0.0 in stage 0.0 (TID 0)/ 1]
java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Integer
Ok both of these issues seem to be related to trying to file an impossible projection with the AvroReader.
For the "Status" issue on the old table an empty projection is given,
For the "subfield" issue the projection is given as if looking for a top level field which seems not to work
The Status issue is caused by a BuildAvroProjection call,
The empty projection note above is turned into a full manifest entry spec request including data_file as a required field. The actual records present in the "Record" call in BuildAvroProjection have a schema like
status type:INT pos:0
snapshot_id type:UNION pos:1
This doesn't have the data_file field which causes the projection to fail with "No field data_file" found
We get this because in ProjectionDatumReader.java setSchema we attempt to prune an expected schema which contains all files and result in a pruned schema with only the above 2 columns.
So our pruned schema looks like
Schema prunedSchema = AvroSchemaUtil.pruneColumns(newFileSchema, projectedIds, nameMapping);
0 status, 1 snapshot_id
Missing the requested data_file column
This all seems to happen on the executors, and since we shouldn't be reading those other columns in the first place it seem to me like the Projection is actually not being serialized correctly to the executors apart from this error with the bad mapping for projectedIds
From what I can tell this actually shouldn't be working on 0.9.1 but works because of a fluke.
When running through prune Columns we check whether or not our field posses a selected ID
SchemafieldSchema = fields.get(field.pos());
// All primitives are selected by selecting the field, but map and list// types can be selected by projecting the keys, values, or elements.// This creates two conditions where the field should be selected: if the// id is selected or if the result of the field is non-null. The only// case where the converted field is non-null is when a map or list is// selected by lower IDs.if (selectedIds.contains(fieldId)) {
filteredFields.add(copyField(field, field.schema(), fieldId));
} elseif (fieldSchema != null) {
hasChange = true;
filteredFields.add(copyField(field, fieldSchema, fieldId));
}
In the 0.9.1 table this correctly also passes through selected field ID's of 0,1,3
We still get the field.pos() on data_file of 2 so it doesn't match. BUT
fields.get(2) returns the Partition schema in "r2" partition type:Record pos:0
Now we aren't actually looking for that field, we are looking for the data_file field. BUT if "filedSchema != null" we follow the secondary pruning pathway above. This means we get to add in a copy where we set
"data_file to have schema RECORD and the fieldId" we expect. Luckily we are pruning this out at the spark level but we are reading the wrong column data here.
The 0.8.0 table doesn't have the "r2" record placed in "fields" and instead just get's null
leading to the error at the beginning of this ticket.
Ok! I'm finally going less crazy, this isn't an issue with old tables, this is broken on new tables as well, any Partitioned table is broken regardless of when it was made. My 0.9.X table I was testing before is also broken if it is partitioned, the key difference was between partitioned and not.
changed the title [-]Exceptions thrown when column pruning metadata tables from older iceberg tables[/-][+]Exceptions thrown when column pruning metadata tables from partitioned Iceberg tables[/+]on Nov 9, 2020
We call pruneColumns with {0 : status,1 : snapshot, 3: sequence_number} as our selected ID's on a second pass (still not sure why we hit this twice or why we request these 3 columns seems like this is a bug too)
These selectedIds are passed in with the fileSchema correctly but there is a slightly strange behavior within the pruning code
This filter means that any "empty" schema will automatically not be removed. If empty schemas are never removed then any top level schema element that contains an empty sub schema element will be saved. This happens when a table is unpartitioned since the PartitionType struct subfield of the file schema is empty.
When the table is unpartitioned the sub schema of "partitionType" is empty, this means filteredFields.size == record.getFields.size() SO the "data_file" field is not pruned out. This means when we go back up the stack and attempt to resolve the top level schema we get a call to "record" with the last parameter "fields" set to
// All primitives are selected by selecting the field, but map and list
// types can be selected by projecting the keys, values, or elements.
// This creates two conditions where the field should be selected: if the
// id is selected or if the result of the field is non-null. The only
// case where the converted field is non-null is when a map or list is
// selected by lower IDs.
Fields.get(2) has a field schema Even though we didn't ask for "partition", the Line 97 check only says we cannot ever prune an empty struct. Since we can't prune the empty "partitionStruct" we end up having to keep data_file even though it is not on our list of selected Ids.
TLDR This is broken because we ask for the wrong field IDs but is unbroken only for unpartitioned tables because we also incorrectly can never prune an empty struct
From (A, B, C, D { foo, bar } )
Project (A, B, C, D {})
Returns
(A, B, C) // Missing D which was required in the projection
Example of Bug 2
From (A, B, C, D {foo, bar, baz {}} ) // Starting with D containing an field baz which is empty
Project (A)
Returns
(A, D{ baz {} }) // Includes D even though it was not requested
In combination these sometimes negate each other ~ kinda Example of interaction of bugs
From (A, B, C, D {foo, bar, baz{}})
Project (A, B, C, D{})
Returns
(A, B, C, D{ baz{} }) // D is present although with an unrequested field but this satisfies the projection
Activity
RussellSpitzer commentedon Nov 6, 2020
Attached is a sample table I made which reproduces the issue
oldicebergtable.zip
RussellSpitzer commentedon Nov 6, 2020
Ok these are two Separate issues.
The "status" issue only happens when dealing with old tables.
The "data_file.subfield" issue happens with new tables as well
RussellSpitzer commentedon Nov 6, 2020
Ok both of these issues seem to be related to trying to file an impossible projection with the AvroReader.
For the "Status" issue on the old table an empty projection is given,
For the "subfield" issue the projection is given as if looking for a top level field which seems not to work
RussellSpitzer commentedon Nov 6, 2020
The Status issue is caused by a BuildAvroProjection call,
The empty projection note above is turned into a full manifest entry spec request including data_file as a required field. The actual records present in the "Record" call in BuildAvroProjection have a schema like
This doesn't have the data_file field which causes the projection to fail with "No field data_file" found
We get this because in ProjectionDatumReader.java setSchema we attempt to prune an expected schema which contains all files and result in a pruned schema with only the above 2 columns.
RussellSpitzer commentedon Nov 7, 2020
Pretty sure the specific error is here
Given an expected schema
The code returns
So our pruned schema looks like
Schema prunedSchema = AvroSchemaUtil.pruneColumns(newFileSchema, projectedIds, nameMapping);
Missing the requested data_file column
This all seems to happen on the executors, and since we shouldn't be reading those other columns in the first place it seem to me like the Projection is actually not being serialized correctly to the executors apart from this error with the bad mapping for projectedIds
RussellSpitzer commentedon Nov 7, 2020
From what I can tell this actually shouldn't be working on 0.9.1 but works because of a fluke.
When running through prune Columns we check whether or not our field posses a selected ID
In the 0.9.1 table this correctly also passes through selected field ID's of 0,1,3
We still get the field.pos() on data_file of 2 so it doesn't match. BUT
fields.get(2) returns the Partition schema in "r2"
partition type:Record pos:0Now we aren't actually looking for that field, we are looking for the data_file field. BUT if "filedSchema != null" we follow the secondary pruning pathway above. This means we get to add in a copy where we set
"data_file to have schema RECORD and the fieldId" we expect. Luckily we are pruning this out at the spark level but we are reading the wrong column data here.
The 0.8.0 table doesn't have the "r2" record placed in "fields" and instead just get's null
leading to the error at the beginning of this ticket.
RussellSpitzer commentedon Nov 9, 2020
Ok! I'm finally going less crazy, this isn't an issue with old tables, this is broken on new tables as well, any Partitioned table is broken regardless of when it was made. My 0.9.X table I was testing before is also broken if it is partitioned, the key difference was between partitioned and not.
[-]Exceptions thrown when column pruning metadata tables from older iceberg tables[/-][+]Exceptions thrown when column pruning metadata tables from partitioned Iceberg tables[/+]RussellSpitzer commentedon Nov 9, 2020
Repo for IcebergSourceTableTest
RussellSpitzer commentedon Nov 9, 2020
A more complete view.
We call pruneColumns with
{0 : status,1 : snapshot, 3: sequence_number}as our selected ID's on a second pass (still not sure why we hit this twice or why we request these 3 columns seems like this is a bug too)These selectedIds are passed in with the fileSchema correctly but there is a slightly strange behavior within the pruning code
iceberg/core/src/main/java/org/apache/iceberg/avro/PruneColumns.java
Lines 97 to 98 in d1ba7b6
This filter means that any "empty" schema will automatically not be removed. If empty schemas are never removed then any top level schema element that contains an empty sub schema element will be saved. This happens when a table is unpartitioned since the PartitionType struct subfield of the file schema is empty.
When the table is unpartitioned the sub schema of "partitionType" is empty, this means filteredFields.size == record.getFields.size() SO the "data_file" field is not pruned out. This means when we go back up the stack and attempt to resolve the top level schema we get a call to "record" with the last parameter "fields" set to
This saves us in the "unpartitioned" pruning case because then when we get down to the check
iceberg/core/src/main/java/org/apache/iceberg/avro/PruneColumns.java
Lines 80 to 86 in d1ba7b6
Fields.get(2) has a field schema Even though we didn't ask for "partition", the Line 97 check only says we cannot ever prune an empty struct. Since we can't prune the empty "partitionStruct" we end up having to keep data_file even though it is not on our list of selected Ids.
TLDR This is broken because we ask for the wrong field IDs but is unbroken only for unpartitioned tables because we also incorrectly can never prune an empty struct
RussellSpitzer commentedon Nov 11, 2020
Overview of bugs found: #1744
Example of Bug 1
Example of Bug 2
In combination these sometimes negate each other ~ kinda
Example of interaction of bugs