Skip to content
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

Please support writing map type directly in SQL #12462

Open
tigercl opened this issue Feb 2, 2024 · 2 comments
Open

Please support writing map type directly in SQL #12462

tigercl opened this issue Feb 2, 2024 · 2 comments
Assignees

Comments

@tigercl
Copy link
Member

tigercl commented Feb 2, 2024

What would you like to be added or enhanced?

Write directly in SQL to construct the map type, such as this:

SELECT
     {'a': {'b': 1}} as t1,
     map_put('b', {'c': 1}, t1) as t2
FROM "t/#"

Why is this needed?

All data types in the rule engine except map can be written directly in SQL, for example:

'a' as t1,
1 as t2,
[t1, t2] as t3

But for the map type, I can't write like this:

{'a': 1} as t1

This causes the SQL to become difficult to write and read when we want to construct a new map based on the fields extracted above:

SELECT
  '1' as t1,
  '2' as t2,
  '3' as t3,
  map_put('t3', t3, map_put('t2', t2, map_put('t1', t1, map_new()))) as t4
FROM
  "t/#"

or

SELECT
  '1' as t1,
  '2' as t2,
  '3' as t3,
  map_put('t1', t1, map_new()) as t4,
  map_put('t2', t2, t4) as t5,
  map_put('t3', t3, t5) as t6
FROM
  "t/#"

In addition, the introduction of map types in the documentation of built-in functions also seems incompatible with other types:

length([1,2,3,4]) = 4
map_get('b', map_put('b', 1, json_decode('{"a": 1}'))) = 1

# Rather Than:
map_get('a', {'a': {'b': {'c': 1}}}) = {'b': {'c': 1}}

I think there should not be a situation where a certain basic type cannot be written in a complete grammar system.

@tigercl tigercl added the Feature label Feb 2, 2024
@id id added the internal label Feb 6, 2024
@zmstone
Copy link
Member

zmstone commented Mar 5, 2024

string interpolation in general basically?
does this work good enough?

SELECT
  interpolate('{"a": ${payload.a}, "b": ${payload.b}}') as my_json_obj

NOTE: there is no such function yet.

@tigercl
Copy link
Member Author

tigercl commented Mar 6, 2024

Actually I'm more looking forward to this format:

SELECT
    {'key': value}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants