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

Unparse Map plan to SQL string #13478

Open
goldmedal opened this issue Nov 19, 2024 · 0 comments
Open

Unparse Map plan to SQL string #13478

goldmedal opened this issue Nov 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@goldmedal
Copy link
Contributor

Is your feature request related to a problem or challenge?

It's similar to #13477. We use the scalar function to handle the Map type but we should unparse it back to the right SQL.

Map Literal

The SQL for creating a MAP:

select MAP {'a': 1, 'b': 2}

The plan:

  Plan: Projection: map(make_array(Utf8("a"), Utf8("b")), make_array(Int64(1), Int64(2)))
EmptyRelation

Unparse the plan:

SELECT map(make_array('a', 'b'), make_array(1, 2))

Access a MAP

The SQL for accessing a MAP:

select map_col['a'] from (select MAP {'a': 1, 'b': 2} as map_col)

The plan:

Projection: get_field(map_col, Utf8("a"))
  Projection: map(make_array(Utf8("a"), Utf8("b")), make_array(Int64(1), Int64(2))) AS map_col
    EmptyRelation

Unparse the plan

SELECT get_field(map_col, 'a') FROM (SELECT map(make_array('a', 'b'), make_array(1, 2)) AS map_col)

Describe the solution you'd like

The SQL should be able to roundtrip for SQL-Plan-SQL.

  • The map with make_array function should be unparsed to ast::Expr::Map
  • The get_fields for MAP should be unparsed to ast::Expr::MapAccess

Describe alternatives you've considered

No response

Additional context

No response

@goldmedal goldmedal added the enhancement New feature or request label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant