jayzhan211 commented on issue #11360: URL: https://github.com/apache/datafusion/issues/11360#issuecomment-2222082311
I found we accidentally convert non-single expression to group by too, we should not convert `select bit_xor(distinct a % 2) from t;` to group by expression. ``` // datafusion statement ok create table t(a int) as values (1), (1), (2), (2), (2), (3); query I select bit_xor(distinct a % 2) from t; ---- 1 query TT explain select bit_xor(distinct a % 2) from t; ---- logical_plan 01)Projection: bit_xor(alias1) AS bit_xor(DISTINCT t.a % Int64(2)) 02)--Aggregate: groupBy=[[]], aggr=[[bit_xor(alias1)]] 03)----Aggregate: groupBy=[[CAST(t.a AS Int64) % Int64(2) AS alias1]], aggr=[[]] 04)------TableScan: t projection=[a] physical_plan 01)ProjectionExec: expr=[bit_xor(alias1)@0 as bit_xor(DISTINCT t.a % Int64(2))] 02)--AggregateExec: mode=Final, gby=[], aggr=[bit_xor(alias1)] 03)----CoalescePartitionsExec 04)------AggregateExec: mode=Partial, gby=[], aggr=[bit_xor(alias1)] 05)--------AggregateExec: mode=FinalPartitioned, gby=[alias1@0 as alias1], aggr=[] 06)----------CoalesceBatchesExec: target_batch_size=8192 07)------------RepartitionExec: partitioning=Hash([alias1@0], 4), input_partitions=4 08)--------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1 09)----------------AggregateExec: mode=Partial, gby=[CAST(a@0 AS Int64) % 2 as alias1], aggr=[] 10)------------------MemoryExec: partitions=1, partition_sizes=[1] query I select bit_xor(a % 2) from t group by a; ---- 0 0 1 query I select bit_xor(a % 2) from t group by (a % 2); ---- 1 0 ``` ``` D create table t(a int); D insert into t values (1); D insert into t values (1); D insert into t values (2); D insert into t values (2); D insert into t values (2); D insert into t values (3); D select bit_xor(distinct a % 2) from t; ┌───────────────────────────┐ │ bit_xor(DISTINCT (a % 2)) │ │ int32 │ ├───────────────────────────┤ │ 1 │ └───────────────────────────┘ D select bit_xor(a % 2) from t group by a; ┌──────────────────┐ │ bit_xor((a % 2)) │ │ int32 │ ├──────────────────┤ │ 0 │ │ 0 │ │ 1 │ └──────────────────┘ D select bit_xor(a % 2) from t group by (a % 2); ┌──────────────────┐ │ bit_xor((a % 2)) │ │ int32 │ ├──────────────────┤ │ 1 │ │ 0 │ └──────────────────┘ D explain select bit_xor(distinct a % 2) from t; ┌─────────────────────────────┐ │┌───────────────────────────┐│ ││ Physical Plan ││ │└───────────────────────────┘│ └─────────────────────────────┘ ┌───────────────────────────┐ │ UNGROUPED_AGGREGATE │ │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ │ bit_xor(DISTINCT #0) │ └─────────────┬─────────────┘ ┌─────────────┴─────────────┐ │ PROJECTION │ │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ │ (a % 2) │ └─────────────┬─────────────┘ ┌─────────────┴─────────────┐ │ SEQ_SCAN │ │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ │ t │ │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ │ a │ │ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ │ EC: 6 │ └───────────────────────────┘ ``` -- 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]
