Skip to content
Closed
Show file tree
Hide file tree
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
12 changes: 3 additions & 9 deletions core/src/test/scala/org/apache/spark/SparkFunSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ abstract class SparkFunSuite
protected def checkError(
exception: SparkThrowable,
errorClass: String,
errorSubClass: Option[String],
sqlState: Option[String],
parameters: Map[String, String],
errorSubClass: Option[String] = None,
sqlState: Option[String] = None,
parameters: Map[String, String] = Map.empty,
matchPVals: Boolean = false): Unit = {
assert(exception.getErrorClass === errorClass)
if (exception.getErrorSubClass != null) {
Expand Down Expand Up @@ -335,12 +335,6 @@ abstract class SparkFunSuite
parameters: Map[String, String]): Unit =
checkError(exception, errorClass, None, Some(sqlState), parameters)

protected def checkError(
exception: SparkThrowable,
errorClass: String,
parameters: Map[String, String]): Unit =
checkError(exception, errorClass, None, None, parameters)

class LogAppender(msg: String = "", maxEvents: Int = 1000)
extends AbstractAppender("logAppender", null, null, true, Property.EMPTY_ARRAY) {
private val _loggingEvents = new ArrayBuffer[LogEvent]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ class EncoderResolutionSuite extends PlanTest {
test("the real type is not compatible with encoder schema: non-array field") {
val encoder = ExpressionEncoder[ArrayClass]
val attrs = Seq($"arr".int)
checkError(exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
checkError(
exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
errorClass = "UNSUPPORTED_DESERIALIZER",
errorSubClass = Some("DATA_TYPE_MISMATCH"),
parameters = Map("desiredType" -> "\"ARRAY\"", "dataType" -> "\"INT\""),
sqlState = None)
parameters = Map("desiredType" -> "\"ARRAY\"", "dataType" -> "\"INT\""))
}

test("the real type is not compatible with encoder schema: array element type") {
Expand All @@ -140,11 +140,11 @@ class EncoderResolutionSuite extends PlanTest {

withClue("inner element is not array") {
val attrs = Seq($"nestedArr".array(new StructType().add("arr", "int")))
checkError(exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
checkError(
exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
errorClass = "UNSUPPORTED_DESERIALIZER",
errorSubClass = Some("DATA_TYPE_MISMATCH"),
parameters = Map("desiredType" -> "\"ARRAY\"", "dataType" -> "\"INT\""),
sqlState = None)
parameters = Map("desiredType" -> "\"ARRAY\"", "dataType" -> "\"INT\""))
}

withClue("nested array element type is not compatible") {
Expand Down Expand Up @@ -177,22 +177,22 @@ class EncoderResolutionSuite extends PlanTest {

{
val attrs = Seq($"a".string, $"b".long, $"c".int)
checkError(exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
checkError(
exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
errorClass = "UNSUPPORTED_DESERIALIZER",
errorSubClass = Some("FIELD_NUMBER_MISMATCH"),
parameters = Map("schema" -> "\"STRUCT<a: STRING, b: BIGINT, c: INT>\"",
"ordinal" -> "2"),
sqlState = None)
"ordinal" -> "2"))
}

{
val attrs = Seq($"a".string)
checkError(exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
checkError(
exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
errorClass = "UNSUPPORTED_DESERIALIZER",
errorSubClass = Some("FIELD_NUMBER_MISMATCH"),
parameters = Map("schema" -> "\"STRUCT<a: STRING>\"",
"ordinal" -> "2"),
sqlState = None)
"ordinal" -> "2"))
}
}

Expand All @@ -201,22 +201,22 @@ class EncoderResolutionSuite extends PlanTest {

{
val attrs = Seq($"a".string, $"b".struct($"x".long, $"y".string, $"z".int))
checkError(exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
checkError(
exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
errorClass = "UNSUPPORTED_DESERIALIZER",
errorSubClass = Some("FIELD_NUMBER_MISMATCH"),
parameters = Map("schema" -> "\"STRUCT<x: BIGINT, y: STRING, z: INT>\"",
"ordinal" -> "2"),
sqlState = None)
"ordinal" -> "2"))
}

{
val attrs = Seq($"a".string, $"b".struct($"x".long))
checkError(exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
checkError(
exception = intercept[AnalysisException](encoder.resolveAndBind(attrs)),
errorClass = "UNSUPPORTED_DESERIALIZER",
errorSubClass = Some("FIELD_NUMBER_MISMATCH"),
parameters = Map("schema" -> "\"STRUCT<x: BIGINT>\"",
"ordinal" -> "2"),
sqlState = None)
"ordinal" -> "2"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,10 @@ class StructTypeSuite extends SparkFunSuite with SQLHelper {
e = intercept[AnalysisException] {
check(Seq("S2", "x"), None)
}
checkError(e, "AMBIGUOUS_COLUMN_OR_FIELD",
Map("name" -> "`S2`.`x`", "n" -> "2"))
checkError(
exception = e,
errorClass = "AMBIGUOUS_COLUMN_OR_FIELD",
parameters = Map("name" -> "`S2`.`x`", "n" -> "2"))
caseSensitiveCheck(Seq("s2", "x"), Some(Seq("s2") -> StructField("x", IntegerType)))

// simple map type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,15 @@ class DatasetUnpivotSuite extends QueryTest
valueColumnName = "val"
)
}
checkErrorClass(
checkError(
exception = e,
errorClass = "UNPIVOT_VALUE_DATA_TYPE_MISMATCH",
msg = "Unpivot value columns must share a least common type, some types do not: \\[" +
"\"STRING\" \\(`str1#\\d+`\\), " +
"\"INT\" \\(`int1#\\d+`, `int2#\\d+`, `int3#\\d+`, ...\\), " +
"\"BIGINT\" \\(`long1#\\d+L`, `long2#\\d+L`\\)\\];(\n.*)*",
matchMsg = true)
parameters = Map(
"types" ->
(""""STRING" \(`str1#\d+`\), """ +
""""INT" \(`int1#\d+`, `int2#\d+`, `int3#\d+`, ...\), """ +
""""BIGINT" \(`long1#\d+L`, `long2#\d+L`\)""")),
matchPVals = true)
}

test("unpivot with compatible value types") {
Expand Down Expand Up @@ -358,12 +359,12 @@ class DatasetUnpivotSuite extends QueryTest
valueColumnName = "val"
)
}
checkErrorClass(
checkError(
exception = e1,
errorClass = "UNRESOLVED_COLUMN",
msg = "A column or function parameter with name `1` cannot be resolved\\. " +
"Did you mean one of the following\\? \\[`id`, `int1`, `str1`, `str2`, `long1`\\];(\n.*)*",
matchMsg = true)
parameters = Map(
"objectName" -> "`1`",
"objectList" -> "`id`, `int1`, `str1`, `str2`, `long1`"))

// unpivoting where value column does not exist
val e2 = intercept[AnalysisException] {
Expand All @@ -374,12 +375,12 @@ class DatasetUnpivotSuite extends QueryTest
valueColumnName = "val"
)
}
checkErrorClass(
checkError(
exception = e2,
errorClass = "UNRESOLVED_COLUMN",
msg = "A column or function parameter with name `does` cannot be resolved\\. " +
"Did you mean one of the following\\? \\[`id`, `int1`, `long1`, `str1`, `str2`\\];(\n.*)*",
matchMsg = true)
parameters = Map(
"objectName" -> "`does`",
"objectList" -> "`id`, `int1`, `long1`, `str1`, `str2`"))

// unpivoting with empty list of value columns
// where potential value columns are of incompatible types
Expand All @@ -391,14 +392,14 @@ class DatasetUnpivotSuite extends QueryTest
valueColumnName = "val"
)
}
checkErrorClass(
checkError(
exception = e3,
errorClass = "UNPIVOT_VALUE_DATA_TYPE_MISMATCH",
msg = "Unpivot value columns must share a least common type, some types do not: \\[" +
"\"INT\" \\(`id#\\d+`, `int1#\\d+`\\), " +
"\"STRING\" \\(`str1#\\d+`, `str2#\\d+`\\), " +
"\"BIGINT\" \\(`long1#\\d+L`\\)\\];(\n.*)*",
matchMsg = true)
parameters = Map("types" ->
(""""INT" \(`id#\d+`, `int1#\d+`\), """ +
""""STRING" \(`str1#\d+`, `str2#\d+`\), """ +
""""BIGINT" \(`long1#\d+L`\)""")),
matchPVals = true)

