-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insert target columns empty fix #5079
Merged
avantgardnerio
merged 3 commits into
apache:master
from
splitgraph:insert-target-columns-empty-fix
Jan 29, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,13 +165,60 @@ fn plan_insert() { | |
"insert into person (id, first_name, last_name) values (1, 'Alan', 'Turing')"; | ||
let plan = r#" | ||
Dml: op=[Insert] table=[person] | ||
Projection: CAST(column1 AS id AS UInt32), column2 AS first_name, column3 AS last_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
Projection: CAST(column1 AS UInt32) AS id, column2 AS first_name, column3 AS last_name | ||
Values: (Int64(1), Utf8("Alan"), Utf8("Turing")) | ||
"# | ||
.trim(); | ||
quick_test(sql, plan); | ||
} | ||
|
||
#[test] | ||
fn plan_insert_no_target_columns() { | ||
let sql = "INSERT INTO test_decimal VALUES (1, 2), (3, 4)"; | ||
let plan = r#" | ||
Dml: op=[Insert] table=[test_decimal] | ||
Projection: CAST(column1 AS Int32) AS id, CAST(column2 AS Decimal128(10, 2)) AS price | ||
Values: (Int64(1), Int64(2)), (Int64(3), Int64(4)) | ||
"# | ||
.trim(); | ||
quick_test(sql, plan); | ||
} | ||
|
||
#[rstest] | ||
#[case::duplicate_columns( | ||
"INSERT INTO test_decimal (id, price, price) VALUES (1, 2, 3), (4, 5, 6)", | ||
"Schema error: Schema contains duplicate unqualified field name 'price'" | ||
)] | ||
#[case::non_existing_column( | ||
"INSERT INTO test_decimal (nonexistent, price) VALUES (1, 2), (4, 5)", | ||
"Schema error: No field named 'nonexistent'. Valid fields are 'id', 'price'." | ||
)] | ||
#[case::type_mismatch( | ||
"INSERT INTO test_decimal SELECT '2022-01-01', to_timestamp('2022-01-01T12:00:00')", | ||
"Error during planning: Cannot automatically convert Timestamp(Nanosecond, None) to Decimal128(10, 2)" | ||
)] | ||
#[case::target_column_count_mismatch( | ||
"INSERT INTO person (id, first_name, last_name) VALUES ($1, $2)", | ||
"Error during planning: Column count doesn't match insert query!" | ||
)] | ||
#[case::source_column_count_mismatch( | ||
"INSERT INTO person VALUES ($1, $2)", | ||
"Error during planning: Column count doesn't match insert query!" | ||
)] | ||
#[case::extra_placeholder( | ||
"INSERT INTO person (id, first_name, last_name) VALUES ($1, $2, $3, $4)", | ||
"Error during planning: Placeholder $4 refers to a non existent column" | ||
)] | ||
#[case::placeholder_type_unresolved( | ||
"INSERT INTO person (id, first_name, last_name) VALUES ($2, $4, $6)", | ||
"Error during planning: Placeholder type could not be resolved" | ||
)] | ||
#[test] | ||
fn test_insert_schema_errors(#[case] sql: &str, #[case] error: &str) { | ||
let err = logical_plan(sql).unwrap_err(); | ||
assert_eq!(err.to_string(), error) | ||
} | ||
|
||
#[test] | ||
fn plan_update() { | ||
let sql = "update person set last_name='Kay' where id=1"; | ||
|
@@ -3464,36 +3511,6 @@ Dml: op=[Insert] table=[person] | |
prepare_stmt_replace_params_quick_test(plan, param_values, expected_plan); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Placeholder $4 refers to a non existent column")] | ||
fn test_prepare_statement_insert_infer_gt() { | ||
let sql = "insert into person (id, first_name, last_name) values ($1, $2, $3, $4)"; | ||
|
||
let expected_plan = r#""#.trim(); | ||
let expected_dt = "[Int32]"; | ||
let _ = prepare_stmt_quick_test(sql, expected_plan, expected_dt); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "value: Plan(\"Column count doesn't match insert query!\")")] | ||
fn test_prepare_statement_insert_infer_lt() { | ||
let sql = "insert into person (id, first_name, last_name) values ($1, $2)"; | ||
|
||
let expected_plan = r#""#.trim(); | ||
let expected_dt = "[Int32]"; | ||
let _ = prepare_stmt_quick_test(sql, expected_plan, expected_dt); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "value: Plan(\"Placeholder type could not be resolved\")")] | ||
fn test_prepare_statement_insert_infer_gap() { | ||
let sql = "insert into person (id, first_name, last_name) values ($2, $4, $6)"; | ||
|
||
let expected_plan = r#""#.trim(); | ||
let expected_dt = "[Int32]"; | ||
let _ = prepare_stmt_quick_test(sql, expected_plan, expected_dt); | ||
} | ||
|
||
#[test] | ||
fn test_prepare_statement_to_plan_one_param() { | ||
let sql = "PREPARE my_plan(INT) AS SELECT id, age FROM person WHERE age = $1"; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ Nice drive by cleanup