| 4924 | |
| 4925 | #[test] |
| 4926 | fn test_fmt_sql() -> Result<()> { |
| 4927 | let schema = Schema::new(vec![ |
| 4928 | Field::new("a", DataType::Int32, false), |
| 4929 | Field::new("b", DataType::Int32, false), |
| 4930 | ]); |
| 4931 | |
| 4932 | // Test basic binary expressions |
| 4933 | let simple_expr = binary_expr( |
| 4934 | col("a", &schema)?, |
| 4935 | Operator::Plus, |
| 4936 | col("b", &schema)?, |
| 4937 | &schema, |
| 4938 | )?; |
| 4939 | let display_string = simple_expr.to_string(); |
| 4940 | assert_eq!(display_string, "a@0 + b@1"); |
| 4941 | let sql_string = fmt_sql(&simple_expr).to_string(); |
| 4942 | assert_eq!(sql_string, "a + b"); |
| 4943 | |
| 4944 | // Test nested expressions with different operator precedence |
| 4945 | let nested_expr = binary_expr( |
| 4946 | Arc::new(binary_expr( |
| 4947 | col("a", &schema)?, |
| 4948 | Operator::Plus, |
| 4949 | col("b", &schema)?, |
| 4950 | &schema, |
| 4951 | )?), |
| 4952 | Operator::Multiply, |
| 4953 | col("b", &schema)?, |
| 4954 | &schema, |
| 4955 | )?; |
| 4956 | let display_string = nested_expr.to_string(); |
| 4957 | assert_eq!(display_string, "(a@0 + b@1) * b@1"); |
| 4958 | let sql_string = fmt_sql(&nested_expr).to_string(); |
| 4959 | assert_eq!(sql_string, "(a + b) * b"); |
| 4960 | |
| 4961 | // Test nested expressions with same operator precedence |
| 4962 | let nested_same_prec = binary_expr( |
| 4963 | Arc::new(binary_expr( |
| 4964 | col("a", &schema)?, |
| 4965 | Operator::Plus, |
| 4966 | col("b", &schema)?, |
| 4967 | &schema, |
| 4968 | )?), |
| 4969 | Operator::Plus, |
| 4970 | col("b", &schema)?, |
| 4971 | &schema, |
| 4972 | )?; |
| 4973 | let display_string = nested_same_prec.to_string(); |
| 4974 | assert_eq!(display_string, "a@0 + b@1 + b@1"); |
| 4975 | let sql_string = fmt_sql(&nested_same_prec).to_string(); |
| 4976 | assert_eq!(sql_string, "a + b + b"); |
| 4977 | |
| 4978 | // Test with literals |
| 4979 | let lit_expr = binary_expr( |
| 4980 | col("a", &schema)?, |
| 4981 | Operator::Eq, |
| 4982 | lit(ScalarValue::Int32(Some(42))), |
| 4983 | &schema, |