This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new cebe2be  [SPARK-34718][SQL] Assign pretty names to 
YearMonthIntervalType and DayTimeIntervalType
cebe2be is described below

commit cebe2be22130667a335e27b7a2d7662e735c4ffb
Author: Max Gekk <max.g...@gmail.com>
AuthorDate: Thu Mar 11 12:55:12 2021 -0800

    [SPARK-34718][SQL] Assign pretty names to YearMonthIntervalType and 
DayTimeIntervalType
    
    ### What changes were proposed in this pull request?
    In the PR, I propose to override the `typeName()` method in 
`YearMonthIntervalType` and `DayTimeIntervalType`, and assign them names 
according to the ANSI SQL standard:
    <img width="836" alt="Screenshot 2021-03-11 at 17 29 04" 
src="https://user-images.githubusercontent.com/1580697/110802854-a54aa980-828f-11eb-956d-dd4fbf14aa72.png";>
    but keep the type name as singular according existing naming convention for 
other types.
    
    ### Why are the changes needed?
    To improve Spark SQL user experience, and have readable types in error 
messages.
    
    ### Does this PR introduce _any_ user-facing change?
    Should not since the types has not been released yet.
    
    ### How was this patch tested?
    By running the modified tests:
    ```
    $ build/sbt "test:testOnly *ExpressionTypeCheckingSuite"
    $ build/sbt "sql/testOnly *SQLQueryTestSuite -- -z windowFrameCoercion.sql"
    $ build/sbt "sql/testOnly *SQLQueryTestSuite -- -z literals.sql"
    ```
    
    Closes #31810 from MaxGekk/interval-types-name.
    
    Authored-by: Max Gekk <max.g...@gmail.com>
    Signed-off-by: Dongjoon Hyun <dh...@apple.com>
---
 .../apache/spark/sql/types/DayTimeIntervalType.scala   |  2 ++
 .../apache/spark/sql/types/YearMonthIntervalType.scala |  2 ++
 .../analysis/ExpressionTypeCheckingSuite.scala         |  4 ++--
 .../resources/sql-tests/results/ansi/literals.sql.out  | 18 +++++++++---------
 .../test/resources/sql-tests/results/literals.sql.out  | 18 +++++++++---------
 .../typeCoercion/native/windowFrameCoercion.sql.out    |  6 +++---
 6 files changed, 27 insertions(+), 23 deletions(-)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DayTimeIntervalType.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DayTimeIntervalType.scala
