panbingkun commented on code in PR #44665:
URL: https://github.com/apache/spark/pull/44665#discussion_r1519273344


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/csvExpressions.scala:
##########
@@ -260,16 +263,33 @@ case class StructsToCsv(
       child = child,
       timeZoneId = None)
 
+  override def checkInputDataTypes(): TypeCheckResult = {
+    child.dataType match {
+      case schema: StructType if schema.map(_.dataType).forall(
+        dt => isSupportedDataType(dt)) => TypeCheckSuccess
+      case _ => DataTypeMismatch(
+        errorSubClass = "UNSUPPORTED_INPUT_TYPE",

Review Comment:
   Using `UNSUPPORTED_INPUT_TYPE` instead of `UNEXPECTED_INPUT_TYPE` here will 
make the prompt information more `clear` to the user, for example:
   
   ```
       val rows = new java.util.ArrayList[Row]()
       rows.add(Row(1L, Row(2L, "Alice",
         Map("math" -> 100L, "english" -> 200L, "science" -> null))))
   
       val valueSchema = StructType(Seq(
         StructField("age", LongType),
         StructField("name", StringType),
         StructField("scores", MapType(StringType, LongType))))
       val schema = StructType(Seq(
         StructField("key", LongType),
         StructField("value", valueSchema)))
   
       val df = spark.createDataFrame(rows, schema)
   
       df.select(to_csv($"value")).collect()
   ```
   
   Before(Last review):
   Users may feel confused about prompt: `requires the "STRUCT" type, however 
"value" has the type "STRUCT...`
   ```
   [DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE] Cannot resolve "to_csv(value)" due 
to data type mismatch: The 1 parameter requires the "STRUCT" type, however 
"value" has the type "STRUCT<age: BIGINT, name: STRING, scores: MAP<STRING, 
BIGINT>>". SQLSTATE: 42K09;
   ```
   
   After(Right now):
   ```
   [DATATYPE_MISMATCH.UNSUPPORTED_INPUT_TYPE] Cannot resolve "to_csv(value)" 
due to data type mismatch: The input of `to_csv` can't be "STRUCT<age: BIGINT, 
name: STRING, scores: MAP<STRING, BIGINT>>" type data. SQLSTATE: 42K09;
   ```



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to