anoopj commented on code in PR #18405: URL: https://github.com/apache/iceberg/pull/18405#discussion_r4362325349
########## format/spec.md: ########## @@ -474,6 +474,27 @@ Two rows are the "same"---that is, the rows represent the same entity---if the i Identifier fields may be nested in structs but cannot be nested within maps or lists. Float, double, and optional fields cannot be used as identifier fields and a nested field cannot be used as an identifier field if it is nested in an optional struct, to avoid null values in identifiers. +#### Stats-only Fields + +Stats are tracked in manifests by field ID. Schema fields have assigned IDs, but additional field IDs may be assigned to track stats for derived values. For instance, lower and upper bounds for `to_lower_case(name)` are useful for case-insensitive file pruning. + +Stats-only fields are used to track stats for derived values that are not part of the table schema and are not materialized. A stats-only field consists of: + +* A **`field-id`** assigned by incrementing the table's `last-column-id` +* A **`type`** that can be `partition-value` or `expr-value` +* An optional **`data-type`** that determines the bound type; must be a primitive or variant +* Type-specific fields that define how derived values are produced + +The `partition-value` type stores stats for the output of a partition field, identified by a `partition-field-id` type-specific field. The bound type is the partition field's result type and `data-type` is omitted. This may be used to store bucket partition values in stats for filtering. + +The `expr-value` type stores stats for the result of a [value expression](expressions-spec.md#value-expressions), stored in the `expr` field. Expressions must use only ID references. The output type of the value expression must be stored in the `data-type` field. + +Readers must not fail when an unsupported stats-only field `type` is found; stats for unsupported types must be ignored. + +Writers must preserve existing stats for stats-only fields listed in a table's `stats-fields` if the `data-type` is known (either set or specified by a supported type). Writers should produce stats when possible for stats-only fields. A writer should produce no stats by setting the field stats struct to null if an expression is not supported, produces an incompatible output type when bound, or binding fails. Review Comment: > A writer should produce no stats by setting the field stats struct to null if an expression is not supported, produces an incompatible output type when bound, or binding fails. If the source type is promoted, it can potentially invalidate the stored expression stats without changing the type? e.g. consider an unpartitioned table where we store an expression `bucket(16, d)` on a date column `d`. Let's say output of the expression is `B1` and we store them as the bounds. If `d` is promoted to a timestamp field, the expression output type is still `int`, but there is no guarantee that the expression would evaluate to the same value, `B1` (depending on the murmur3 hash value). Now if a query comes in, the stored bounds can cause false pruning? Should we require source type promotions to preserve the expression’s values, or invalidate the affected existing stats when they don’t? Checking output-type compatibility alone would not catch this case. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
