Weijun-H commented on code in PR #12194:
URL: https://github.com/apache/datafusion/pull/12194#discussion_r1732794203


##########
datafusion/functions-nested/src/utils.rs:
##########
@@ -253,6 +254,21 @@ pub(crate) fn compute_array_dims(
     }
 }
 
+pub(crate) fn get_map_entry_field(data_type: &DataType) -> Result<&Fields> {
+    match data_type {
+        DataType::Map(field, _) => {
+            let field_data_type = field.data_type();
+            match field_data_type {
+                DataType::Struct(fields) => Ok(fields),
+                _ => {
+                    _internal_err!("Expected a Struct type, got {:?}", 
field_data_type)
+                }
+            }
+        }
+        _ => _internal_err!("Expected a Map type, got {:?}", data_type),
+    }
+}
+

Review Comment:
   👍 



##########
datafusion/sqllogictest/test_files/map.slt:
##########
@@ -568,8 +568,49 @@ select map_extract(column1, 1), map_extract(column1, 5), 
map_extract(column1, 7)
 [] [[4, , 6]] []
 [] [] [[1, , 3]]
 
+# Tests for map_keys
+
+query ?
+SELECT map_keys(MAP { 'a': 1, 2: 3 });
+----
+[a, 2]
+
+query ?
+SELECT map_keys(MAP {'a':1, 'b':2, 'c':3 }) FROM t;
+----
+[a, b, c]
+[a, b, c]
+[a, b, c]
+
+query ?
+SELECT map_keys(Map{column1: column2, column3: column4}) FROM t;
+----
+[a, k1]
+[b, k3]
+[d, k5]
+
+query ?
+SELECT map_keys(map(column5, column6)) FROM t;
+----
+[k1, k2]
+[k3]
+[k5]
+
+query ?
+SELECT map_keys(map(column8, column9)) FROM t;
+----
+[[1, 2, 3]]
+[[4]]
+[[1, 2]]
+
+query ?
+SELECT map_keys(Map{});
+----
+[]
+

Review Comment:
   ```suggestion
   SELECT map_keys(column1) from map_array_table_1;
   ```



-- 
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]

Reply via email to