datafuselabs / databend

๐——๐—ฎ๐˜๐—ฎ, ๐—”๐—ป๐—ฎ๐—น๐˜†๐˜๐—ถ๐—ฐ๐˜€ & ๐—”๐—œ. Modern alternative to Snowflake. Cost-effective and simple for massive-scale analytics. https://databend.com
https://docs.databend.com
Other
7.31k stars 704 forks source link

feat(functions): add map_insert function #15567

Open hanxuanliang opened 2 weeks ago

hanxuanliang commented 2 weeks ago

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

part of https://github.com/datafuselabs/databend/issues/15295

Tests

Type of change


This change isโ€‚Reviewable

hanxuanliang commented 2 weeks ago

However, there is such a description in Snowflake:

If updateFlag is set to TRUE, then the existing input key is updated to the input value

But in Databend, do we support dynamically setting config in the query? Alternatively, we can set the config when querying with the bendsql?

b41sh commented 2 weeks ago

However, there is such a description in Snowflake:

If updateFlag is set to TRUE, then the existing input key is updated to the input value

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 map_insert, for example st_geometryfromwkb can support two and three args.

hanxuanliang commented 1 week ago

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 ๐Ÿ˜ฃ

b41sh commented 1 week ago

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 {..})) => ...,
    (_, _) => ...,
}