goldmedal commented on issue #10688:
URL: https://github.com/apache/datafusion/issues/10688#issuecomment-2137711858

   > I think it is because the first `-128.2` is read as float 32, then treated 
as float 64. I said "treated" because I don't see there is cast expression. It 
may be happened when DataFusion parses float literal and resolves its data type.
   
   Agreed. I also found it.
   ```
   > explain select 128.2::float;
   +---------------+------------------------------------------------+
   | plan_type     | plan                                           |
   +---------------+------------------------------------------------+
   | logical_plan  | Projection: Float32(128.2) AS Float64(128.2)   |
   |               |   EmptyRelation                                |
   | physical_plan | ProjectionExec: expr=[128.2 as Float64(128.2)] |
   |               |   PlaceholderRowExec                           |
   |               |                                                |
   +---------------+------------------------------------------------+
   2 row(s) fetched. 
   Elapsed 0.004 seconds.
   
   > explain select 128.2;
   +---------------+------------------------------------------------+
   | plan_type     | plan                                           |
   +---------------+------------------------------------------------+
   | logical_plan  | Projection: Float64(128.2)                     |
   |               |   EmptyRelation                                |
   | physical_plan | ProjectionExec: expr=[128.2 as Float64(128.2)] |
   |               |   PlaceholderRowExec                           |
   |               |                                                |
   +---------------+------------------------------------------------+
   2 row(s) fetched. 
   Elapsed 0.004 seconds.
   
   > explain select 128.2::double;
   +---------------+------------------------------------------------+
   | plan_type     | plan                                           |
   +---------------+------------------------------------------------+
   | logical_plan  | Projection: Float64(128.2)                     |
   |               |   EmptyRelation                                |
   | physical_plan | ProjectionExec: expr=[128.2 as Float64(128.2)] |
   |               |   PlaceholderRowExec                           |
   |               |                                                |
   +---------------+------------------------------------------------+
   2 row(s) fetched. 
   Elapsed 0.003 seconds.
   
   > explain select -128.2 union all select -128.2::double;
   +---------------+----------------------------------------------------+
   | plan_type     | plan                                               |
   +---------------+----------------------------------------------------+
   | logical_plan  | Union                                              |
   |               |   Projection: Float64(-128.2) AS Float64(-128.2)   |
   |               |     EmptyRelation                                  |
   |               |   Projection: Float64(-128.2) AS Float64(-128.2)   |
   |               |     EmptyRelation                                  |
   | physical_plan | UnionExec                                          |
   |               |   ProjectionExec: expr=[-128.2 as Float64(-128.2)] |
   |               |     PlaceholderRowExec                             |
   |               |   ProjectionExec: expr=[-128.2 as Float64(-128.2)] |
   |               |     PlaceholderRowExec                             |
   |               |                                                    |
   +---------------+----------------------------------------------------+
   2 row(s) fetched. 
   Elapsed 0.008 seconds.
   
   > explain select -128.2 union all select -128.2::float;
   
+---------------+----------------------------------------------------------------+
   | plan_type     | plan                                                       
    |
   
+---------------+----------------------------------------------------------------+
   | logical_plan  | Union                                                      
    |
   |               |   Projection: Float64(-128.2) AS Float64(-128.2)           
    |
   |               |     EmptyRelation                                          
    |
   |               |   Projection: Float64(-128.1999969482422) AS 
Float64(-128.2)   |
   |               |     EmptyRelation                                          
    |
   | physical_plan | UnionExec                                                  
    |
   |               |   ProjectionExec: expr=[-128.2 as Float64(-128.2)]         
    |
   |               |     PlaceholderRowExec                                     
    |
   |               |   ProjectionExec: expr=[-128.1999969482422 as 
Float64(-128.2)] |
   |               |     PlaceholderRowExec                                     
    |
   |               |                                                            
    |
   
+---------------+----------------------------------------------------------------+
   2 row(s) fetched. 
   Elapsed 0.008 seconds.
   ````
   
   If we cast `128.2` to `double`, the value won't be changed. I guess the 
reason is that DataFusion performs type coercion between float32 and float64 
when combining two select plans.


-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to