[CH] Fallback takes place at wrong place
- Dominant language
- Scala
- Stars
- 1.6k
- Forks
- 657
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 80
Description
### Backend
CH (ClickHouse)
### Bug description
```sql
select b.uid as uid
,a.userid
,a.birthday
,a.rtime
from
(select userid
,birthday
,rtime
from
(select userid
,birthday
,rtime
-- ,row_number() over(partition by userid order by rtime desc) as rk
,1 as rk
from
(
select userid
,birthday
,rtime
from t0
union all
select userid
,from_unixtime(unix_timestamp(content, 'MM/dd/yyyy'),'yyyy-MM-dd') as birthday
,time as rtime
from t1
where day = '${day}'
and id = '01505004'
and emoji_name='birthday'
and click ='introduction_save'
and status ='1'
) a
) a
where rk=1 and birthday<>''
) a
join
t2 b
on a.userid=udfhash(b.uid);
```
```
Execute InsertIntoHadoopFsRelationCommand (38)
+- FakeRowAdaptor (37)
+- AdaptiveSparkPlan (36)
+- == Final Plan ==
^ ProjectExecTransformer (23)
+- ^ InputIteratorTransformer (22)
+- RowToCHNativeColumnar (20)
+- ShuffledHashJoin Inner BuildLeft (19)
:- CHNativeColumnarToRow (12)
: +- AQEShuffleRead (11)
: +- ShuffleQueryStage (10), Statistics(sizeInBytes=26.8 MiB, rowCount=9.05E+5)
: +- ColumnarExchange (9)
: +- ColumnarUnion (8)
: :- ^ FilterExecTransformer (2)
: : +- ^ ScanTransformer orc t0 (1)
: +- ^ ProjectExecTransformer (6)
: +- ^ FilterExecTransformer (5)
: +- ^ ScanTransformer parquet t1(4)
+- AQEShuffleRead (18)
+- ShuffleQueryStage (17), Statistics(sizeInBytes=28.8 GiB, rowCount=9.66E+8)
+- Exchange (16)
+- CHNativeColumnarToRow (15)
+- ^ ScanTransformer orc t2(13)
```
Since `udfhash` is an unsupported UDF, the plan has a fallback on the join operation. But the the fallback on the left table takes place after the shuffle, this make the left partitions don't match with the right partitions, and the result is wrong.
### Spark version
None
### Spark configurations
_No response_
### System information
_No response_
### Relevant logs
```bash
```
Contributor guide
Research direction
Start by reproducing the provided SQL query and comparing its Execute InsertIntoHadoopFsRelationCommand plan, focusing on the ShuffledHashJoin, ColumnarExchange, and fallback caused by unsupported udfhash. Trace where the left-table fallback occurs relative to the shuffle; done means the fallback preserves matching partitions and the query returns correct results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clickhouse, scala, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100