ShashidharM0118 opened a new pull request, #19419:
URL: https://github.com/apache/datafusion/pull/19419

   ## Which issue does this PR close?
   
   - Closes #19416
   
   ## Rationale for this change
   
   Currently, when projecting literal values (constants) in projection 
operations, the statistics are set to unknown 
(`ColumnStatistics::new_unknown()`). This prevents the optimizer from using 
constant column information for various optimizations, such as:
   
   - Sort elimination when sorting by constant columns
   
   ## What changes are included in this PR?
   
   1. **Updated `project_statistics` method** in `ProjectionExprs`:
   
      - Added detection and statistics calculation for `Literal` expressions 
(non-null constants)
      - Statistics calculated: `min_value = max_value = literal value`, 
`distinct_count = 1`, `null_count = 0`, `byte_size = data_type_width × 
num_rows` (for primitive types)
      - NULL literals return `ColumnStatistics::new_unknown()`
   
   2. **Added test**:
      - `test_project_statistics_with_literal`: Tests non-null literal 
statistics
   
   ## Are these changes tested?
   
   Yes
   
   ## Are there any user-facing changes?
   
   No 
   
   ## Example
   
   **Before this change:**
   `SELECT 42 AS status, name FROM users ORDER BY status ` - Statistics for 
`status` were unknown
   - Optimizer couldn't eliminate the sort operation
   
   **After this change:**
   `SELECT 42 AS status, name FROM users ORDER BY status` - Statistics show 
`status` has `min_value = max_value = 42`, `distinct_count = 1`
   - Optimizer can eliminate the sort since the column is already sorted (all 
values are the same)


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