Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dengziming committed Feb 23, 2024
1 parent b90514c commit 68fc227
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 16 deletions.
22 changes: 12 additions & 10 deletions common/utils/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@
],
"sqlState" : "56000"
},
"CLASS_NOT_OVERRIDE_EXPECTED_METHOD" : {
"message" : [
"<className> must override either <m1> or <m2>."
],
"sqlState" : "38000"
},
"CLASS_UNSUPPORTED_BY_MAP_OBJECTS" : {
"message" : [
"`MapObjects` does not support the class <cls> as resulting collection."
Expand Down Expand Up @@ -2884,6 +2890,12 @@
],
"sqlState" : "42809"
},
"NOT_A_UNRESOLVED_ENCODER" : {
"message" : [
"Unresolved encoder expected, but <attr> was found."
],
"sqlState" : "42601"
},
"NOT_NULL_CONSTRAINT_VIOLATION" : {
"message" : [
"Assigning a NULL is not allowed here."
Expand Down Expand Up @@ -5715,16 +5727,6 @@
"Couldn't find a primary constructor on <cls>."
]
},
"_LEGACY_ERROR_TEMP_2023" : {
"message" : [
"Unresolved encoder expected, but <attr> was found."
]
},
"_LEGACY_ERROR_TEMP_2025" : {
"message" : [
"<className> must override either <m1> or <m2>."
]
},
"_LEGACY_ERROR_TEMP_2026" : {
"message" : [
"Failed to convert value <value> (class of <cls>) with the type of <dataType> to JSON."
Expand Down
18 changes: 18 additions & 0 deletions docs/sql-error-conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ Checkpoint block `<rddBlockId>` not found!
Either the executor that originally checkpointed this partition is no longer alive, or the original RDD is unpersisted.
If this problem persists, you may consider using `rdd.checkpoint()` instead, which is slower than local checkpointing but more fault-tolerant.

### CLASS_NOT_OVERRIDE_EXPECTED_METHOD

[SQLSTATE: 38000](sql-error-conditions-sqlstates.html#class-38-external-routine-exception)

`<className>` must override either `<m1>` or `<m2>`.

### CLASS_UNSUPPORTED_BY_MAP_OBJECTS

[SQLSTATE: 0A000](sql-error-conditions-sqlstates.html#class-0A-feature-not-supported)
Expand Down Expand Up @@ -1663,6 +1669,12 @@ For more details see [NOT_A_CONSTANT_STRING](sql-error-conditions-not-a-constant

Operation `<operation>` is not allowed for `<tableIdentWithDB>` because it is not a partitioned table.

### NOT_A_UNRESOLVED_ENCODER

[SQLSTATE: 42601](sql-error-conditions-sqlstates.html#class-42-syntax-error-or-access-rule-violation)

Unresolved encoder expected, but `<attr>` was found.

### [NOT_NULL_CONSTRAINT_VIOLATION](sql-error-conditions-not-null-constraint-violation-error-class.html)

[SQLSTATE: 42000](sql-error-conditions-sqlstates.html#class-42-syntax-error-or-access-rule-violation)
Expand Down Expand Up @@ -2470,6 +2482,12 @@ The deserializer is not supported:

For more details see [UNSUPPORTED_DESERIALIZER](sql-error-conditions-unsupported-deserializer-error-class.html)

### UNSUPPORTED_ENCODER

[SQLSTATE: 0A000](sql-error-conditions-sqlstates.html#class-0A-feature-not-supported)

Only expression encoders are supported for now.

### UNSUPPORTED_EXPRESSION_GENERATED_COLUMN

[SQLSTATE: 42621](sql-error-conditions-sqlstates.html#class-42-syntax-error-or-access-rule-violation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ case class ExpressionEncoder[T](
* has not been done already in places where we plan to do later composition of encoders.
*/
def assertUnresolved(): Unit = {
(deserializer +: serializer).foreach(_.foreach {
(deserializer +: serializer).foreach(_.foreach {
case a: AttributeReference if a.name != "loopVar" =>
throw QueryExecutionErrors.notExpectedUnresolvedEncoderError(a)
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ abstract class UnaryExpression extends Expression with UnaryLike[Expression] {
* of evaluation process, we should override [[eval]].
*/
protected def nullSafeEval(input: Any): Any =
throw QueryExecutionErrors.notOverrideExpectedMethodsError("UnaryExpressions",
throw QueryExecutionErrors.notOverrideExpectedMethodsError("UnaryExpression",
"eval", "nullSafeEval")

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE

def notExpectedUnresolvedEncoderError(attr: AttributeReference): SparkRuntimeException = {
new SparkRuntimeException(
errorClass = "_LEGACY_ERROR_TEMP_2023",
errorClass = "NOT_A_UNRESOLVED_ENCODER",
messageParameters = Map("attr" -> attr.toString()))
}

Expand All @@ -472,7 +472,7 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
def notOverrideExpectedMethodsError(
className: String, m1: String, m2: String): SparkRuntimeException = {
new SparkRuntimeException(
errorClass = "_LEGACY_ERROR_TEMP_2025",
errorClass = "CLASS_NOT_OVERRIDE_EXPECTED_METHOD",
messageParameters = Map("className" -> className, "m1" -> m1, "m2" -> m2))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import org.apache.spark._
import org.apache.spark.sql.{AnalysisException, DataFrame, Dataset, Encoder, KryoData, QueryTest, Row, SaveMode}
import org.apache.spark.sql.catalyst.FunctionIdentifier
import org.apache.spark.sql.catalyst.analysis.{NamedParameter, UnresolvedGenerator}
import org.apache.spark.sql.catalyst.expressions.{Concat, CreateArray, EmptyRow, Flatten, Grouping, Literal, RowNumber}
import org.apache.spark.sql.catalyst.encoders.{ExpressionEncoder, RowEncoder}
import org.apache.spark.sql.catalyst.expressions.{AttributeReference, Concat, CreateArray, EmptyRow, Expression, Flatten, Grouping, Literal, RowNumber, UnaryExpression}
import org.apache.spark.sql.catalyst.expressions.CodegenObjectFactoryMode._
import org.apache.spark.sql.catalyst.expressions.codegen.CodegenContext
import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCode}
import org.apache.spark.sql.catalyst.expressions.objects.InitializeJavaBean
import org.apache.spark.sql.catalyst.rules.RuleIdCollection
import org.apache.spark.sql.execution.datasources.jdbc.{DriverRegistry, JDBCOptions}
Expand All @@ -53,6 +54,7 @@ import org.apache.spark.sql.jdbc.{JdbcDialect, JdbcDialects}
import org.apache.spark.sql.streaming.StreamingQueryException
import org.apache.spark.sql.test.SharedSparkSession
import org.apache.spark.sql.types.{ArrayType, BooleanType, DataType, DecimalType, LongType, MetadataBuilder, StructField, StructType}
import org.apache.spark.sql.types.{ArrayType, BooleanType, DataType, DecimalType, IntegerType, LongType, MetadataBuilder, StructField, StructType}
import org.apache.spark.sql.vectorized.ColumnarArray
import org.apache.spark.unsafe.array.ByteArrayMethods.MAX_ROUNDED_ARRAY_LENGTH
import org.apache.spark.util.ThreadUtils
Expand Down Expand Up @@ -1170,6 +1172,48 @@ class QueryExecutionErrorsSuite
)
)
}

test("ExpressionEncoder.objDeserializer should be a unsolved encoder ") {
val rowEnc = RowEncoder.encoderFor(new StructType(Array(StructField("v", IntegerType))))
val enc: ExpressionEncoder[Row] = ExpressionEncoder(rowEnc)
val deserializer = AttributeReference.apply("v", IntegerType)()
implicit val im: ExpressionEncoder[Row] = new ExpressionEncoder[Row](
enc.objSerializer, deserializer, enc.clsTag)

checkError(
exception = intercept[SparkRuntimeException] {
spark.createDataset(Seq(Row(1))).collect()
},
errorClass = "NOT_A_UNRESOLVED_ENCODER",
parameters = Map(
"attr" -> deserializer.toString
)
)
}


test("UnaryExpression should override eval or nullSafeEval") {
case class NyUnaryExpression(child: Expression)
extends UnaryExpression {
override def dataType: DataType = IntegerType

override protected def withNewChildInternal(newChild: Expression): UnaryExpression = this

override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = null
}

checkError(
exception = intercept[SparkRuntimeException] {
NyUnaryExpression(Literal.create(1, IntegerType)).eval(EmptyRow)
},
errorClass = "CLASS_NOT_OVERRIDE_EXPECTED_METHOD",
parameters = Map(
"className" -> "UnaryExpression",
"m1" -> "eval",
"m2" -> "nullSafeEval"
)
)
}
}

class FakeFileSystemSetPermission extends LocalFileSystem {
Expand Down

0 comments on commit 68fc227

Please sign in to comment.