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

maxgekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b81aaad1e9 [SPARK-38740][SQL][TESTS] Test the error class: 
INVALID_JSON_SCHEMA_MAPTYPE
3b81aaad1e9 is described below

commit 3b81aaad1e9420fe537c7871e6ae337d5a34f881
Author: panbingkun <pbk1...@gmail.com>
AuthorDate: Sun Apr 24 10:34:38 2022 +0300

    [SPARK-38740][SQL][TESTS] Test the error class: INVALID_JSON_SCHEMA_MAPTYPE
    
    ## What changes were proposed in this pull request?
    This PR aims to add a test for the error class INVALID_JSON_SCHEMA_MAPTYPE 
to `QueryCompilationErrorsSuite`.
    
    ### Why are the changes needed?
    The changes improve test coverage, and document expected error messages in 
tests.
    
    ### Does this PR introduce any user-facing change?
    No
    
    ### How was this patch tested?
    By running new test:
    ```
    $ build/sbt "sql/testOnly *QueryCompilationErrorsSuite*"
    ```
    
    Closes #36298 from panbingkun/SPARK-38740.
    
    Authored-by: panbingkun <pbk1...@gmail.com>
    Signed-off-by: Max Gekk <max.g...@gmail.com>
---
 .../spark/sql/errors/QueryCompilationErrorsSuite.scala | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git 
a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
 
b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
index 23e512993c4..66d7465c184 100644
--- 
a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
+++ 
b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
@@ -22,7 +22,7 @@ import org.apache.spark.sql.api.java.{UDF1, UDF2, UDF23Test}
 import org.apache.spark.sql.expressions.SparkUserDefinedFunction
 import org.apache.spark.sql.functions.{grouping, grouping_id, sum, udf}
 import org.apache.spark.sql.internal.SQLConf
-import org.apache.spark.sql.types.{IntegerType, StringType}
+import org.apache.spark.sql.types.{IntegerType, MapType, StringType, 
StructField, StructType}
 
 case class StringLongClass(a: String, b: Long)
 
@@ -393,6 +393,22 @@ class QueryCompilationErrorsSuite
         sqlState = Some("22023"))
     }
   }
+
+  test("INVALID_JSON_SCHEMA_MAPTYPE: " +
+    "Parse JSON rows can only contain StringType as a key type for a 
MapType.") {
+    val schema = StructType(
+      StructField("map", MapType(IntegerType, IntegerType, true), false) :: 
Nil)
+
+    checkErrorClass(
+      exception = intercept[AnalysisException] {
+        spark.read.schema(schema).json(spark.emptyDataset[String])
+      },
+      errorClass = "INVALID_JSON_SCHEMA_MAPTYPE",
+      msg = "Input schema " +
+        
"StructType(StructField(map,MapType(IntegerType,IntegerType,true),false)) " +
+        "can only contain StringType as a key type for a MapType."
+    )
+  }
 }
 
 class MyCastToString extends SparkUserDefinedFunction(


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

Reply via email to