Support `map_keys` for MAP type
Which issue does this PR close?
Closes #12147
Rationale for this change
What changes are included in this PR?
- Added
map_keysscalar function. Ref : https://duckdb.org/docs/sql/functions/map.html#map_valuesmap
Are these changes tested?
Are there any user-facing changes?
Encounter a bug. Fixed it by changing field name to item. But why ?
Internal error: Failed due to a difference in schemas, original schema: DFSchema { inner: Schema { fields: [Field { name: "map_keys(map(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(1),Int64(2),Int64(3))))", data_type: List(Field { name: "keys", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {} }, field_qualifiers: [None], functional_dependencies: FunctionalDependencies { deps: [] } }, new schema: DFSchema { inner: Schema { fields: [Field { name: "map_keys(map(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(1),Int64(2),Int64(3))))", data_type: List(Field { name: "item", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {} }, field_qualifiers: [None], functional_dependencies: FunctionalDependencies { deps: [] } }.
Encounter a bug. Fixed it by changing field name to
item. But why ?Internal error: Failed due to a difference in schemas, original schema: DFSchema { inner: Schema { fields: [Field { name: "map_keys(map(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(1),Int64(2),Int64(3))))", data_type: List(Field { name: "keys", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {} }, field_qualifiers: [None], functional_dependencies: FunctionalDependencies { deps: [] } }, new schema: DFSchema { inner: Schema { fields: [Field { name: "map_keys(map(make_array(Int64(1),Int64(2),Int64(3)),make_array(Int64(1),Int64(2),Int64(3))))", data_type: List(Field { name: "item", data_type: Int64, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }), nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {} }, field_qualifiers: [None], functional_dependencies: FunctionalDependencies { deps: [] } }.
I think it is caused by the pre-defined field name in make_array.
https://github.com/apache/datafusion/blob/7e9ea3ad59071d56093c197c5ecd5c50021deb94/datafusion/functions-nested/src/map.rs#L33-L39
@dharanad could you add some doc for this function?
Sorry for the mess, i thought since the change was similar for both map_keys && map_values why not club it.
After fixing CI, it is ready to go
After fixing CI, it is ready to go
@Weijun-H Any idea, how do i fix the docs formatting issue
After fixing CI, it is ready to go
@Weijun-H Any idea, how do i fix the docs formatting issue
You could check here https://datafusion.apache.org/contributor-guide/howtos.html#how-to-format-md-document
ship it!
Thanks @dharanad contribution, and @Blizzara and @jayzhan211 for reviewing.
Thank You @Weijun-H @jayzhan211 @Blizzara