index 9060b5e..d7c1164 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DayTimeIntervalType.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DayTimeIntervalType.scala
@@ -56,6 +56,8 @@ class DayTimeIntervalType private() extends AtomicType {
   override def defaultSize: Int = 8
 
   private[spark] override def asNullable: DayTimeIntervalType = this
+
+  override def typeName: String = "day-time interval"
 }
 
 /**
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/YearMonthIntervalType.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/YearMonthIntervalType.scala
index 254ecd2..1a2f528 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/types/YearMonthIntervalType.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/types/YearMonthIntervalType.scala
@@ -54,6 +54,8 @@ class YearMonthIntervalType private() extends AtomicType {
   override def defaultSize: Int = 4
 
   private[spark] override def asNullable: YearMonthIntervalType = this
+
+  override def typeName: String = "year-month interval"
 }
 
 /**
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala
index ee560ea..44f3333 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala
@@ -78,9 +78,9 @@ class ExpressionTypeCheckingSuite extends SparkFunSuite {
     assertErrorForDifferingTypes(BitwiseXor(Symbol("intField"), 
Symbol("booleanField")))
 
     assertError(Add(Symbol("booleanField"), Symbol("booleanField")),
-      "requires (numeric or interval or daytimeinterval or yearmonthinterval) 
type")
+      "requires (numeric or interval or day-time interval or year-month 
interval) type")
     assertError(Subtract(Symbol("booleanField"), Symbol("booleanField")),
-      "requires (numeric or interval or daytimeinterval or yearmonthinterval) 
type")
+      "requires (numeric or interval or day-time interval or year-month 
interval) type")
     assertError(Multiply(Symbol("booleanField"), Symbol("booleanField")), 
"requires numeric type")
     assertError(Divide(Symbol("booleanField"), Symbol("booleanField")),
       "requires (double or decimal) type")
diff --git 
a/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out 
b/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out
index 1c290a0..df370e4 100644
--- a/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out
@@ -436,7 +436,7 @@ select +date '1999-01-01'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ DATE '1999-01-01')' due to data type mismatch: argument 1 
requires (numeric or interval or daytimeinterval or yearmonthinterval) type, 
however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7
+cannot resolve '(+ DATE '1999-01-01')' due to data type mismatch: argument 1 
requires (numeric or interval or day-time interval or year-month interval) 
type, however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7
 
 
 -- !query
@@ -445,7 +445,7 @@ select +timestamp '1999-01-01'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ TIMESTAMP '1999-01-01 00:00:00')' due to data type 
mismatch: argument 1 requires (numeric or interval or daytimeinterval or 
yearmonthinterval) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of 
timestamp type.; line 1 pos 7
+cannot resolve '(+ TIMESTAMP '1999-01-01 00:00:00')' due to data type 
mismatch: argument 1 requires (numeric or interval or day-time interval or 
year-month interval) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of 
timestamp type.; line 1 pos 7
 
 
 -- !query
@@ -462,7 +462,7 @@ select +map(1, 2)
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ map(1, 2))' due to data type mismatch: argument 1 requires 
(numeric or interval or daytimeinterval or yearmonthinterval) type, however, 
'map(1, 2)' is of map<int,int> type.; line 1 pos 7
+cannot resolve '(+ map(1, 2))' due to data type mismatch: argument 1 requires 
(numeric or interval or day-time interval or year-month interval) type, 
however, 'map(1, 2)' is of map<int,int> type.; line 1 pos 7
 
 
 -- !query
@@ -471,7 +471,7 @@ select +array(1,2)
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ array(1, 2))' due to data type mismatch: argument 1 
requires (numeric or interval or daytimeinterval or yearmonthinterval) type, 
however, 'array(1, 2)' is of array<int> type.; line 1 pos 7
+cannot resolve '(+ array(1, 2))' due to data type mismatch: argument 1 
requires (numeric or interval or day-time interval or year-month interval) 
type, however, 'array(1, 2)' is of array<int> type.; line 1 pos 7
 
 
 -- !query
@@ -480,7 +480,7 @@ select +named_struct('a', 1, 'b', 'spark')
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ named_struct('a', 1, 'b', 'spark'))' due to data type 
mismatch: argument 1 requires (numeric or interval or daytimeinterval or 
yearmonthinterval) type, however, 'named_struct('a', 1, 'b', 'spark')' is of 
struct<a:int,b:string> type.; line 1 pos 7
+cannot resolve '(+ named_struct('a', 1, 'b', 'spark'))' due to data type 
mismatch: argument 1 requires (numeric or interval or day-time interval or 
year-month interval) type, however, 'named_struct('a', 1, 'b', 'spark')' is of 
struct<a:int,b:string> type.; line 1 pos 7
 
 
 -- !query
@@ -489,7 +489,7 @@ select +X'1'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ X'01')' due to data type mismatch: argument 1 requires 
(numeric or interval or daytimeinterval or yearmonthinterval) type, however, 
'X'01'' is of binary type.; line 1 pos 7
+cannot resolve '(+ X'01')' due to data type mismatch: argument 1 requires 
(numeric or interval or day-time interval or year-month interval) type, 
however, 'X'01'' is of binary type.; line 1 pos 7
 
 
 -- !query
@@ -498,7 +498,7 @@ select -date '1999-01-01'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(- DATE '1999-01-01')' due to data type mismatch: argument 1 
requires (numeric or interval or daytimeinterval or yearmonthinterval) type, 
however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7
+cannot resolve '(- DATE '1999-01-01')' due to data type mismatch: argument 1 
requires (numeric or interval or day-time interval or year-month interval) 
type, however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7
 
 
 -- !query
@@ -507,7 +507,7 @@ select -timestamp '1999-01-01'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(- TIMESTAMP '1999-01-01 00:00:00')' due to data type 
mismatch: argument 1 requires (numeric or interval or daytimeinterval or 
yearmonthinterval) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of 
timestamp type.; line 1 pos 7
+cannot resolve '(- TIMESTAMP '1999-01-01 00:00:00')' due to data type 
mismatch: argument 1 requires (numeric or interval or day-time interval or 
year-month interval) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of 
timestamp type.; line 1 pos 7
 
 
 -- !query
@@ -516,4 +516,4 @@ select -x'2379ACFe'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(- X'2379ACFE')' due to data type mismatch: argument 1 
requires (numeric or interval or daytimeinterval or yearmonthinterval) type, 
however, 'X'2379ACFE'' is of binary type.; line 1 pos 7
+cannot resolve '(- X'2379ACFE')' due to data type mismatch: argument 1 
requires (numeric or interval or day-time interval or year-month interval) 
type, however, 'X'2379ACFE'' is of binary type.; line 1 pos 7
diff --git a/sql/core/src/test/resources/sql-tests/results/literals.sql.out 
b/sql/core/src/test/resources/sql-tests/results/literals.sql.out
index 1c290a0..df370e4 100644
--- a/sql/core/src/test/resources/sql-tests/results/literals.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/literals.sql.out
@@ -436,7 +436,7 @@ select +date '1999-01-01'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ DATE '1999-01-01')' due to data type mismatch: argument 1 
requires (numeric or interval or daytimeinterval or yearmonthinterval) type, 
however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7
+cannot resolve '(+ DATE '1999-01-01')' due to data type mismatch: argument 1 
requires (numeric or interval or day-time interval or year-month interval) 
type, however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7
 
 
 -- !query
@@ -445,7 +445,7 @@ select +timestamp '1999-01-01'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ TIMESTAMP '1999-01-01 00:00:00')' due to data type 
mismatch: argument 1 requires (numeric or interval or daytimeinterval or 
yearmonthinterval) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of 
timestamp type.; line 1 pos 7
+cannot resolve '(+ TIMESTAMP '1999-01-01 00:00:00')' due to data type 
mismatch: argument 1 requires (numeric or interval or day-time interval or 
year-month interval) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of 
timestamp type.; line 1 pos 7
 
 
 -- !query
@@ -462,7 +462,7 @@ select +map(1, 2)
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ map(1, 2))' due to data type mismatch: argument 1 requires 
(numeric or interval or daytimeinterval or yearmonthinterval) type, however, 
'map(1, 2)' is of map<int,int> type.; line 1 pos 7
+cannot resolve '(+ map(1, 2))' due to data type mismatch: argument 1 requires 
(numeric or interval or day-time interval or year-month interval) type, 
however, 'map(1, 2)' is of map<int,int> type.; line 1 pos 7
 
 
 -- !query
@@ -471,7 +471,7 @@ select +array(1,2)
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ array(1, 2))' due to data type mismatch: argument 1 
requires (numeric or interval or daytimeinterval or yearmonthinterval) type, 
however, 'array(1, 2)' is of array<int> type.; line 1 pos 7
+cannot resolve '(+ array(1, 2))' due to data type mismatch: argument 1 
requires (numeric or interval or day-time interval or year-month interval) 
type, however, 'array(1, 2)' is of array<int> type.; line 1 pos 7
 
 
 -- !query
@@ -480,7 +480,7 @@ select +named_struct('a', 1, 'b', 'spark')
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ named_struct('a', 1, 'b', 'spark'))' due to data type 
mismatch: argument 1 requires (numeric or interval or daytimeinterval or 
yearmonthinterval) type, however, 'named_struct('a', 1, 'b', 'spark')' is of 
struct<a:int,b:string> type.; line 1 pos 7
+cannot resolve '(+ named_struct('a', 1, 'b', 'spark'))' due to data type 
mismatch: argument 1 requires (numeric or interval or day-time interval or 
year-month interval) type, however, 'named_struct('a', 1, 'b', 'spark')' is of 
struct<a:int,b:string> type.; line 1 pos 7
 
 
 -- !query
@@ -489,7 +489,7 @@ select +X'1'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(+ X'01')' due to data type mismatch: argument 1 requires 
(numeric or interval or daytimeinterval or yearmonthinterval) type, however, 
'X'01'' is of binary type.; line 1 pos 7
+cannot resolve '(+ X'01')' due to data type mismatch: argument 1 requires 
(numeric or interval or day-time interval or year-month interval) type, 
however, 'X'01'' is of binary type.; line 1 pos 7
 
 
 -- !query
@@ -498,7 +498,7 @@ select -date '1999-01-01'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(- DATE '1999-01-01')' due to data type mismatch: argument 1 
requires (numeric or interval or daytimeinterval or yearmonthinterval) type, 
however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7
+cannot resolve '(- DATE '1999-01-01')' due to data type mismatch: argument 1 
requires (numeric or interval or day-time interval or year-month interval) 
type, however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7
 
 
 -- !query
@@ -507,7 +507,7 @@ select -timestamp '1999-01-01'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(- TIMESTAMP '1999-01-01 00:00:00')' due to data type 
mismatch: argument 1 requires (numeric or interval or daytimeinterval or 
yearmonthinterval) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of 
timestamp type.; line 1 pos 7
+cannot resolve '(- TIMESTAMP '1999-01-01 00:00:00')' due to data type 
mismatch: argument 1 requires (numeric or interval or day-time interval or 
year-month interval) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of 
timestamp type.; line 1 pos 7
 
 
 -- !query
@@ -516,4 +516,4 @@ select -x'2379ACFe'
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve '(- X'2379ACFE')' due to data type mismatch: argument 1 
requires (numeric or interval or daytimeinterval or yearmonthinterval) type, 
however, 'X'2379ACFE'' is of binary type.; line 1 pos 7
+cannot resolve '(- X'2379ACFE')' due to data type mismatch: argument 1 
requires (numeric or interval or day-time interval or year-month interval) 
type, however, 'X'2379ACFE'' is of binary type.; line 1 pos 7
diff --git 
a/sql/core/src/test/resources/sql-tests/results/typeCoercion/native/windowFrameCoercion.sql.out
 
b/sql/core/src/test/resources/sql-tests/results/typeCoercion/native/windowFrameCoercion.sql.out
index 1520d80..9ac9e67 100644
--- 
a/sql/core/src/test/resources/sql-tests/results/typeCoercion/native/windowFrameCoercion.sql.out
+++ 
b/sql/core/src/test/resources/sql-tests/results/typeCoercion/native/windowFrameCoercion.sql.out
@@ -168,7 +168,7 @@ SELECT COUNT(*) OVER (PARTITION BY 1 ORDER BY cast(1 as 
string) DESC RANGE BETWE
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve 'RANGE BETWEEN CURRENT ROW AND CAST(1 AS STRING) FOLLOWING' due 
to data type mismatch: The data type of the upper bound 'string' does not match 
the expected data type '(numeric or interval or daytimeinterval or 
yearmonthinterval)'.; line 1 pos 21
+cannot resolve 'RANGE BETWEEN CURRENT ROW AND CAST(1 AS STRING) FOLLOWING' due 
to data type mismatch: The data type of the upper bound 'string' does not match 
the expected data type '(numeric or interval or day-time interval or year-month 
interval)'.; line 1 pos 21
 
 
 -- !query
@@ -177,7 +177,7 @@ SELECT COUNT(*) OVER (PARTITION BY 1 ORDER BY cast('1' as 
binary) DESC RANGE BET
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve 'RANGE BETWEEN CURRENT ROW AND CAST(1 AS BINARY) FOLLOWING' due 
to data type mismatch: The data type of the upper bound 'binary' does not match 
the expected data type '(numeric or interval or daytimeinterval or 
yearmonthinterval)'.; line 1 pos 21
+cannot resolve 'RANGE BETWEEN CURRENT ROW AND CAST(1 AS BINARY) FOLLOWING' due 
to data type mismatch: The data type of the upper bound 'binary' does not match 
the expected data type '(numeric or interval or day-time interval or year-month 
interval)'.; line 1 pos 21
 
 
 -- !query
@@ -186,7 +186,7 @@ SELECT COUNT(*) OVER (PARTITION BY 1 ORDER BY cast(1 as 
boolean) DESC RANGE BETW
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve 'RANGE BETWEEN CURRENT ROW AND CAST(1 AS BOOLEAN) FOLLOWING' 
due to data type mismatch: The data type of the upper bound 'boolean' does not 
match the expected data type '(numeric or interval or daytimeinterval or 
yearmonthinterval)'.; line 1 pos 21
+cannot resolve 'RANGE BETWEEN CURRENT ROW AND CAST(1 AS BOOLEAN) FOLLOWING' 
due to data type mismatch: The data type of the upper bound 'boolean' does not 
match the expected data type '(numeric or interval or day-time interval or 
year-month interval)'.; line 1 pos 21
 
 
 -- !query


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

Reply via email to