Skip to content

arrayMap(x -> x + 1, [1, 2, 3]) returns wrong result #16

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
l1t1 opened this issue Nov 7, 2024 · 3 comments
Closed

arrayMap(x -> x + 1, [1, 2, 3]) returns wrong result #16

l1t1 opened this issue Nov 7, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@l1t1
Copy link

l1t1 commented Nov 7, 2024

it should return [2,3,4], rather than [1,4,9], others also wrong

D SELECT arrayMap(x -> x + 1, [1, 2, 3]); 
┌────────────────────────────────────────────────────┐
│ arraymap((x -> (x + 1)), main.list_value(1, 2, 3)) │
│                      int32[]                       │
├────────────────────────────────────────────────────┤
│ [1, 4, 9]                                          │
└────────────────────────────────────────────────────┘
D SELECT arrayMap(x -> x -1, [1, 2, 3]); --also wrong
┌────────────────────────────────────────────────────┐
│ arraymap((x -> (x - 1)), main.list_value(1, 2, 3)) │
│                      int32[]                       │
├────────────────────────────────────────────────────┤
│ [1, 4, 9]                                          │
└────────────────────────────────────────────────────┘
D SELECT arrayMap(x -> x, [1, 2, 3]); --also wrong
┌──────────────────────────────────────────────┐
│ arraymap((x -> x), main.list_value(1, 2, 3)) │
│                   int32[]                    │
├──────────────────────────────────────────────┤
│ [1, 4, 9]                                    │
└──────────────────────────────────────────────┘
@lmangani
Copy link
Collaborator

lmangani commented Nov 7, 2024

Thanks for the report! The macro indeed requires a patch to correctly accept and execute the lambda function.
In order to correctly register macros with lamba expressions we need to use a custom loader to retain the type.

@lmangani lmangani added the bug Something isn't working label Nov 7, 2024
@lmangani
Copy link
Collaborator

lmangani commented Nov 7, 2024

Big has been fixed in master and will be part of next release tonight. Thanks for the report @l1t1

D SELECT arrayMap(x -> x + 1, [1, 2, 3]);
┌────────────────────────────────────────────────────┐
│ arraymap((x -> (x + 1)), main.list_value(1, 2, 3)) │
│                      int32[]                       │
├────────────────────────────────────────────────────┤
│ [2, 3, 4]                                          │
└────────────────────────────────────────────────────┘
D SELECT arrayMap(x -> x + 10, [1, 2, 3]);
┌─────────────────────────────────────────────────────┐
│ arraymap((x -> (x + 10)), main.list_value(1, 2, 3)) │
│                       int32[]                       │
├─────────────────────────────────────────────────────┤
│ [11, 12, 13]                                        │
└─────────────────────────────────────────────────────┘

Note: the lambda expression syntax requires using x

@lmangani
Copy link
Collaborator

lmangani commented Nov 7, 2024

Fixed in chsql v1.0.6 for DuckDB v1.1.3

@lmangani lmangani closed this as completed Nov 7, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants