piyushgarg5021 commented on issue #15161:
URL: https://github.com/apache/datafusion/issues/15161#issuecomment-2715474312

   @scsmithr 
   
   The issue lies in the type coercion logic during query planning. The fix 
involves modifying the coercion rules to prioritize casting the string literal 
to the column's type instead of casting the column to Utf8.
   
   Changes Required:
   1. Modify Type Coercion Logic:
   - Update the coercion rules in the query planner to cast the string literal 
to the column's type when comparing a column with a literal.
   
   For example, in the query column1 < '10', the string literal '10' should be 
cast to Int64.
   
   2. Error Handling:
   - Ensure that invalid casts (e.g., 'hello' to Int64) result in an error 
during query planning or execution.
   
   **Implementation Plan:**
   
   1. Locate the type coercion logic in the DataFusion codebase (likely in the 
query planner or expression evaluation module).
   2. Modify the logic to prioritize casting the literal to the column's type.
   3. Add tests to verify the fix:
   - Test numeric string literals (e.g., '10').
   - Test non-numeric string literals (e.g., 'hello').
   - Test edge cases (e.g., empty strings, NULL values).
   
   // Updated coercion logic
   if left_type != right_type {
       if left_type.is_numeric() && right_type == DataType::Utf8 {
           // Cast right to left_type (e.g., cast '10' to Int64)
       } else if right_type.is_numeric() && left_type == DataType::Utf8 {
           // Cast left to right_type
       } else {
           // Handle other cases
       }
   }
   
   #[test]
   fn test_int_column_less_than_string_literal() {
       let sql = "select * from t1 where column1 < '10';";
       let expected = vec![1, 2, 3]; // Expected results after correct casting
       assert_eq!(execute_query(sql), expected);
   }
   
   #[test]
   fn test_int_column_less_than_invalid_string() {
       let sql = "select * from t1 where column1 < 'hello';";
       assert!(execute_query(sql).is_err()); // Should return an error
   }
   
   
   
   By follows that i think it is solve


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