AdamGS commented on PR #20665:
URL: https://github.com/apache/datafusion/pull/20665#issuecomment-3990410210

   I was curious about overflow behavior which I think is right, but I have 
noticed one difference (at least when going through SQL):
   ```sql
   statement ok
   CREATE TABLE IF NOT EXISTS tbl (val INTEGER UNSIGNED);
   
   statement ok
   INSERT INTO tbl VALUES (4294967295);
   
   statement ok
   INSERT INTO tbl VALUES (4294967295);
   
   query II
   SELECT SUM(val + 1), SUM(val + 2) FROM tbl;
   ----
   8589934592 8589934594
   
   query TT
   EXPLAIN SELECT SUM(val + 1), SUM(val + 2)  FROM tbl;
   ----
   logical_plan
   01)Aggregate: groupBy=[[]], aggr=[[sum(__common_expr_1 AS tbl.val + 
Int64(1)), sum(__common_expr_1 AS tbl.val + Int64(2))]]
   02)--Projection: CAST(tbl.val AS Int64) AS __common_expr_1
   03)----TableScan: tbl projection=[val]
   physical_plan
   01)AggregateExec: mode=Single, gby=[], aggr=[sum(tbl.val + Int64(1)), 
sum(tbl.val + Int64(2))]
   02)--ProjectionExec: expr=[CAST(val@0 AS Int64) as __common_expr_1]
   03)----DataSourceExec: partitions=1, partition_sizes=[2]
   
   query RR
   SELECT SUM(val) + 1 * COUNT(val), SUM(val) + 2 * COUNT(val)  FROM tbl;
   ----
   8589934592 8589934594
   
   query TT
   EXPLAIN SELECT SUM(val) + 1 * COUNT(val), SUM(val) + 2 * COUNT(val)  FROM 
tbl;
   ----
   logical_plan
   01)Projection: __common_expr_1 + CAST(count(tbl.val) AS Decimal128(20, 0)) 
AS sum(tbl.val) + Int64(1) * count(tbl.val), __common_expr_1 AS sum(tbl.val) + 
CAST(Int64(2) * count(tbl.val) AS Decimal128(20, 0))
   02)--Projection: CAST(sum(tbl.val) AS Decimal128(20, 0)) AS __common_expr_1, 
count(tbl.val)
   03)----Aggregate: groupBy=[[]], aggr=[[sum(CAST(tbl.val AS UInt64)), 
count(tbl.val)]]
   04)------TableScan: tbl projection=[val]
   physical_plan
   01)ProjectionExec: expr=[__common_expr_1@0 + CAST(count(tbl.val)@1 AS 
Decimal128(20, 0)) as sum(tbl.val) + Int64(1) * count(tbl.val), 
__common_expr_1@0 + CAST(2 * count(tbl.val)@1 AS Decimal128(20, 0)) as 
sum(tbl.val) + Int64(2) * count(tbl.val)]
   02)--ProjectionExec: expr=[CAST(sum(tbl.val)@0 AS Decimal128(20, 0)) as 
__common_expr_1, count(tbl.val)@1 as count(tbl.val)]
   03)----AggregateExec: mode=Single, gby=[], aggr=[sum(tbl.val), 
count(tbl.val)]
   04)------DataSourceExec: partitions=1, partition_sizes=[2]
   
   statement ok
   DROP TABLE IF EXISTS tbl;
   ```
   
   The "rewritten" form retruns floats for some reason? not sure what that is 
about


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