MaxGekk commented on code in PR #48387:
URL: https://github.com/apache/spark/pull/48387#discussion_r1793071850


##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -4188,6 +4188,12 @@
     ],
     "sqlState" : "42K06"
   },
+  "PARTITION_TRANSFORM_EXPRESSION_NOT_IN_PARTITIONED_BY" : {
+    "message" : [
+      "The expression <expression> must be inside 'partitionedBy'"

Review Comment:
   ```suggestion
         "The expression <expression> must be inside 'partitionedBy'."
   ```



##########
sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala:
##########
@@ -1006,6 +1006,17 @@ class QueryExecutionErrorsSuite
       sqlState = "XX000")
   }
 
+  test("PartitionTransformExpression throws error on eval") {
+

Review Comment:
   Unnecessary empty line:
   ```suggestion
   ```



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/PartitionTransforms.scala:
##########
@@ -37,8 +41,19 @@ import org.apache.spark.sql.types.{DataType, IntegerType}
 abstract class PartitionTransformExpression extends Expression with Unevaluable
   with UnaryLike[Expression] {
   override def nullable: Boolean = true
-}
 
+  override def eval(input: InternalRow): Any =
+    throw new AnalysisException(
+      errorClass = "PARTITION_TRANSFORM_EXPRESSION_NOT_IN_PARTITIONED_BY",
+      messageParameters = Map("expression" -> toSQLStmt(toString))

Review Comment:
   If it is an expression, we should use `toSQLExpr`



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/PartitionTransforms.scala:
##########
@@ -37,8 +41,19 @@ import org.apache.spark.sql.types.{DataType, IntegerType}
 abstract class PartitionTransformExpression extends Expression with Unevaluable
   with UnaryLike[Expression] {
   override def nullable: Boolean = true
-}
 
+  override def eval(input: InternalRow): Any =
+    throw new AnalysisException(

Review Comment:
   Don't think it should be `AnalysisException`. Could you replace it by 
`SparkException`



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/PartitionTransforms.scala:
##########
@@ -37,8 +41,19 @@ import org.apache.spark.sql.types.{DataType, IntegerType}
 abstract class PartitionTransformExpression extends Expression with Unevaluable
   with UnaryLike[Expression] {
   override def nullable: Boolean = true
-}
 
+  override def eval(input: InternalRow): Any =
+    throw new AnalysisException(
+      errorClass = "PARTITION_TRANSFORM_EXPRESSION_NOT_IN_PARTITIONED_BY",
+      messageParameters = Map("expression" -> toSQLStmt(toString))
+    )
+
+  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode =
+    throw new AnalysisException(
+      errorClass = "PARTITION_TRANSFORM_EXPRESSION_NOT_IN_PARTITIONED_BY",
+      messageParameters = Map("expression" -> toString)

Review Comment:
   Wrapping should be the same as in `eval()`



##########
sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala:
##########
@@ -1006,6 +1006,17 @@ class QueryExecutionErrorsSuite
       sqlState = "XX000")
   }
 
+  test("PartitionTransformExpression throws error on eval") {
+
+    val e = intercept[AnalysisException] {
+      Years(Literal("foo")).eval()

Review Comment:
   Is it possible to reproduce the error using public APIs?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to