-
Notifications
You must be signed in to change notification settings - Fork 752
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
feat(function): Support generic Array access elements by index #5244
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Thanks for the contribution! Please review the labels and make any necessary changes. |
} | ||
} else { | ||
return Err(ErrorCode::IllegalDataType(format!( | ||
"Array column only support accessed by index, but got {:#?}", |
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.
If array only support accessed by index, we should not use path_keys
.
I think the better way is to parse the path column into integer index column.
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.
The purpose of using path_keys
is to reuse the parse_path_keys
function. It seems that the access method of the array column and variant column is somewhat different. We can rewrite a function to generate an index path key.
ab22b1b
to
ace0b7f
Compare
What's the purpose of get_path of array? It seems same as normal get. |
|
let inner_column: &<$T as Scalar>::ColumnType = Series::check_get(array_column.values())?; | ||
let mut builder = NullableColumnBuilder::<$T>::with_capacity(input_rows); | ||
|
||
for index in indexes.iter() { |
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.
I think it's incorrect, what if index's size is not 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.
if the index is from a table column, we will have multi indexes.
for example:
mysql> create table t (index uint64);
mysql> insert into t values(0),(1),(2);
mysql> select get([1,2,3,4], index) from t;
+--------------------------+
| get([1, 2, 3, 4], index) |
+--------------------------+
| 1 |
| 2 |
| 3 |
+--------------------------+
3 rows in set (0.05 sec)
@@ -68,4 +72,10 @@ select id, json_extract_path_text(str, '["a"]') from t3; | |||
select id, json_extract_path_text(str, 'b.c') from t3; | |||
select id, json_extract_path_text(str, '["b"]["c"]') from t3; | |||
|
|||
select '==get from array table=='; | |||
select id, get(arr, 0) from t4; |
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.
get(arr, number % 2 ) from t4;
LGTM |
e0d41cd
to
8239842
Compare
let data_type = args[0]; | ||
let path_type = args[1]; | ||
|
||
if !data_type.data_type_id().is_array() || !path_type.data_type_id().is_integer() { |
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.
What if index is negative?
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.
currently, we don't support index by a negative number, a error will return.
mysql> select get(v, -1) from arr;
ERROR 1105 (HY000): Code: 1010, displayText = Unexpected type:Int64 to get u64 number (while in processor thread 0).
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.
Sorry, I have not seen as_u64
method.
let index_column: &PrimitiveColumn<$T2> = Series::check_get(columns[1].column())?; | ||
let mut offset = 0; | ||
for i in 0..input_rows { | ||
let index = index_column.get(i).as_u64()? as usize; |
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.
we should not use get(i)
to construct a datavalue and convert it into as_u64
for (row, index) in index_column.iter().enumerate() {
if index < 0 { ...}
....
}
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.
ok
@mergify update |
1 similar comment
@mergify update |
✅ Branch has been successfully updated |
❌ Base branch update has failedexpected head sha didn’t match current head ref. |
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
Support accessing elements of generic
Array
by indexChangelog
Related Issues
Fixes #5224