-
Notifications
You must be signed in to change notification settings - Fork 734
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(functions): add map_insert function #15567
base: main
Are you sure you want to change the base?
feat(functions): add map_insert function #15567
Conversation
However, there is such a description in Snowflake:
But in Databend, do we support dynamically setting config in the query? Alternatively, we can set the config when querying with the bendsql? |
We can register a new function with four arguments for |
|
||
registry.register_3_arg_core::<EmptyMapType, GenericType<0>, GenericType<1>, MapType<GenericType<0>, GenericType<1>>, _, _>( | ||
"map_insert", | ||
|_, _, _, _| FunctionDomain::Full, |
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 can build map domain from key domain and value domain.
085cead
to
f4ae992
Compare
But, I have discovered a problem now: CREATE TABLE map_insert_test(col_str Map(String, String Null) Not Null, col_int Map(String, Int Null) Null);
SELECT map_insert(col_int, 'a', 100)
FROM map_insert_test; For the NULL map, it is currently stuck and unable to run. However, I tried to modify the domain calculation, but it had no effect. I have no idea here 😣 |
Both val_domain and insert_value_domain may be nullable, and we need to deal with various cases, such as match (val_domain, insert_value_domain) {
(Domain::Nullable(NullableDomain {..}), Domain::Nullable(NullableDomain {..})) => ...,
(Domain::Nullable(NullableDomain {..}), _) => ...,
(_, Domain::Nullable(NullableDomain {..})) => ...,
(_, _) => ...,
} |
d3ad954
to
35c6a6e
Compare
insert_value_domain.clone(), | ||
))) | ||
}, | ||
|_, key, value, ctx| { |
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.
use vectorize_with_builder_3_arg
here, so that we can support column values in this function
&& !key_type.is_decimal() | ||
&& !key_type.is_date_or_date_time() | ||
{ | ||
ctx.set_error(0, format!("map keys can not be {}", key_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.
if has error, we should return at here.
@@ -244,4 +252,144 @@ pub fn register(registry: &mut FunctionRegistry) { | |||
.any(|(k, _)| k == key) | |||
}, | |||
); | |||
|
|||
registry.register_3_arg_core::<EmptyMapType, GenericType<0>, GenericType<1>, MapType<GenericType<0>, GenericType<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.
EmptyMapType
also need support 4 arguments with update_flag
, use register_4_arg_core
register another function.
FunctionDomain::Domain(match source_domain.has_null { | ||
true => Some(( | ||
insert_key_domain.clone(), | ||
insert_value_domain.clone(), |
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.
insert_key_domain
and insert_value_domain
need merge with the key and value domain in source_domain
.
|
||
registry.register_passthrough_nullable_3_arg( | ||
"map_insert", | ||
|_, domain1, key_domain, value_domain| { |
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 function can be removed, as we already have register_3_arg_core
function
); | ||
|
||
// grammar: map_insert(map, insert_key, insert_value, allow_update) | ||
registry.register_passthrough_nullable_4_arg( |
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.
use register_4_arg_core
here like the previous one.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
part of #15295
Tests
Type of change
This change is