Apache DataFusion SQL Query Engine
fix string coercion missing in Eq/NotEq operator (#2258)
DuRipeng22b70b8eeb10
diff --git a/datafusion/core/tests/sql/select.rs b/datafusion/core/tests/sql/select.rsindex b5179d08a3..8ce74ebf68 100644--- a/datafusion/core/tests/sql/select.rs+++ b/datafusion/core/tests/sql/select.rs@@ -958,6 +958,44 @@ async fn parallel_query_with_filter() -> Result<()> {Ok(())}+#[tokio::test]+async fn query_with_filter_string_type_coercion() {+ let large_string_array = LargeStringArray::from(vec!["1", "2", "3", "4", "5"]);+ let schema =+ Schema::new(vec![Field::new("large_string", DataType::LargeUtf8, false)]);+ let batch =+ RecordBatch::try_new(Arc::new(schema), vec![Arc::new(large_string_array)])+ .unwrap();++ let ctx = SessionContext::new();+ let table = MemTable::try_new(batch.schema(), vec![vec![batch]]).unwrap();+ ctx.register_table("t", Arc::new(table)).unwrap();+ let sql = "select * from t where large_string = '1'";+ let actual = execute_to_batches(&ctx, sql).await;+ let expected = vec![+ "+--------------+",+ "| large_string |",+ "+--------------+",+ "| 1 |",+ "+--------------+",+ ];+ assert_batches_eq!(expected, &actual);++ let sql = "select * from t where large_string != '1'";+ let actual = execute_to_batches(&ctx, sql).await;+ let expected = vec![+ "+--------------+",+ "| large_string |",+ "+--------------+",+ "| 2 |",+ "| 3 |",+ "| 4 |",+ "| 5 |",+ "+--------------+",+ ];+ assert_batches_eq!(expected, &actual);+}+#[tokio::test]async fn query_empty_table() {let ctx = SessionContext::new();diff --git a/datafusion/physical-expr/src/coercion_rule/binary_rule.rs b/datafusion/physical-expr/src/coercion_rule/binary_rule.rsindex b09fc340f8..1233ed9800 100644--- a/datafusion/physical-expr/src/coercion_rule/binary_rule.rs+++ b/datafusion/physical-expr/src/coercion_rule/binary_rule.rs@@ -116,6 +116,7 @@ fn comparison_eq_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<Dacomparison_binary_numeric_coercion(lhs_type, rhs_type).or_else(|| dictionary_coercion(lhs_type, rhs_type)).or_else(|| temporal_coercion(lhs_type, rhs_type))+ .or_else(|| string_coercion(lhs_type, rhs_type))}fn comparison_order_coercion(