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
18 changes: 0 additions & 18 deletions core/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
"GROUPING_SIZE_LIMIT_EXCEEDED" : {
"message" : [ "Grouping sets size cannot be greater than %s" ]
},
"IF_PARTITION_NOT_EXISTS_UNSUPPORTED" : {
"message" : [ "Cannot write, IF NOT EXISTS is not supported for table: %s" ]
},
"ILLEGAL_SUBSTRING" : {
"message" : [ "%s cannot contain %s." ]
},
Expand Down Expand Up @@ -141,10 +138,6 @@
"message" : [ "Unrecognized SQL type %s" ],
"sqlState" : "42000"
},
"UNSUPPORTED_CHANGE_COLUMN" : {
"message" : [ "Please add an implementation for a column change here" ],
"sqlState" : "0A000"
},
"UNSUPPORTED_DATATYPE" : {
"message" : [ "Unsupported data type %s" ],
"sqlState" : "0A000"
Expand All @@ -153,17 +146,6 @@
"message" : [ "The feature is not supported: %s" ],
"sqlState" : "0A000"
},
"UNSUPPORTED_LITERAL_TYPE" : {
"message" : [ "Unsupported literal type %s %s" ],
"sqlState" : "0A000"
},
"UNSUPPORTED_SIMPLE_STRING_WITH_NODE_ID" : {
"message" : [ "%s does not implement simpleStringWithNodeId" ]
},
"UNSUPPORTED_TRANSACTION_BY_JDBC_SERVER" : {
"message" : [ "The target JDBC server does not support transaction and can only support ALTER TABLE with a single action." ],
"sqlState" : "0A000"
},
"WRITING_JOB_ABORTED" : {
"message" : [ "Writing job aborted" ],
"sqlState" : "40000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ abstract class Expression extends TreeNode[Expression] {
}

override def simpleStringWithNodeId(): String = {
throw QueryExecutionErrors.simpleStringWithNodeIdUnsupportedError(nodeName)
throw new IllegalStateException(s"$nodeName does not implement simpleStringWithNodeId")
}

protected def typeSuffix =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.apache.spark.sql.catalyst.expressions
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.codegen.{UnsafeArrayWriter, UnsafeRowWriter, UnsafeWriter}
import org.apache.spark.sql.catalyst.util.ArrayData
import org.apache.spark.sql.errors.QueryExecutionErrors
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{UserDefinedType, _}
import org.apache.spark.unsafe.Platform
Expand Down Expand Up @@ -254,7 +253,8 @@ object InterpretedUnsafeProjection {
(_, _) => {}

case _ =>
throw QueryExecutionErrors.dataTypeUnsupportedError(dt)
throw new IllegalStateException(s"The data type '${dt.typeName}' is not supported in " +
"generating a writer function for a struct field, array element, map key or map value.")
}

// Always wrap the writer with a null safe version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ trait Block extends TreeNode[Block] with JavaCode {

override def verboseString(maxFields: Int): String = toString
override def simpleStringWithNodeId(): String = {
throw QueryExecutionErrors.simpleStringWithNodeIdUnsupportedError(nodeName)
throw new IllegalStateException(s"$nodeName does not implement simpleStringWithNodeId")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ object QueryCompilationErrors {

def unsupportedIfNotExistsError(tableName: String): Throwable = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we add a QueryCompilationErrorsSuite and test this error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InsertIntoSQLOnlyTests has a test for the error already. BTW, the test from InsertIntoSQLOnlyTests runs as part of:

  • V1WriteFallbackSessionCatalogSuite
  • DataSourceV2SQLSuite
  • DataSourceV2SQLSessionCatalogSuite
  • DataSourceV2DataFrameSuite
  • DataSourceV2DataFrameSessionCatalogSuite

@cloud-fan How about to create the QueryCompilationErrorsSuiteBase trait/abstract class and include it to those test suites?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the base test suites QueryCompilationErrorsSuiteBase + SessionCatalogTestBase and new test suites for compilation errors:

  • QueryCompilationErrorsDSv2Suite
  • QueryCompilationErrorsDSv2SessionCatalogSuite
  • QueryCompilationErrorsV1WriteFallbackSuite

new AnalysisException(
errorClass = "IF_PARTITION_NOT_EXISTS_UNSUPPORTED",
messageParameters = Array(tableName))
errorClass = "UNSUPPORTED_FEATURE",
messageParameters = Array(s"IF NOT EXISTS for the table '$tableName' by INSERT INTO."))
}

