-
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
fix: add ArrayAndElementAndOptionalIndex
for proper casting in array_position
#9233
Changes from 3 commits
c2f76f9
2d7b78b
64b4be3
3cc94ac
b19e3c8
2a83ab4
466f2c9
5086f31
4ec6289
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,31 @@ fn get_valid_types( | |
_ => Ok(vec![vec![]]), | ||
} | ||
} | ||
fn array_append_and_optional_index( | ||
current_types: &[DataType], | ||
) -> Result<Vec<Vec<DataType>>> { | ||
// make sure there's at least 2 arguments | ||
if !(current_types.len() == 2 || current_types.len() == 3) { | ||
return Ok(vec![vec![]]); | ||
} | ||
|
||
let first_two_types = ¤t_types[0..2]; | ||
let valid_types = array_append_or_prepend_valid_types(first_two_types, true)?; | ||
|
||
let valid_types_with_index = valid_types | ||
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. We can optionally append valid_types_with_index if the length is 3, otherwise, return here. 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. Thanks! Addressed in 5086f31. |
||
.iter() | ||
.map(|t| { | ||
let mut t = t.clone(); | ||
t.push(DataType::Int64); | ||
t | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
let mut valid_types = valid_types; | ||
valid_types.extend(valid_types_with_index); | ||
|
||
Ok(valid_types) | ||
} | ||
fn array_and_index(current_types: &[DataType]) -> Result<Vec<Vec<DataType>>> { | ||
if current_types.len() != 2 { | ||
return Ok(vec![vec![]]); | ||
|
@@ -184,6 +209,9 @@ fn get_valid_types( | |
ArrayFunctionSignature::ArrayAndElement => { | ||
return array_append_or_prepend_valid_types(current_types, true) | ||
} | ||
ArrayFunctionSignature::ArrayAndElementAndOptionalIndex => { | ||
return array_append_and_optional_index(current_types) | ||
} | ||
ArrayFunctionSignature::ArrayAndIndex => { | ||
return array_and_index(current_types) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2603,6 +2603,16 @@ select array_position(arrow_cast(make_array([1, 2, 3], [4, 5, 6], [5, 5, 5], [4, | |
---- | ||
2 2 | ||
|
||
query I | ||
SELECT array_position(arrow_cast([5, 2, 3, 4, 5], 'List(Int32)'), 5) | ||
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. For the record, this test fails on main like this:
|
||
---- | ||
1 | ||
|
||
query I | ||
SELECT array_position(arrow_cast([5, 2, 3, 4, 5], 'List(Int32)'), 5, 2) | ||
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. Can we please add a few more tests:
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. Thanks for the feedback...
Because this PR is leveraging the append's casting functionality, this seems to be the current behavior on main for append:
I guess as I user I'd think if the array_append case would work, I'd also expect array_position to work like that. FWIW duckdb works for both array_append and Anyways, happy to go either way, just thought I'd bring it up before delving further. 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. For the second case, we return NULL which is compatible with Postgres behavior, so I think it is acceptable. You can just add the test case to make sure we got NULL
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. Sounds good... added in 4ec6289 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. Thanks for adding the tests and doing the background research |
||
---- | ||
5 | ||
|
||
# list_position scalar function #5 (function alias `array_position`) | ||
query III | ||
select list_position(['h', 'e', 'l', 'l', 'o'], 'l'), list_position([1, 2, 3, 4, 5], 5), list_position([1, 1, 1], 1); | ||
|
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.
array_element_and_optional_index
seems a better nameThere 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.
Also in 5086f31