Raza Jafri created SPARK-39015:
----------------------------------

             Summary: SparkRuntimeException when trying to get non-existent key 
in a map
                 Key: SPARK-39015
                 URL: https://issues.apache.org/jira/browse/SPARK-39015
             Project: Spark
          Issue Type: Bug
          Components: Spark Core
    Affects Versions: 3.3.0
            Reporter: Raza Jafri


[~maxgekk] submitted a 
[commit|https://github.com/apache/spark/commit/bc8c264851457d8ef59f5b332c79296651ec5d1e]
 that tries to convert the key to SQL but that part of the code is blowing up. 

```
scala> :pa
// Entering paste mode (ctrl-D to finish)

import org.apache.spark.sql.Row
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.types.StringType
import org.apache.spark.sql.types.DataTypes

val arrayStructureData = Seq(
Row(Map("hair"->"black", "eye"->"brown")),
Row(Map("hair"->"blond", "eye"->"blue")),
Row(Map()))

val mapType  = DataTypes.createMapType(StringType,StringType)

val arrayStructureSchema = new StructType()
.add("properties", mapType)



val mapTypeDF = spark.createDataFrame(
    spark.sparkContext.parallelize(arrayStructureData),arrayStructureSchema)

mapTypeDF.selectExpr("element_at(properties, 'hair')").show

// Exiting paste mode, now interpreting.

+----------------------------+
|element_at(properties, hair)|
+----------------------------+
|                       black|
|                       blond|
|                        null|
+----------------------------+

scala>     spark.conf.set("spark.sql.ansi.enabled", true)

scala> mapTypeDF.selectExpr("element_at(properties, 'hair')").show
22/04/25 18:26:01 ERROR Executor: Exception in task 6.0 in stage 5.0 (TID 23)
org.apache.spark.SparkRuntimeException: The feature is not supported: literal 
for 'hair' of class org.apache.spark.unsafe.types.UTF8String.
        at 
org.apache.spark.sql.errors.QueryExecutionErrors$.literalTypeUnsupportedError(QueryExecutionErrors.scala:240)
 ~[spark-catalyst_2.12-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
        at 
org.apache.spark.sql.catalyst.expressions.Literal$.apply(literals.scala:101) 
~[spark-catalyst_2.12-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
        at 
org.apache.spark.sql.errors.QueryErrorsBase.toSQLValue(QueryErrorsBase.scala:44)
 ~[spark-catalyst_2.12-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
        at 
org.apache.spark.sql.errors.QueryErrorsBase.toSQLValue$(QueryErrorsBase.scala:43)
 ~[spark-catalyst_2.12-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
        at 
org.apache.spark.sql.errors.QueryExecutionErrors$.toSQLValue(QueryExecutionErrors.scala:69)
 ~[spark-catalyst_2.12-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]


```



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to