goldmedal commented on code in PR #11361:
URL: https://github.com/apache/datafusion/pull/11361#discussion_r1674235631
##########
datafusion/sqllogictest/test_files/map.slt:
##########
@@ -100,3 +100,93 @@ physical_plan
statement ok
drop table table_with_map;
+
+query ?
+SELECT MAKE_MAP('POST', 41, 'HEAD', 33, 'PATCH', 30, 'OPTION', 29, 'GET', 27,
'PUT', 25, 'DELETE', 24) AS method_count;
+----
+{POST: 41, HEAD: 33, PATCH: 30, OPTION: 29, GET: 27, PUT: 25, DELETE: 24}
+
+query I
+SELECT MAKE_MAP('POST', 41, 'HEAD', 33)['POST'];
+----
+41
+
+query ?
+SELECT MAKE_MAP('POST', 41, 'HEAD', 33, 'PATCH', null);
+----
+{POST: 41, HEAD: 33, PATCH: }
+
+query ?
+SELECT MAKE_MAP('POST', null, 'HEAD', 33, 'PATCH', null);
+----
+{POST: , HEAD: 33, PATCH: }
+
+query ?
+SELECT MAKE_MAP(1, null, 2, 33, 3, null);
+----
+{1: , 2: 33, 3: }
+
+query ?
+SELECT MAKE_MAP([1,2], ['a', 'b'], [3,4], ['b']);
+----
+{[1, 2]: [a, b], [3, 4]: [b]}
+
+query error DataFusion error: Execution error: map requires all values to have
the same type Int64, got Utf8 instead at position 1
+SELECT MAKE_MAP('POST', 41, 'HEAD', 'ab', 'PATCH', 30);
+
+query error DataFusion error: Execution error: make_map key cannot be null at
position 2
+SELECT MAKE_MAP('POST', 41, 'HEAD', 33, null, 30);
+
+query error DataFusion error: Execution error: make_map requires all keys to
have the same type Utf8, got Int64 instead at position 1
+SELECT MAKE_MAP('POST', 41, 123, 33,'PATCH', 30);
+
+query error
+SELECT MAKE_MAP()
+
+query error DataFusion error: Execution error: make_map requires an even
number of arguments, got 3 instead
+SELECT MAKE_MAP('POST', 41, 'HEAD');
+
+query ?
+SELECT MAP(['POST', 'HEAD', 'PATCH'], [41, 33, 30]);
+----
+{POST: 41, HEAD: 33, PATCH: 30}
+
+query ?
+SELECT MAP(['POST', 'HEAD', 'PATCH'], [41, 33, null]);
+----
+{POST: 41, HEAD: 33, PATCH: }
+
+query ?
+SELECT MAP([[1,2], [3,4]], ['a', 'b']);
+----
+{[1, 2]: a, [3, 4]: b}
+
+query error
+SELECT MAP()
+
+query error DataFusion error: Execution error: map requires an even number of
arguments, got 1 instead
+SELECT MAP(['POST', 'HEAD'])
+
+query error DataFusion error: Execution error: Expected list, large_list or
fixed_size_list, got Null
+SELECT MAP(null, [41, 33, 30]);
+
+query error DataFusion error: Execution error: map requires key and value
lists to have the same length
+SELECT MAP(['POST', 'HEAD', 'PATCH'], [41, 33]);
+
+query error DataFusion error: Execution error: map key cannot be null
+SELECT MAP(['POST', 'HEAD', null], [41, 33, 30]);
+
+query ?
+SELECT MAP(make_array('POST', 'HEAD', 'PATCH'), make_array(41, 33, 30));
+----
+{POST: 41, HEAD: 33, PATCH: 30}
+
+query ?
+SELECT MAP(arrow_cast(make_array('POST', 'HEAD', 'PATCH'), 'FixedSizeList(3,
Utf8)'), arrow_cast(make_array(41, 33, 30), 'FixedSizeList(3, Int64)'));
+----
+{POST: 41, HEAD: 33, PATCH: 30}
+
+query ?
+SELECT MAP(arrow_cast(make_array('POST', 'HEAD', 'PATCH'), 'LargeList(Utf8)'),
arrow_cast(make_array(41, 33, 30), 'LargeList(Int64)'));
+----
+{POST: 41, HEAD: 33, PATCH: 30}
Review Comment:
I had some challenges in transforming the array values to the map array
layout. If the given table and SQL are
```
statement ok
create table t as values
('a', 1, 'k1', 10),
('b', 2, 'k3', 30),
('d', 4, 'k5', 50);
query ?
SELECT make_map(column1, column2, column3, column4) FROM t;
----
{a: 1, k1: 10}
{b: 2, k3: 30}
{d: 4, k5: 50}
```
We'll get the keys like
```
[datafusion/functions/src/core/map.rs:37:5] &key = [
Array(
StringArray
[
"a",
"b",
"d",
],
),
Array(
StringArray
[
"k1",
"k3",
"k5",
],
),
]
```
I think I need to aggregate them into one array like
```
["a", "k1", "b", "k3", "d", "k5"]
```
And then, I can give the offsets when building MapArray
```
[0,2,4,6]
```
However, I have no good idea for array aggregation now. I handle the array
value by throwing `not_impl_err` currently. Maybe we can solve it in the
follow-up PR.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]