Github user junegunn commented on the issue:
https://github.com/apache/spark/pull/16347
Thanks for the comment. I was trying to implement the following Hive QL in
Spark SQL/API:
```sql
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.mapred.mode = nonstrict;
insert overwrite table target_table
partition (day)
select * from source_table
distribute by day sort by id;
```
In Hive, `distribute by day` ensures that the records with the same "day"
goes to the same reducer, and `sort by id` ensures that the input to each
reducer is sorted by "id". It works as expected. The number of reducers is no
more than the cardinality of "day" column, and I could confirm that the
generated ORC file in each partition is sorted by "id".
However, if I run the same query or its equivalent Spark code â
[`repartition('day)` for `distribute by
day`](https://github.com/apache/spark/blob/bfeccd80ef032cab3525037be3d3e42519619493/sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala#L2423),
and [`sortWithinPartitions('id)` for `sort by
id`](https://github.com/apache/spark/blob/bfeccd80ef032cab3525037be3d3e42519619493/sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala#L990)
â on Spark, we have the right number of writer tasks, one for each
partition, and each task generates a single output file, but the generated ORC
file is not properly sorted by "id" making ORC index ineffective.
> Can your use case be satisfied by adding an explicit sortBy?
`sortBy` is for bucketed tables and requires `bucketBy`, so I'm not sure if
it's related to this issue regarding Hive compatibility.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]