You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* draft commit to rolledback changes on function naming and include prepare clause on the infer types tests
* include data types in plan when it is not included in the prepare statement
* fix: prepare statement error
* Update datafusion/sql/src/statement.rs
Co-authored-by: Andrew Lamb <[email protected]>
* remove infer types from prepare statement
the infer data type changes in statement will be introduced in a new PR
* fix to show correct output message
* remove white space
* Restore the original tests too
---------
Co-authored-by: Andrew Lamb <[email protected]>
let sql = "PREPARE my_plan AS SELECT id, age FROM person WHERE age = (select max(age) from person where id = $1)";
4819
+
4820
+
let plan = logical_plan(sql).unwrap();
4821
+
assert_snapshot!(
4822
+
plan,
4823
+
@r#"
4824
+
Prepare: "my_plan" []
4825
+
Projection: person.id, person.age
4826
+
Filter: person.age = (<subquery>)
4827
+
Subquery:
4828
+
Projection: max(person.age)
4829
+
Aggregate: groupBy=[[]], aggr=[[max(person.age)]]
4830
+
Filter: person.id = $1
4831
+
TableScan: person
4832
+
TableScan: person
4833
+
"#
4834
+
);
4835
+
4836
+
let actual_types = plan.get_parameter_types().unwrap();
4837
+
let expected_types = HashMap::from([("$1".to_string(),Some(DataType::UInt32))]);
4838
+
assert_eq!(actual_types, expected_types);
4839
+
}
4840
+
4752
4841
#[test]
4753
4842
fntest_update_infer(){
4754
4843
let sql = "update person set age=$1 where id=$2";
@@ -4786,6 +4875,30 @@ fn test_update_infer() {
4786
4875
);
4787
4876
}
4788
4877
4878
+
#[test]
4879
+
fntest_prepare_statement_update_infer(){
4880
+
let sql = "PREPARE my_plan AS update person set age=$1 where id=$2";
4881
+
4882
+
let plan = logical_plan(sql).unwrap();
4883
+
assert_snapshot!(
4884
+
plan,
4885
+
@r#"
4886
+
Prepare: "my_plan" []
4887
+
Dml: op=[Update] table=[person]
4888
+
Projection: person.id AS id, person.first_name AS first_name, person.last_name AS last_name, $1 AS age, person.state AS state, person.salary AS salary, person.birth_date AS birth_date, person.😀 AS 😀
4889
+
Filter: person.id = $2
4890
+
TableScan: person
4891
+
"#
4892
+
);
4893
+
4894
+
let actual_types = plan.get_parameter_types().unwrap();
4895
+
let expected_types = HashMap::from([
4896
+
("$1".to_string(),Some(DataType::Int32)),
4897
+
("$2".to_string(),Some(DataType::UInt32)),
4898
+
]);
4899
+
assert_eq!(actual_types, expected_types);
4900
+
}
4901
+
4789
4902
#[test]
4790
4903
fntest_insert_infer(){
4791
4904
let sql = "insert into person (id, first_name, last_name) values ($1, $2, $3)";
@@ -4824,6 +4937,29 @@ fn test_insert_infer() {
4824
4937
);
4825
4938
}
4826
4939
4940
+
#[test]
4941
+
fntest_prepare_statement_insert_infer(){
4942
+
let sql = "PREPARE my_plan AS insert into person (id, first_name, last_name) values ($1, $2, $3)";
4943
+
let plan = logical_plan(sql).unwrap();
4944
+
assert_snapshot!(
4945
+
plan,
4946
+
@r#"
4947
+
Prepare: "my_plan" []
4948
+
Dml: op=[Insert Into] table=[person]
4949
+
Projection: column1 AS id, column2 AS first_name, column3 AS last_name, CAST(NULL AS Int32) AS age, CAST(NULL AS Utf8) AS state, CAST(NULL AS Float64) AS salary, CAST(NULL AS Timestamp(Nanosecond, None)) AS birth_date, CAST(NULL AS Int32) AS 😀
4950
+
Values: ($1, $2, $3)
4951
+
"#
4952
+
);
4953
+
4954
+
let actual_types = plan.get_parameter_types().unwrap();
4955
+
let expected_types = HashMap::from([
4956
+
("$1".to_string(),Some(DataType::UInt32)),
4957
+
("$2".to_string(),Some(DataType::Utf8)),
4958
+
("$3".to_string(),Some(DataType::Utf8)),
4959
+
]);
4960
+
assert_eq!(actual_types, expected_types);
4961
+
}
4962
+
4827
4963
#[test]
4828
4964
fntest_prepare_statement_to_plan_one_param(){
4829
4965
let sql = "PREPARE my_plan(INT) AS SELECT id, age FROM person WHERE age = $1";
0 commit comments