Zoltán Borók-Nagy created IMPALA-15794:
------------------------------------------
Summary: Iceberg metrics of FLOAT and DOUBLE columns written by
Impala let other engines skip matching files
Key: IMPALA-15794
URL: https://issues.apache.org/jira/browse/IMPALA-15794
Project: IMPALA
Issue Type: Bug
Components: Backend
Reporter: Zoltán Borók-Nagy
Iceberg keeps NaNs out of the lower and upper bounds, counts them in
{{nan_value_counts}}, and orders -0.0 before 0.0. Its readers assume that a
file without NaN value counts has no NaNs. The metrics Impala writes for FLOAT
and DOUBLE columns of Iceberg data files don't follow this:
* Impala writes no NaN value counts
({{IcebergCatalogOpExecutor.buildDataFileMetrics()}} passes null), while
{{fmin()}} and {{fmax()}} in {{ColumnStats}} leave NaNs out of the bounds. So a
file with the values 1 and NaN gets 1 as both bounds. Iceberg's
{{InclusiveMetricsEvaluator}} skips this file for {{d != 1}} and {{d NOT IN
(1)}}, and {{StrictMetricsEvaluator}} says that all of its rows match {{d = 1}}
and {{d < 5}}. Spark uses the latter to drop whole data files in DELETE FROM
({{SparkTable.canDeleteUsingMetadata()}}), so it would delete the NaN row too.
* When two zeros tie, {{fmin()}} and {{fmax()}} keep the zero seen last. So a
file with the values -3, 0 and -0.0, in this order, gets -0.0 as upper bound.
Iceberg skips this file for {{d = 0}}, {{d >= 0}} and {{d IN (0, 5)}}, and says
that all of its rows match {{d < 0}}.
* If every non-null value is NaN, both bounds are NaN, although the spec says
"NaNs are not permitted as lower or upper bounds". Iceberg's Java readers
ignore NaN bounds, but without a NaN count they can't skip such a file for any
comparison either.
Impala's own predicate push down works around the first two (IMPALA-15635), but
other engines read the same metrics.
{code:sql}
create table nan_t (d double, f float) stored as iceberg;
insert into nan_t values (1, 1), (cast('nan' as double), cast('nan' as float));
select lower_bounds, upper_bounds, nan_value_counts from nan_t.`files`;
-- {1:"AAAAAAAA8D8=",2:"AACAPw=="} {1:"AAAAAAAA8D8=",2:"AACAPw=="} NULL
-- i.e. 1 is both bounds of both columns, and there are no NaN counts
create table zero_t (i int, d double) stored as iceberg;
insert into zero_t values (1, -3), (2, 0), (3, cast('-0' as double));
select readable_metrics.d.lower_bound, readable_metrics.d.upper_bound
from zero_t.`files`;
-- -3.0 -0.0
create table all_nan (d double) stored as iceberg;
insert into all_nan values (cast('nan' as double)), (cast('nan' as double));
select lower_bounds, upper_bounds from all_nan.`files`;
-- {1:"AAAAAAAA+H8="} {1:"AAAAAAAA+H8="}, i.e. NaN
{code}
The evaluators of Iceberg 1.11.0 on such metrics:
{noformat}
bounds 1 and 1, no NaN count inclusive: d != 1 -> skip, d NOT IN (1) -> skip
strict: d = 1 -> all rows match, d < 5 ->
all rows match
same, with a NaN count of 1 inclusive: d != 1, d NOT IN (1) -> might match
strict: d = 1, d < 5 -> not all rows match
bounds -3.0 and -0.0 inclusive: d = 0, d >= 0, d IN (0, 5) -> skip
strict: d < 0 -> all rows match
{noformat}
Iceberg's own writers count NaNs and compare with the total order
({{FloatFieldMetrics}}, {{DoubleFieldMetrics}}), and write no bounds if all
values are NaN. Impala could do the same when it collects the Iceberg stats,
and send the NaN counts to the catalog with the other column stats.
Found while comparing the Iceberg metrics written by master (19731aa580) with
Iceberg 1.11.0.
---------------------------------------------------------------------------------------------
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)