Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.apache.spark.sql

import org.apache.spark.SparkThrowable
import org.apache.spark.{SparkException, SparkRuntimeException}
import org.apache.spark.sql.QueryTest.sameRows
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.{Cast, Literal}
Expand Down Expand Up @@ -359,16 +359,24 @@ class VariantEndToEndSuite extends QueryTest with SharedSparkSession {
val expectedMetadata: Array[Byte] = Array(VERSION, 3, 0, 1, 2, 3, 'a', 'b', 'c')
assert(actual === new VariantVal(expectedValue, expectedMetadata))
}
withSQLConf(SQLConf.VARIANT_ALLOW_DUPLICATE_KEYS.key -> "false") {
val df = Seq(json).toDF("j")
.selectExpr("from_json(j,'variant')")
checkError(
exception = intercept[SparkThrowable] {
// Check whether the parse_json and from_json expressions throw the correct exception.
Seq("from_json(j, 'variant')", "parse_json(j)").foreach { expr =>
withSQLConf(SQLConf.VARIANT_ALLOW_DUPLICATE_KEYS.key -> "false") {
val df = Seq(json).toDF("j").selectExpr(expr)
val exception = intercept[SparkException] {
df.collect()
},
condition = "MALFORMED_RECORD_IN_PARSING.WITHOUT_SUGGESTION",
parameters = Map("badRecord" -> json, "failFastMode" -> "FAILFAST")
)
}
checkError(
exception = exception,
condition = "MALFORMED_RECORD_IN_PARSING.WITHOUT_SUGGESTION",
parameters = Map("badRecord" -> json, "failFastMode" -> "FAILFAST")
)
checkError(
exception = exception.getCause.asInstanceOf[SparkRuntimeException],
condition = "VARIANT_DUPLICATE_KEY",
parameters = Map("key" -> "a")
)
}
}
}
}