// unpivoting with star id columns so that no value columns are left
val e4 = intercept[AnalysisException] {
Expand All @@ -409,12 +410,10 @@ class DatasetUnpivotSuite extends QueryTest
valueColumnName = "val"
)
}
checkErrorClass(
checkError(
exception = e4,
errorClass = "UNPIVOT_REQUIRES_VALUE_COLUMNS",
msg = "At least one value column needs to be specified for UNPIVOT, " +
"all columns specified as ids;(\\n.*)*",
matchMsg = true)
parameters = Map())

// unpivoting with star value columns
// where potential value columns are of incompatible types
Expand All @@ -426,14 +425,14 @@ class DatasetUnpivotSuite extends QueryTest
valueColumnName = "val"
)
}
checkErrorClass(
checkError(
exception = e5,
errorClass = "UNPIVOT_VALUE_DATA_TYPE_MISMATCH",
msg = "Unpivot value columns must share a least common type, some types do not: \\[" +
"\"INT\" \\(`id#\\d+`, `int1#\\d+`\\), " +
"\"STRING\" \\(`str1#\\d+`, `str2#\\d+`\\), " +
"\"BIGINT\" \\(`long1#\\d+L`\\)\\];(\n.*)*",
matchMsg = true)
parameters = Map("types" ->
(""""INT" \(`id#\d+`, `int1#\d+`\), """ +
""""STRING" \(`str1#\d+`, `str2#\d+`\), """ +
""""BIGINT" \(`long1#\d+L`\)""")),
matchPVals = true)

// unpivoting without giving values and no non-id columns
val e6 = intercept[AnalysisException] {
Expand All @@ -444,12 +443,10 @@ class DatasetUnpivotSuite extends QueryTest
valueColumnName = "val"
)
}
checkErrorClass(
checkError(
exception = e6,
errorClass = "UNPIVOT_REQUIRES_VALUE_COLUMNS",
msg = "At least one value column needs to be specified for UNPIVOT, " +
"all columns specified as ids;(\\n.*)*",
matchMsg = true)
parameters = Map.empty)
}

test("unpivot after pivot") {
Expand Down Expand Up @@ -499,14 +496,13 @@ class DatasetUnpivotSuite extends QueryTest
valueColumnName = "val"
)
}
checkErrorClass(
checkError(
exception = e,
errorClass = "UNRESOLVED_COLUMN",
// expected message is wrong: https://issues.apache.org/jira/browse/SPARK-39783
msg = "A column or function parameter with name `an`\\.`id` cannot be resolved\\. " +
"Did you mean one of the following\\? " +
"\\[`an`.`id`, `int1`, `long1`, `str`.`one`, `str`.`two`\\];(\n.*)*",
matchMsg = true)
parameters = Map(
"objectName" -> "`an`.`id`",
"objectList" -> "`an`.`id`, `int1`, `long1`, `str`.`one`, `str`.`two`"))
}

test("unpivot with struct fields") {
Expand Down
Loading