Skip to content

ArrayIndex support with expression as key #2442

@ovr

Description

@ovr

Hello!

SELECT r.value[1 + 1] FROM (SELECT array[1,2,3] as value, 1 as key UNION ALL SELECT array[1,2,3] as value, 1 as key) as r;
+------------------------------+
| r.value[Int64(1) + Int64(1)] |
+------------------------------+
| 3                            |
| 3                            |
+------------------------------+
SELECT r.key, r.value[r.key] FROM (SELECT array[1,2,3] as value, 1 as key UNION ALL SELECT array[1,2,3] as value, 1 as key) as r;
+-----+----------------+
| key | r.value[r.key] |
+-----+----------------+
| 1   | 2              |
| 1   | 2              |
+-----+----------------+
SELECT (ARRAY[1,2,3])[1 + 1];

Describe the solution you'd like

I would like to split GetIndexedExpr into MapAccessExpr (will continue to accept key as ScalarValue) & ArrayIndexExpr (will use PhysicalExpr for key)

Describe alternatives you've considered

Making key as PhysicalExprfor GetIndexedExpr but it makes a problem with type detection for a field of a Struct type. Probably, it's why PostgreSQL doesn't allow expression in MapAccess.

Additional context

I have drafted already a branch that supports it.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions