Github user maryannxue commented on a diff in the pull request: https://github.com/apache/spark/pull/21720#discussion_r201137638 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -515,13 +515,33 @@ class Analyzer( s"Aggregate expression required for pivot, found '$e'") } } + // Check all pivot values are literal and match pivot column data type. + val evalPivotValues = pivotValues.map { value => + if (!Cast.canCast(value.dataType, pivotColumn.dataType)) { + throw new AnalysisException(s"Invalid pivot value '$value': " + + s"value data type ${value.dataType.simpleString} does not match " + + s"pivot column data type ${pivotColumn.dataType.simpleString}") + } + try { + Cast(value, pivotColumn.dataType).eval(EmptyRow) + } catch { + case _: UnsupportedOperationException => + throw new AnalysisException( + s"Literal expressions required for pivot values, found '$value'") --- End diff -- Yes, you are right. Please refer to @gatorsmile's comment.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org