You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "goldmedal (via GitHub)" <gi...@apache.org> on 2024/08/02 17:31:16 UTC
[I] Access a Map with a non-string keys [datafusion]
goldmedal opened a new issue, #11785:
URL: https://github.com/apache/datafusion/issues/11785
### Describe the bug
Currently, we support creating a map like
```
SELECT MAKE_MAP(1, 'a', 2, 'b', 3, 'c');
----
{1: a, 2: b, 3: c}
```
However, we can't access this map if its key isn't a string.
```
SELECT MAKE_MAP(1, 'a', 2, 'b', 3, 'c')[1]
```
It will get the error
```
External error: query failed: DataFusion error: Error during planning: Error during planning: Coercion from [Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false), Int64] to the signature ArraySignature(ArrayAndIndex) failed. No function matches the given name and argument types 'array_element(Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false), Int64)'. You might need to add explicit type casts.
Candidate functions:
array_element(array, index)
```
If the key is a string, it works well.
```
query T
SELECT MAKE_MAP('1', 'a', '2', 'b', '3', 'c')['1']
----
a
```
### To Reproduce
As mentioned above, create a map with non-string keys and try to access it by the key.
### Expected behavior
Given the SQL
```
SELECT MAKE_MAP(1, 'a', 2, 'b', 3, 'c')[1]
```
It should return the value `'a'`.
### Additional context
https://github.com/apache/datafusion/pull/11780#discussion_r1702121012
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Access a Map with a non-string keys [datafusion]
Posted by "dharanad (via GitHub)" <gi...@apache.org>.
dharanad commented on issue #11785:
URL: https://github.com/apache/datafusion/issues/11785#issuecomment-2265914647
take
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Access a Map with a non-string keys [datafusion]
Posted by "dharanad (via GitHub)" <gi...@apache.org>.
dharanad commented on issue #11785:
URL: https://github.com/apache/datafusion/issues/11785#issuecomment-2265852901
Interesting, I can give it a try.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Access a Map with a non-string keys [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #11785: Access a Map with a non-string keys
URL: https://github.com/apache/datafusion/issues/11785
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Access a Map with a non-string keys [datafusion]
Posted by "dharanad (via GitHub)" <gi...@apache.org>.
dharanad commented on issue #11785:
URL: https://github.com/apache/datafusion/issues/11785#issuecomment-2287082683
> I think `map_extract` function can benefit this issue #11969
I will prioritise this issue
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Access a Map with a non-string keys [datafusion]
Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on issue #11785:
URL: https://github.com/apache/datafusion/issues/11785#issuecomment-2286494676
I think `map_extract` function can benefit this issue #11969
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Access a Map with a non-string keys [datafusion]
Posted by "dharanad (via GitHub)" <gi...@apache.org>.
dharanad commented on issue #11785:
URL: https://github.com/apache/datafusion/issues/11785#issuecomment-2320815451
Seems like a bug with `GetFieldFunc` function
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Access a Map with a non-string keys [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on issue #11785:
URL: https://github.com/apache/datafusion/issues/11785#issuecomment-2644158363
This is still a problem. The error message requires the index to be Int64, but it doesn't work even if it is Int64
```
query error
SELECT column1[arrow_cast(1, 'Int64')] FROM map_array_table_1
----
DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'array_element' function: coercion from [Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false), Int64] to the signature ArraySignature(ArrayAndIndexes(1)) failed No function matches the given name and argument types 'array_element(Map(Field { name: "entries", data_type: Struct([Field { name: "key", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "value", data_type: List(Field { name: "item", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered:
false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }, false), Int64)'. You might need to add explicit type casts.
Candidate functions:
array_element(array, index)
```
cc @jayzhan211
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org