This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 342cfdf0e1 feat: support get_field for map literal (#18371)
342cfdf0e1 is described below

commit 342cfdf0e11060ac506a4b494f2c2e5dfeb5d857
Author: Chen Chongchen <[email protected]>
AuthorDate: Fri Oct 31 01:06:52 2025 +0800

    feat: support get_field for map literal (#18371)
    
    ## Which issue does this PR close?
    
    
    
    ## Rationale for this change
    
    currently, get_field for map only supports column.
    
    ## What changes are included in this PR?
    
    support get_field for map literal
    
    ## Are these changes tested?
    
    UT
    
    ## Are there any user-facing changes?
    
    No
---
 datafusion/functions-nested/src/planner.rs |  5 +----
 datafusion/sqllogictest/test_files/map.slt | 32 ++++++++++++++++++++----------
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/datafusion/functions-nested/src/planner.rs 
b/datafusion/functions-nested/src/planner.rs
index f4fa8630a8..4fec5e3806 100644
--- a/datafusion/functions-nested/src/planner.rs
+++ b/datafusion/functions-nested/src/planner.rs
@@ -18,7 +18,6 @@
 //! SQL planning extensions like [`NestedFunctionPlanner`] and 
[`FieldAccessPlanner`]
 
 use arrow::datatypes::DataType;
-use datafusion_common::ExprSchema;
 use datafusion_common::{plan_err, utils::list_ndims, DFSchema, Result};
 use datafusion_expr::expr::ScalarFunction;
 use datafusion_expr::expr::{AggregateFunction, AggregateFunctionParams};
@@ -177,9 +176,7 @@ impl ExprPlanner for FieldAccessPlanner {
                         )),
                     )),
                     // special case for map access with
-                    Expr::Column(ref c)
-                        if matches!(schema.data_type(c)?, DataType::Map(_, _)) 
=>
-                    {
+                    _ if matches!(expr.get_type(schema)?, DataType::Map(_, _)) 
=> {
                         Ok(PlannerResult::Planned(Expr::ScalarFunction(
                             ScalarFunction::new_udf(
                                 get_field_inner(),
diff --git a/datafusion/sqllogictest/test_files/map.slt 
b/datafusion/sqllogictest/test_files/map.slt
index fc21638b3f..949edb8376 100644
--- a/datafusion/sqllogictest/test_files/map.slt
+++ b/datafusion/sqllogictest/test_files/map.slt
@@ -526,11 +526,23 @@ SELECT MAP { 'a': 1, 'b': 3 };
 query error DataFusion error: Arrow error: Cast error: Cannot cast string 'a' 
to value of Int64 type
 SELECT MAP { 'a': 1, 2: 3 };
 
-# TODO(https://github.com/apache/datafusion/issues/11785): fix accessing map 
with non-string key
-# query ?
-# SELECT MAP { 1: 'a', 2: 'b', 3: 'c' }[1];
-# ----
-# a
+# accessing map with non-string key
+query T
+SELECT MAP { 1: 'a', 2: 'b', 3: 'c' }[1];
+----
+a
+
+# accessing map with string key
+query I
+SELECT MAP { 'a': 1, 'b': 2, 'c': 3 }['a'];
+----
+1
+
+# accessing map with non-string key in case expression
+query I
+SELECT (CASE WHEN 1 > 0 THEN MAP {'x': 100} ELSE MAP {'y': 200} END)['x']; 
+----
+100
 
 # TODO(https://github.com/apache/datafusion/issues/11785): fix accessing map 
with non-string key
 # query ?
@@ -538,11 +550,11 @@ SELECT MAP { 'a': 1, 2: 3 };
 # ----
 # 1
 
-# TODO(https://github.com/apache/datafusion/issues/11785): fix accessing map 
with non-string key
-# query ?
-# SELECT MAKE_MAP(1, null, 2, 33, 3, null)[2];
-# ----
-# 33
+# accessing map with non-string key
+query I
+SELECT MAKE_MAP(1, null, 2, 33, 3, null)[2];
+----
+33
 
 ## cardinality
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to