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 30a2d9bd3a0 [SPARK-38748][SQL][TESTS] Test the error class: 
PIVOT_VALUE_DATA_TYPE_MISMATCH
30a2d9bd3a0 is described below

commit 30a2d9bd3a0fbf19d6862f9a0904457fac16ff5d
Author: panbingkun <pbk1...@gmail.com>
AuthorDate: Fri Apr 29 09:29:35 2022 +0300

    [SPARK-38748][SQL][TESTS] Test the error class: 
PIVOT_VALUE_DATA_TYPE_MISMATCH
    
    ## What changes were proposed in this pull request?
    This PR aims to add a test for the error class 
PIVOT_VALUE_DATA_TYPE_MISMATCH 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 #36400 from panbingkun/SPARK-38748.
    
    Authored-by: panbingkun <pbk1...@gmail.com>
    Signed-off-by: Max Gekk <max.g...@gmail.com>
---
 .../sql/errors/QueryCompilationErrorsSuite.scala   | 24 +++++++++++++++++++++-
 1 file changed, 23 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 ec8edd2acd6..1115db07f21 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
@@ -20,7 +20,7 @@ package org.apache.spark.sql.errors
 import org.apache.spark.sql.{AnalysisException, IntegratedUDFTestUtils, 
QueryTest, Row}
 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.functions.{grouping, grouping_id, lit, struct, 
sum, udf}
 import org.apache.spark.sql.internal.SQLConf
 import org.apache.spark.sql.types.{IntegerType, MapType, StringType, 
StructField, StructType}
 
@@ -491,6 +491,28 @@ class QueryCompilationErrorsSuite
         msg = "Field name c.X is ambiguous and has 2 matching fields in the 
struct.; line 1 pos 0")
     }
   }
+
+  test("PIVOT_VALUE_DATA_TYPE_MISMATCH: can't cast pivot value data type 
(struct) " +
+    "to pivot column data type (int)") {
+    val df = Seq(
+      ("dotNET", 2012, 10000),
+      ("Java", 2012, 20000),
+      ("dotNET", 2012, 5000),
+      ("dotNET", 2013, 48000),
+      ("Java", 2013, 30000)
+    ).toDF("course", "year", "earnings")
+
+    checkErrorClass(
+      exception = intercept[AnalysisException] {
+        df.groupBy(df("course")).pivot(df("year"), Seq(
+          struct(lit("dotnet"), lit("Experts")),
+          struct(lit("java"), lit("Dummies")))).
+          agg(sum($"earnings")).collect()
+      },
+      errorClass = "PIVOT_VALUE_DATA_TYPE_MISMATCH",
+      msg = "Invalid pivot value 'struct(col1, dotnet, col2, Experts)': value 
data type " +
+        "struct<col1:string,col2:string> does not match pivot column data type 
int")
+  }
 }
 
 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