acvictor commented on issue #8227:
URL: 
https://github.com/apache/incubator-gluten/issues/8227#issuecomment-2837547504

   @NEUpanning @zhztheplayer even if collect list is made imperative and we 
retain `ObjectHashAggregate` in the initial plan, I believe the sort clause 
will still be removed as part of the local sort elimination rules and the 
result order does not match. 
   
   Vanilla Spark
   ```
   == Physical Plan ==
   AdaptiveSparkPlan isFinalPlan=true
   +- == Final Plan ==
      ObjectHashAggregate(keys=[_groupingexpression#160], 
functions=[collect_list(value#151, 0, 0)])
      +- ObjectHashAggregate(keys=[_groupingexpression#160], 
functions=[partial_collect_list(value#151, 0, 0)])
         +- *(3) Project [value#151, (1 - id#150) AS _groupingexpression#160]
            +- *(3) Sort [id#150 ASC NULLS FIRST, value#151 ASC NULLS FIRST], 
false, 0
               +- ShuffleQueryStage 1
                  +- Exchange SinglePartition, REPARTITION_BY_COL, [plan_id=543]
                     +- *(2) Project [id#150, value#151]
                        +- ShuffleQueryStage 0
                           +- Exchange SinglePartition, REPARTITION_BY_COL, 
[plan_id=506]
                              +- *(1) Project [id#150, value#151, 
rand(-8150862051285969770) AS _nondeterministic#157]
                                 +- *(1) ColumnarToRow
                                    +- BatchScan parquet 
file:/tmp/spark-a469daee-5cdc-4c1d-8e29-e07bca7dd1f1[id#150, value#151] 
ParquetScan DataFilters: [], Format: parquet, Location: InMemoryFileIndex(1 
paths)[file:/tmp/spark-a469daee-5cdc-4c1d-8e29-e07bca7dd1f1], PartitionFilters: 
[], PushedAggregation: [], PushedFilters: [], PushedGroupBy: [], ReadSchema: 
struct<id:int,value:string> RuntimeFilters: []
   +- == Initial Plan ==
      ObjectHashAggregate(keys=[_groupingexpression#160], 
functions=[collect_list(value#151, 0, 0)])
      +- ObjectHashAggregate(keys=[_groupingexpression#160], 
functions=[partial_collect_list(value#151, 0, 0)])
         +- Project [value#151, (1 - id#150) AS _groupingexpression#160]
            +- Sort [id#150 ASC NULLS FIRST, value#151 ASC NULLS FIRST], false, 0
               +- Exchange SinglePartition, REPARTITION_BY_COL, [plan_id=487]
                  +- Project [id#150, value#151]
                     +- Exchange SinglePartition, REPARTITION_BY_COL, 
[plan_id=485]
                        +- Project [id#150, value#151, 
rand(-8150862051285969770) AS _nondeterministic#157]
                           +- BatchScan parquet 
file:/tmp/spark-a469daee-5cdc-4c1d-8e29-e07bca7dd1f1[id#150, value#151] 
ParquetScan DataFilters: [], Format: parquet, Location: InMemoryFileIndex(1 
paths)[file:/tmp/spark-a469daee-5cdc-4c1d-8e29-e07bca7dd1f1], PartitionFilters: 
[], PushedAggregation: [], PushedFilters: [], PushedGroupBy: [], ReadSchema: 
struct<id:int,value:string> RuntimeFilters: []
   
   ```
   Gluten
   ```
   == Physical Plan ==
   AdaptiveSparkPlan isFinalPlan=true
   +- == Final Plan ==
      VeloxColumnarToRow
      +- ^(7) HashAggregateTransformer(keys=[_groupingexpression#223], 
functions=[collect_list(value#151, 0, 0)], isStreamingAgg=false)
         +- ^(7) ProjectExecTransformer [value#151, (1 - id#150) AS 
_groupingexpression#223]
            +- ^(7) InputIteratorTransformer[id#150, value#151]
               +- ShuffleQueryStage 1
                  +- ColumnarExchange SinglePartition, REPARTITION_BY_COL, 
[plan_id=4835], [shuffle_writer_type=hash], [OUTPUT] List(id:IntegerType, 
value:StringType)
                     +- ^(6) ProjectExecTransformer [id#150, value#151]
                        +- ^(6) InputIteratorTransformer[id#150, value#151, 
_nondeterministic#220]
                           +- ShuffleQueryStage 0
                              +- ColumnarExchange SinglePartition, 
REPARTITION_BY_COL, [plan_id=4716], [shuffle_writer_type=hash], [OUTPUT] 
List(id:IntegerType, value:StringType, _nondeterministic:DoubleType)
                                 +- ^(5) ProjectExecTransformer [id#150, 
value#151, rand(7086698720347140193) AS _nondeterministic#220]
                                    +- ^(5) BatchScanTransformer parquet 
file:/tmp/spark-d935795f-f5c9-48ba-8328-3a01b27df46e[id#150, value#151] 
ParquetScan DataFilters: [], Format: parquet, Location: InMemoryFileIndex(1 
paths)[file:/tmp/spark-d935795f-f5c9-48ba-8328-3a01b27df46e], PartitionFilters: 
[], PushedAggregation: [], PushedFilters: [], PushedGroupBy: [], ReadSchema: 
struct<id:int,value:string> RuntimeFilters: [] NativeFilters: []
   +- == Initial Plan ==
      ObjectHashAggregate(keys=[_groupingexpression#223], 
functions=[collect_list(value#151, 0, 0)])
      +- ObjectHashAggregate(keys=[_groupingexpression#223], 
functions=[partial_collect_list(value#151, 0, 0)])
         +- Project [value#151, (1 - id#150) AS _groupingexpression#223]
            +- Sort [id#150 ASC NULLS FIRST, value#151 ASC NULLS FIRST], false, 0
               +- Exchange SinglePartition, REPARTITION_BY_COL, [plan_id=1529]
                  +- Project [id#150, value#151]
                     +- Exchange SinglePartition, REPARTITION_BY_COL, 
[plan_id=1527]
                        +- Project [id#150, value#151, 
rand(7086698720347140193) AS _nondeterministic#220]
                           +- BatchScan parquet 
file:/tmp/spark-d935795f-f5c9-48ba-8328-3a01b27df46e[id#150, value#151] 
ParquetScan DataFilters: [], Format: parquet, Location: InMemoryFileIndex(1 
paths)[file:/tmp/spark-d935795f-f5c9-48ba-8328-3a01b27df46e], PartitionFilters: 
[], PushedAggregation: [], PushedFilters: [], PushedGroupBy: [], ReadSchema: 
struct<id:int,value:string> RuntimeFilters: []
   
   ```
   
   In the docs for 
[collect_list](https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.functions.collect_list.html)
 I see this note - The function is non-deterministic because the order of 
collected results depends on the order of the rows which may be 
non-deterministic after a shuffle. Does this mean that ordering cannot be 
guaranteed whatever the input order?


-- 
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]

Reply via email to