def nonPartitionColError(partitionName: String): Throwable = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ import org.apache.spark.util.CircularBuffer
*/
object QueryExecutionErrors {

def columnChangeUnsupportedError(): Throwable = {
new SparkUnsupportedOperationException(errorClass = "UNSUPPORTED_CHANGE_COLUMN",
messageParameters = Array.empty)
}

def logicalHintOperatorNotRemovedDuringAnalysisError(): Throwable = {
new SparkIllegalStateException(errorClass = "INTERNAL_ERROR",
messageParameters = Array(
Expand Down Expand Up @@ -131,22 +126,12 @@ object QueryExecutionErrors {
messageParameters = Array.empty)
}

def simpleStringWithNodeIdUnsupportedError(nodeName: String): Throwable = {
new SparkUnsupportedOperationException(errorClass = "UNSUPPORTED_SIMPLE_STRING_WITH_NODE_ID",
messageParameters = Array(nodeName))
}

def evaluateUnevaluableAggregateUnsupportedError(
methodName: String, unEvaluable: UnevaluableAggregate): Throwable = {
new SparkUnsupportedOperationException(errorClass = "INTERNAL_ERROR",
messageParameters = Array(s"Cannot evaluate expression: $methodName: $unEvaluable"))
}

def dataTypeUnsupportedError(dt: DataType): Throwable = {
new SparkException(errorClass = "UNSUPPORTED_DATATYPE",
messageParameters = Array(dt.typeName), null)
}

def dataTypeUnsupportedError(dataType: String, failure: String): Throwable = {
new SparkIllegalArgumentException(errorClass = "UNSUPPORTED_DATATYPE",
messageParameters = Array(dataType + failure))
Expand Down Expand Up @@ -257,8 +242,9 @@ object QueryExecutionErrors {
}

def literalTypeUnsupportedError(v: Any): RuntimeException = {
new SparkRuntimeException("UNSUPPORTED_LITERAL_TYPE",
Array(v.getClass.toString, v.toString))
new SparkRuntimeException(
errorClass = "UNSUPPORTED_FEATURE",
messageParameters = Array(s"literal for '${v.toString}' of ${v.getClass.toString}."))
}

def noDefaultForDataTypeError(dataType: DataType): RuntimeException = {
Expand Down Expand Up @@ -784,8 +770,10 @@ object QueryExecutionErrors {
}

def transactionUnsupportedByJdbcServerError(): Throwable = {
new SparkSQLFeatureNotSupportedException(errorClass = "UNSUPPORTED_TRANSACTION_BY_JDBC_SERVER",
Array.empty)
new SparkSQLFeatureNotSupportedException(
errorClass = "UNSUPPORTED_FEATURE",
messageParameters = Array("the target JDBC server does not support transaction and " +
"can only support ALTER TABLE with a single action."))
}

def dataTypeUnsupportedYetError(dataType: DataType): Throwable = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,6 @@ class LiteralExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
checkStructLiteral((Period.ZERO, ("abc", Duration.ofDays(1))))
}

test("unsupported types (map and struct) in Literal.apply") {
def checkUnsupportedTypeInLiteral(v: Any): Unit = {
val errMsgMap = intercept[RuntimeException] {
Literal(v)
}
assert(errMsgMap.getMessage.startsWith("Unsupported literal type"))
}
checkUnsupportedTypeInLiteral(Map("key1" -> 1, "key2" -> 2))
checkUnsupportedTypeInLiteral(("mike", 29, 1.0))
}

test("SPARK-24571: char literals") {
checkEvaluation(Literal('X'), "X")
checkEvaluation(Literal.create('0'), "0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,6 @@ class DataFramePivotSuite extends QueryTest with SharedSparkSession {
checkAnswer(df, expected)
}

test("pivoting column list") {
val exception = intercept[RuntimeException] {
trainingSales
.groupBy($"sales.year")
.pivot(struct(lower($"sales.course"), $"training"))
.agg(sum($"sales.earnings"))
.collect()
}
assert(exception.getMessage.contains("Unsupported literal type"))
}

test("SPARK-26403: pivoting by array column") {
val df = Seq(
(2, Seq.empty[String]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,6 @@ trait InsertIntoSQLOnlyTests
}
}

test("InsertInto: IF PARTITION NOT EXISTS not supported") {
val t1 = s"${catalogAndNamespace}tbl"
withTableAndData(t1) { view =>
sql(s"CREATE TABLE $t1 (id bigint, data string) USING $v2Format PARTITIONED BY (id)")

val exc = intercept[AnalysisException] {
sql(s"INSERT OVERWRITE TABLE $t1 PARTITION (id = 1) IF NOT EXISTS SELECT * FROM $view")
}

verifyTable(t1, spark.emptyDataFrame)
assert(exc.getMessage.contains("Cannot write, IF NOT EXISTS is not supported for table"))
assert(exc.getMessage.contains(t1))
assert(exc.getErrorClass == "IF_PARTITION_NOT_EXISTS_UNSUPPORTED")
}
}

test("InsertInto: overwrite - dynamic clause - static mode") {
withSQLConf(PARTITION_OVERWRITE_MODE.key -> PartitionOverwriteMode.STATIC.toString) {
val t1 = s"${catalogAndNamespace}tbl"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.sql.errors

import org.apache.spark.sql.{AnalysisException, QueryTest}
import org.apache.spark.sql.connector.{DatasourceV2SQLBase, FakeV2Provider}
import org.apache.spark.sql.test.SharedSparkSession

class QueryCompilationErrorsDSv2Suite
extends QueryTest
with SharedSparkSession
with DatasourceV2SQLBase {

test("UNSUPPORTED_FEATURE: IF PARTITION NOT EXISTS not supported by INSERT") {
val v2Format = classOf[FakeV2Provider].getName
val tbl = "testcat.ns1.ns2.tbl"

withTable(tbl) {
val view = "tmp_view"
val df = spark.createDataFrame(Seq((1L, "a"), (2L, "b"), (3L, "c"))).toDF("id", "data")
df.createOrReplaceTempView(view)
withTempView(view) {
sql(s"CREATE TABLE $tbl (id bigint, data string) USING $v2Format PARTITIONED BY (id)")

val e = intercept[AnalysisException] {
sql(s"INSERT OVERWRITE TABLE $tbl PARTITION (id = 1) IF NOT EXISTS SELECT * FROM $view")
}

checkAnswer(spark.table(tbl), spark.emptyDataFrame)
assert(e.getMessage === "The feature is not supported: " +
s"IF NOT EXISTS for the table '$tbl' by INSERT INTO.")
assert(e.getErrorClass === "UNSUPPORTED_FEATURE")
assert(e.getSqlState === "0A000")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.spark.sql.errors

import org.apache.spark.{SparkException, SparkRuntimeException}
import org.apache.spark.sql.{DataFrame, QueryTest}
import org.apache.spark.sql.functions.{lit, lower, struct, sum}
import org.apache.spark.sql.test.SharedSparkSession

class QueryExecutionErrorsSuite extends QueryTest with SharedSparkSession {
Expand Down Expand Up @@ -89,7 +90,7 @@ class QueryExecutionErrorsSuite extends QueryTest with SharedSparkSession {
}
}

test("UNSUPPORTED_MODE: unsupported combinations of AES modes and padding") {
test("UNSUPPORTED_FEATURE: unsupported combinations of AES modes and padding") {
val key16 = "abcdefghijklmnop"
val key32 = "abcdefghijklmnop12345678ABCDEFGH"
val (df1, df2) = getAesInputs()
Expand All @@ -112,4 +113,26 @@ class QueryExecutionErrorsSuite extends QueryTest with SharedSparkSession {
checkUnsupportedMode(df2.selectExpr(s"aes_decrypt(value16, '$key16', 'GCM', 'PKCS')"))
checkUnsupportedMode(df2.selectExpr(s"aes_decrypt(value32, '$key32', 'ECB', 'None')"))
}

test("UNSUPPORTED_FEATURE: unsupported types (map and struct) in lit()") {
def checkUnsupportedTypeInLiteral(v: Any): Unit = {
val e1 = intercept[SparkRuntimeException] { lit(v) }
assert(e1.getErrorClass === "UNSUPPORTED_FEATURE")
assert(e1.getSqlState === "0A000")
assert(e1.getMessage.matches("""The feature is not supported: literal for '.+' of .+\."""))
}
checkUnsupportedTypeInLiteral(Map("key1" -> 1, "key2" -> 2))
checkUnsupportedTypeInLiteral(("mike", 29, 1.0))

val e2 = intercept[SparkRuntimeException] {
trainingSales
.groupBy($"sales.year")
.pivot(struct(lower($"sales.course"), $"training"))
.agg(sum($"sales.earnings"))
.collect()
}
assert(e2.getMessage === "The feature is not supported: " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, this message is quite misleading, as the query does not create literals directly. We can improve it later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened the ticket SPARK-38097 to improve the error.

"literal for '[dotnet,Dummies]' of class " +
"org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema.")
}
}