[
https://issues.apache.org/jira/browse/SPARK-59150?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Stefan Savic updated SPARK-59150:
---------------------------------
Description:
Currently the VARIANT data type cannot be used where values are compared for
equality: GROUP BY, DISTINCT, set operations (UNION/INTERSECT/EXCEPT), equality
predicates (=, <=>, IN), joins on Variant keys, and equality-based aggregates
such as collect_set. Doing so requires convoluted workarounds (casting or
serializing to strings).
Two logically equal Variants can have different binary encodings (field-name
dictionary layout, integer widths, decimal scales, negative zero, NaN
encodings), so byte-wise comparison and hashing cannot be used directly. We
follow the MapSort approach: canonicalize a Variant into a unique binary form
right before it is compared or hashed, so the existing hash- and sort-based
execution works unchanged.
Plan:
# SPARK-59151 (done): the internal CanonicalizeVariant Catalyst expression.
Equal Variants produce identical canonical bytes.
# SPARK-60338: optimizer rules that insert CanonicalizeVariant into every
equality consumer of Variant values: equality predicates (=, <=>, IN, INSET, IN
subqueries), hash expressions, set operations, equality-based aggregate
arguments (DISTINCT, collect_set, pivot keys), grouping keys, repartition and
rebalance keys, window partition keys, streaming deduplication keys, and the
keys of the (co)group-by-key APIs for Scala, Python and R. Guarded by
spark.sql.optimizer.insertVariantCanonicalization.enabled.
# SPARK-60339: enable the feature end to end: relax the analyzer checks that
currently reject Variant in these operations, make hashing and comparison of
canonical Variant keys work in execution (including sort-based fallback and
spilling), and add SQL tests covering equivalent encodings, nulls and multiple
partitions.
was:
Currently VARIANT datatype doesn't support aggregation functions (like GROUP BY
and DISTINCT). Doing so requires some convoluted workarounds.
It would be a great addition to implement that as a natively-supported
capability.
We should follow MapSort path, where we canonicalise a Variant before
aggregating it
Summary: Support equality-based operations on VARIANT (GROUP BY,
DISTINCT, comparisons, set operations) (was: VARIANT datatype aggregation)
> Support equality-based operations on VARIANT (GROUP BY, DISTINCT,
> comparisons, set operations)
> ----------------------------------------------------------------------------------------------
>
> Key: SPARK-59150
> URL: https://issues.apache.org/jira/browse/SPARK-59150
> Project: Spark
> Issue Type: Umbrella
> Components: SQL
> Affects Versions: 5.0.0
> Reporter: Aleksandr Chernousov
> Priority: Major
>
> Currently the VARIANT data type cannot be used where values are compared for
> equality: GROUP BY, DISTINCT, set operations (UNION/INTERSECT/EXCEPT),
> equality predicates (=, <=>, IN), joins on Variant keys, and equality-based
> aggregates such as collect_set. Doing so requires convoluted workarounds
> (casting or serializing to strings).
> Two logically equal Variants can have different binary encodings (field-name
> dictionary layout, integer widths, decimal scales, negative zero, NaN
> encodings), so byte-wise comparison and hashing cannot be used directly. We
> follow the MapSort approach: canonicalize a Variant into a unique binary form
> right before it is compared or hashed, so the existing hash- and sort-based
> execution works unchanged.
> Plan:
> # SPARK-59151 (done): the internal CanonicalizeVariant Catalyst expression.
> Equal Variants produce identical canonical bytes.
> # SPARK-60338: optimizer rules that insert CanonicalizeVariant into every
> equality consumer of Variant values: equality predicates (=, <=>, IN, INSET,
> IN subqueries), hash expressions, set operations, equality-based aggregate
> arguments (DISTINCT, collect_set, pivot keys), grouping keys, repartition and
> rebalance keys, window partition keys, streaming deduplication keys, and the
> keys of the (co)group-by-key APIs for Scala, Python and R. Guarded by
> spark.sql.optimizer.insertVariantCanonicalization.enabled.
> # SPARK-60339: enable the feature end to end: relax the analyzer checks that
> currently reject Variant in these operations, make hashing and comparison of
> canonical Variant keys work in execution (including sort-based fallback and
> spilling), and add SQL tests covering equivalent encodings, nulls and
> multiple partitions.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]