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
There is a problem where the statistics for the wrong columns can be used to prune parquet row groups, leading to potentially incorrect answers (missing data)
It affects cases where there are predicates that can be used to prune row groups. This used to work
To Reproduce
I am working on a self contained reproducer
Here is what I found in IOx: for the file that is being pruned incorrectly, the state column is a string with the value MA but the max value from the statistics that is returned is as follows (it turns out it is the statistics for the time column):
+-------+
| state |
+-------+
| 50 |
+-------+
I dug into the issue some more, and I found that It appears to be a bug in how the column index names are looked up by the parquet_column function (that we sadly added to handle another bug 🤦 )
Here is the arrow schema:
Schema {
fields: [
Field { name: "area", data_type: UInt64, nullable: true },
Field { name: "city", data_type: Dictionary(Int32, Utf8) },
Field { name: "max_temp", data_type: Float64, nullable: true },
Field { name: "min_temp", data_type: Float64, nullable: true },
Field { name: "no_overlap", data_type: Float64, nullable: true },
Field { name: "state", data_type: Dictionary(Int32, Utf8), nullable: true }, <--- index 5
Field { name: "time", data_type: Timestamp(Nanosecond, None), nullable: false },
]
}
Note the state column is index 5
The code in parquet_column resolves column 5 to index 5 in the parquet schema
At the core, the problem is that previously parquet statistics were looked up by name using the parquet schema. We added a lookup on arrow schema first to make sure the right parquet field was found, but we used the wrong arrow scheam.
@tustvold pointed out that this is incorrect for nested types (#8335), and thus we fixed the problem by doing the lookup by name in the arrow schema, and then mapping to the parquet schema by column index and checking that it was not part of a nested type.
However, this mapping failed to account for the fact that each individual parquet file may have a different schema than the overall table (and ParquetExec handles this mapping)
The text was updated successfully, but these errors were encountered:
alamb
changed the title
Incorrect results when reading parquet files with different schemas and statistics
Regression: Incorrect results when reading parquet files with different schemas and statistics
Dec 13, 2023
Describe the bug
There is a problem where the statistics for the wrong columns can be used to prune parquet row groups, leading to potentially incorrect answers (missing data)
It affects cases where there are predicates that can be used to prune row groups. This used to work
To Reproduce
I am working on a self contained reproducer
Here is what I found in IOx: for the file that is being pruned incorrectly, the state column is a string with the value
MA
but the max value from the statistics that is returned is as follows (it turns out it is the statistics for thetime
column):I dug into the issue some more, and I found that It appears to be a bug in how the column index names are looked up by the
parquet_column
function (that we sadly added to handle another bug 🤦 )Here is the arrow schema:
Note the
state
column is index 5The code in parquet_column resolves column
5
to index 5 in the parquet schemaThe paruqet_file in question has this schema
Note that
state
is actually at offset6
in this file, which leads to the statistics being incorrectly read and therefore pruned.Expected behavior
The correct statistics should be used
Additional context
Kudos to @appletreeisyellow for helping track down this issue.
This was introduced in #8294 / 06bbe12 by myself and @tustvold
At the core, the problem is that previously parquet statistics were looked up by name using the parquet schema. We added a lookup on arrow schema first to make sure the right parquet field was found, but we used the wrong arrow scheam.
@tustvold pointed out that this is incorrect for nested types (#8335), and thus we fixed the problem by doing the lookup by name in the arrow schema, and then mapping to the parquet schema by column index and checking that it was not part of a nested type.
However, this mapping failed to account for the fact that each individual parquet file may have a different schema than the overall table (and ParquetExec handles this mapping)
The text was updated successfully, but these errors were encountered: