Skip to content

Commit 2a4d8a4

Browse files
committed
[SPARK-39243][SQL][DOCS] Rules of quoting elements in error messages
### What changes were proposed in this pull request? In the PR, I propose to describe the rules of quoting elements in error messages introduced by the PRs: - apache#36210 - apache#36233 - apache#36259 - apache#36324 - apache#36335 - apache#36359 - apache#36579 ### Why are the changes needed? To improve code maintenance, and the process of code review. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? By existing GAs. Closes apache#36621 from MaxGekk/update-error-class-guide. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
1 parent d165de8 commit 2a4d8a4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryErrorsBase.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ import org.apache.spark.sql.catalyst.expressions.Literal
2323
import org.apache.spark.sql.catalyst.util.quoteIdentifier
2424
import org.apache.spark.sql.types.{DataType, DoubleType, FloatType}
2525

26+
/**
27+
* The trait exposes util methods for preparing error messages such as quoting of error elements.
28+
* All classes that extent `QueryErrorsBase` shall follow the rules:
29+
* 1. Any values shall be outputted in the SQL standard style by using `toSQLValue()`.
30+
* For example: 'a string value', 1, NULL.
31+
* 2. SQL types shall be double quoted and outputted in the upper case using `toSQLType()`.
32+
* For example: "INT", "DECIMAL(10,0)".
33+
* 3. Elements of identifiers shall be wrapped by backticks by using `toSQLId()`.
34+
* For example: `namespaceA`.`funcB`, `tableC`.
35+
* 4. SQL statements shall be in the upper case prepared by using `toSQLStmt`.
36+
* For example: DESC PARTITION, DROP TEMPORARY FUNCTION.
37+
* 5. SQL configs and datasource options shall be wrapped by double quotes by using
38+
* `toSQLConf()`/`toDSOption()`.
39+
* For example: "spark.sql.ansi.enabled".
40+
* 6. Any values of datasource options or SQL configs shall be double quoted.
41+
* For example: "true", "CORRECTED".
42+
*/
2643
trait QueryErrorsBase {
2744
// Converts an error class parameter to its SQL representation
2845
def toSQLValue(v: Any, t: DataType): String = Literal.create(v, t) match {

0 commit comments

Comments
 (0)