Skip to content

Commit

Permalink
[SPARK-39243][SQL][DOCS] Rules of quoting elements in error messages
Browse files Browse the repository at this point in the history
### 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:
- #36210
- #36233
- #36259
- #36324
- #36335
- #36359
- #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 #36621 from MaxGekk/update-error-class-guide.

Authored-by: Max Gekk <max.gekk@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
(cherry picked from commit 2a4d8a4)
Signed-off-by: Max Gekk <max.gekk@gmail.com>
  • Loading branch information
MaxGekk committed May 22, 2022
1 parent 3f77be2 commit fa400c6
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ import org.apache.spark.sql.catalyst.expressions.Literal
import org.apache.spark.sql.catalyst.util.quoteIdentifier
import org.apache.spark.sql.types.{DataType, DoubleType, FloatType}

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

0 comments on commit fa400c6

Please sign in to comment.