allisonwang-db commented on a change in pull request #30564:
URL: https://github.com/apache/spark/pull/30564#discussion_r537768880



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -1484,7 +1476,7 @@ class Analyzer(override val catalogManager: 
CatalogManager)
           }
         )
       case g: Generate if containsStar(g.generator.children) =>
-        failAnalysis("Invalid usage of '*' in explode/json_tuple/UDTF")
+        throw 
QueryCompilationErrors.invalidStarUsageError(g.generator.prettyName)

Review comment:
       There is one unit test that matches this error msg: `DataFrameSuite.Star 
Expansion - ds.explode should fail with a meaningful message if it takes a 
star`. To avoid changing the error message we can use 
`invalidStarUsageError("explode/json_tuple/UDTF")` for this one and 
`invalidStarUsageError(s"expression '${o.prettyName}'")` for the one below.
   

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/QueryCompilationErrors.scala
##########
@@ -159,6 +164,166 @@ object QueryCompilationErrors {
       s"Couldn't find the reference column for $after at $parentName")
   }
 
-}
+  def windowSpecificationNotDefinedError(windowName: String): Throwable = {
+    new AnalysisException(s"Window specification $windowName is not defined in 
the WINDOW clause.")
+  }
+
+  def selectExprNotInGroupByError(expr: Expression, groupByAliases: 
Seq[Alias]): Throwable = {
+    new AnalysisException(s"$expr doesn't show up in the GROUP BY list 
$groupByAliases")
+  }
+
+  def groupingMustWithGroupingSetsOrCubeOrRollupError(): Throwable = {
+    new AnalysisException("grouping()/grouping_id() can only be used with 
GroupingSets/Cube/Rollup")
+  }
+
+  def pandasUDFAggregateNotSupportedInPivotError(): Throwable = {
+    new AnalysisException("Pandas UDF aggregate expressions are currently not 
supported in pivot.")
+  }
+
+  def aggregateExpressionRequiredForPivotError(sql: String): Throwable = {
+    new AnalysisException(s"Aggregate expression required for pivot, but 
'$sql' " +
+      "did not appear in any aggregate function.")
+  }
+
+  def expectTableNotTempViewError(quoted: String, cmd: String, t: 
TreeNode[_]): Throwable = {
+    new AnalysisException(s"$quoted is a temp view. '$cmd' expects a table",
+      t.origin.line, t.origin.startPosition)
+  }
+
+  def expectTableOrPermanentViewNotTempViewError(
+      quoted: String, cmd: String, t: TreeNode[_]): Throwable = {
+    new AnalysisException(s"$quoted is a temp view. '$cmd' expects a table or 
permanent view.",
+      t.origin.line, t.origin.startPosition)
+  }
+
+  def viewDepthExceedsMaxResolutionDepthError(
+      identifier: TableIdentifier, maxNestedViewDepth: Int, t: TreeNode[_]): 
Throwable = {
+    new AnalysisException(s"The depth of view $identifier exceeds the maximum 
" +
+      s"view resolution depth ($maxNestedViewDepth). Analysis is aborted to " +
+      s"avoid errors. Increase the value of 
${SQLConf.MAX_NESTED_VIEW_DEPTH.key} to work " +
+      "around this.", t.origin.line, t.origin.startPosition)
+  }
+
+  def insertIntoViewNotAllowedError(identifier: TableIdentifier, t: 
TreeNode[_]): Throwable = {
+    new AnalysisException(s"Inserting into a view is not allowed. View: 
$identifier.",
+      t.origin.line, t.origin.startPosition)
+  }
+
+  def writeIntoViewNotAllowedError(identifier: TableIdentifier, t: 
TreeNode[_]): Throwable = {
+    new AnalysisException(s"Writing into a view is not allowed. View: 
$identifier.",
+      t.origin.line, t.origin.startPosition)
+  }
+
+  def writeIntoV1TableNotAllowedError(identifier: TableIdentifier, t: 
TreeNode[_]): Throwable = {
+    new AnalysisException(s"Cannot write into v1 table: $identifier.",
+      t.origin.line, t.origin.startPosition)
+  }
+
+  def expectTableNotViewError(v: ResolvedView, cmd: String, t: TreeNode[_]): 
Throwable = {
+    val viewStr = if (v.isTemp) "temp view" else "view"
+    new AnalysisException(s"${v.identifier.quoted} is a $viewStr. '$cmd' 
expects a table.",
+      t.origin.line, t.origin.startPosition)
+  }
+
+  def starNotAllowedWhenGroupByOrdinalPositionUsedError(): Throwable = {
+    new AnalysisException(
+      "Star (*) is not allowed in select list when GROUP BY ordinal position 
is used")
+  }
+
+  def invalidStarUsageError(prettyName: String): Throwable = {
+    new AnalysisException(s"Invalid usage of '*' in expression '$prettyName'")
+  }
+
+  def orderByPositionRangeError(index: Int, size: Int, t: TreeNode[_]): 
Throwable = {
+    new AnalysisException(s"ORDER BY position $index is not in select list " +
+      s"(valid range is [1, $size])", t.origin.line, t.origin.startPosition)
+  }
+
+  def groupByPositionRangeError(index: Int, size: Int, t: TreeNode[_]): 
Throwable = {
+    new AnalysisException(s"GROUP BY position $index is not in select list " +
+      s"(valid range is [1, $size])", t.origin.line, t.origin.startPosition)
+  }
 
+  def generatorNotExpectedError(name: FunctionIdentifier, classCanonicalName: 
String): Throwable = {
+    new AnalysisException(s"$name is expected to be a generator. However, " +
+      s"its class is $classCanonicalName, which is not a generator.")
+  }
 
+  def distinctOrFilterOnlyWithAggregateFunctionError(prettyName: String): 
Throwable = {
+    new AnalysisException("DISTINCT or FILTER specified, " +
+      s"but $prettyName is not an aggregate function")
+  }
+
+  def nonDeterministicFilterInAggregateError(): Throwable = {
+    new AnalysisException("FILTER expression is non-deterministic, " +
+      "it cannot be used in aggregate functions")
+  }
+
+  def aliasNumberNotMatchColumnNumberError(
+      columnSize: Int, outputSize: Int, t: TreeNode[_]): Throwable = {
+    new AnalysisException("Number of column aliases does not match number of 
columns. " +
+      s"Number of column aliases: $columnSize; " +
+      s"number of columns: $outputSize.", t.origin.line, 
t.origin.startPosition)
+  }
+
+  def aliasesNumberNotMatchUDTFOutputError(
+      aliasesSize: Int, aliasesNames: String): Throwable = {
+    new AnalysisException("The number of aliases supplied in the AS clause 
does not " +
+      s"match the number of columns output by the UDTF expected $aliasesSize " 
+
+      s"aliases but got $aliasesNames ")
+  }
+
+  def windowAggregateFunctionWithFilterNotSupportedError(): Throwable = {
+    new AnalysisException("window aggregate function with filter predicate is 
not supported yet.")
+  }
+
+  def windowFunctionInsideAggregateFunctionNotAllowedError(): Throwable = {
+    new AnalysisException("It is not allowed to use a window function inside 
an aggregate " +
+      "function. Please use the inner window function in a sub-query.")
+  }
+
+  def expressionWithoutWindowExpressionError(expr: NamedExpression): Throwable 
= {
+    new AnalysisException(s"$expr does not have any WindowExpression.")
+  }
+
+  def expressionWithMultiWindowExpressionsError(
+      expr: NamedExpression, distinctWindowSpec: Seq[WindowSpecDefinition]): 
Throwable = {
+    new AnalysisException(s"$expr has multiple Window Specifications 
($distinctWindowSpec)." +
+      s"Please file a bug report with this error message, stack trace, and the 
query.")
+  }
+
+  def windowFunctionNotAllowedError(): Throwable = {
+    new AnalysisException("It is not allowed to use window functions inside 
WHERE/HAVING clause")

Review comment:
       This change breaks the test `DataFrameWindowFunctionsSuite.SPARK-24575: 
Window functions inside WHERE and HAVING clauses` that matches the keyword 
"WHERE" only. To avoid change the error message we can add a `clause` 
parameter. 




----------------------------------------------------------------
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.

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