-
Notifications
You must be signed in to change notification settings - Fork 705
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): Implement map_delete function #15480
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: shamb0 <r.raajey@gmail.com>
Hi @b41sh,
Thanks! |
Signed-off-by: shamb0 <r.raajey@gmail.com>
Hi @shamb0 , thanks for continuing to contribute code. https://github.com/datafuselabs/databend/blob/main/src/query/functions/src/scalars/string_multi_args.rs#L88 There are many more implementations of the factory function, and you can find more examples by searching the code base for The factory function is not written in the same way as the builtin function, it can support more flexible argument types, but it needs to deal with more problems, there are mainly the following steps: First of all, you need to check whether the input arguments are supported types, for the The second part of writing the logic for executing the function is that the input args are of type |
Thanks @b41sh, for sharing those details! I'll take a good look at the requirements and circle back with any questions or updates. |
Hi @shamb0 It's been a long time since last update, have you made any progress recently? |
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
Hi @b41sh, I've refactored the implementation to use a factory function instead of a built-in function. The proto implementation is ready for your review. Currently, it only supports the key variant of type |
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
Hi @shamb0 Thank you for your modification. There are still some minor problems that need to be modified. You can have a look at them when you are free. |
Hi @b41sh, Thank you for the review comments. I'll incorporate the suggested changes and have an updated version ready for your review soon. |
Signed-off-by: shamb0 <r.raajey@gmail.com>
Hi @b41sh, Code refactored based on the review comments. Appreciate the detailed feedback, it helped in making the necessary changes. |
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
Hi @b41sh, I've addressed all the comments and made the necessary changes. Please let me know if there's anything else that needs attention. Thanks, |
Signed-off-by: shamb0 <r.raajey@gmail.com>
…abend into feat-15295-map-ops-map-delete
Signed-off-by: shamb0 <r.raajey@gmail.com>
tests/sqllogictests/suites/query/functions/02_0074_function_map.test
Outdated
Show resolved
Hide resolved
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
|
||
let inner_builder_type = match input_map_sref.infer_data_type() { | ||
DataType::Map(box typ) => typ, | ||
DataType::EmptyMap => DataType::EmptyMap, |
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.
this can be removed, as the ScalarRef::Map(col)
can't have EmptyMap
type.
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 have a quick clarification regarding the test cases for the EmptyMap condition. I have captured the current behavior of the function as follows:
// Deleting keys from an empty map
run_ast(file, "map_delete({})", &[]);
run_ast(file, "map_delete({}, NULL, NULL)", &[]);
// Deleting keys from a map literal
run_ast(file, "map_delete({}, ['k3'], ['k2'])", &[]);
run_ast(
file,
"map_delete({'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k4': 'v4'}, 'k3', 'k2')",
&[],
);
Here are the unit test results:
error:
--> SQL:1:1
|
1 | map_delete({})
| ^^^^^^^^^^^^^^ no overload satisfies `map_delete(Map(Nothing))`
error:
--> SQL:1:1
|
1 | map_delete({}, NULL, NULL)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ no overload satisfies `map_delete(Map(Nothing), NULL, NULL)`
error:
--> SQL:1:1
|
1 | map_delete({}, ['k3'], ['k2'])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no overload satisfies `map_delete(Map(Nothing), Array(String), Array(String))`
Is this behavior aligned with the requirements? I couldn't find details for handling the EmptyMap condition in the documentation: Snowflake Documentation.
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.
These sqls do not match the type required by the map_delete
function. The first example has only one argument, and the second and third examples have the wrong type of key value, so return the error is correct.
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
} | ||
|
||
let map_key_type = match args_type[0].remove_nullable() { | ||
DataType::Map(box DataType::Tuple(type_tuple)) if type_tuple.len() == 2 => { |
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 need support EmptyMap
here, the previous code is correct, you can modify it back. Delete DataType::EmptyMap
on line 317 is because we have already processed the EmptyMap
type on line 299, so EmptyMap
type can't appear on line 317.
I think there is basically ok with the rest of the codes. After this modification is completed, we can merge this PR.
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.
Thankyou
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.
Hi @shamb0 , seems not correct. select map_delete({}, 'a')
will return SemanticError
, you can write like this:
let map_key_type = match args_type[0].remove_nullable() {
DataType::Map(box DataType::Tuple(type_tuple)) if type_tuple.len() == 2 => {
Some(type_tuple[0].clone())
}
DataType::EmptyMap => None,
_ => return None,
};
if let Some(map_key_type) = map_key_type {
for arg_type in args_type.iter().skip(1) {
if arg_type != &map_key_type {
return None;
}
}
} else {
let key_type = &args_type[1];
if !key_type.is_boolean()
&& !key_type.is_string()
&& !key_type.is_numeric()
&& !key_type.is_decimal()
&& !key_type.is_date_or_date_time()
{
return None;
}
for arg_type in args_type.iter().skip(2) {
if arg_type != key_type {
return None;
}
}
}
Please also remove DataType::EmptyMap => DataType::EmptyMap
at line 325, because this case will never matched.
Add a unit test for EmptyMap
, like map_delete({}, 'a', 'b')
. After these changes are complete, we can merge this PR.
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.
Hi @b41sh,
Changes are done, and I've added the suggested test case. Could you please double-check the result? It looks correct on my end.
ast : map_delete({}, 'a', 'b')
raw expr : map_delete(map(array(), array()), 'a', 'b')
checked expr : map_delete<Map(Nothing), String, String>(map<Array(Nothing), Array(Nothing)>(array<>(), array<>()), "a", "b")
optimized expr : {} :: Map(Nothing)
output type : Map(Nothing)
output domain : {}
output : {}
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
Signed-off-by: shamb0 <r.raajey@gmail.com>
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
Implement
map_delete
functionTests
Type of change
This change is