Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
* {{{
* [TYPE] '[VALUE]'
* }}}
* Currently Date, Timestamp, Interval, Binary and INTEGER typed literals are supported.
* Currently Date, Timestamp, Interval and Binary typed literals are supported.
*/
override def visitTypeConstructor(ctx: TypeConstructorContext): Literal = withOrigin(ctx) {
val value = string(ctx.STRING)
Expand Down Expand Up @@ -1897,16 +1897,6 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
case "X" =>
val padding = if (value.length % 2 != 0) "0" else ""
Literal(DatatypeConverter.parseHexBinary(padding + value))
case "INTEGER" =>
val i = try {
value.toInt
} catch {
case e: NumberFormatException =>
val ex = new ParseException(s"Cannot parse the Int value: $value, $e", ctx)
ex.setStackTrace(e.getStackTrace)
throw ex
}
Literal(i, IntegerType)
case other =>
throw new ParseException(s"Literals of type '$other' are currently not" +
" supported.", ctx)
Expand Down
7 changes: 0 additions & 7 deletions sql/core/src/test/resources/sql-tests/inputs/literals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,7 @@ select X'XuZ';
-- Hive literal_double test.
SELECT 3.14, -3.14, 3.14e8, 3.14e-8, -3.14e8, -3.14e-8, 3.14e+8, 3.14E8, 3.14E-8;

-- typed integer expression
select integer '7';
select integer'7';
select integer '2147483648';

-- awareness of the negative/positive sign before type
select -integer '7';
select +integer '7';
select +date '1999-01-01';
select +timestamp '1999-01-01';
select +interval '1 day';
Expand Down
106 changes: 30 additions & 76 deletions sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 55
-- Number of queries: 50


-- !query 0
Expand Down Expand Up @@ -393,135 +393,89 @@ struct<3.14:decimal(3,2),-3.14:decimal(3,2),3.14E8:double,3.14E-8:double,-3.14E8


-- !query 40
select integer '7'
-- !query 40 schema
struct<7:int>
-- !query 40 output
7


-- !query 41
select integer'7'
-- !query 41 schema
struct<7:int>
-- !query 41 output
7


-- !query 42
select integer '2147483648'
-- !query 42 schema
struct<>
-- !query 42 output
org.apache.spark.sql.catalyst.parser.ParseException

Cannot parse the Int value: 2147483648, java.lang.NumberFormatException: For input string: "2147483648"(line 1, pos 7)

== SQL ==
select integer '2147483648'
-------^^^


-- !query 43
select -integer '7'
-- !query 43 schema
struct<(- 7):int>
-- !query 43 output
-7


-- !query 44
select +integer '7'
-- !query 44 schema
struct<(+ 7):int>
-- !query 44 output
7


-- !query 45
select +date '1999-01-01'
-- !query 45 schema
-- !query 40 schema
struct<>
-- !query 45 output
-- !query 40 output
org.apache.spark.sql.AnalysisException
cannot resolve '(+ DATE '1999-01-01')' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7


-- !query 46
-- !query 41
select +timestamp '1999-01-01'
-- !query 46 schema
-- !query 41 schema
struct<>
-- !query 46 output
-- !query 41 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) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of timestamp type.; line 1 pos 7


-- !query 47
-- !query 42
select +interval '1 day'
-- !query 47 schema
-- !query 42 schema
struct<(+ INTERVAL '1 days'):interval>
-- !query 47 output
-- !query 42 output
1 days


-- !query 48
-- !query 43
select +map(1, 2)
-- !query 48 schema
-- !query 43 schema
struct<>
-- !query 48 output
-- !query 43 output
org.apache.spark.sql.AnalysisException
cannot resolve '(+ map(1, 2))' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'map(1, 2)' is of map<int,int> type.; line 1 pos 7


-- !query 49
-- !query 44
select +array(1,2)
-- !query 49 schema
-- !query 44 schema
struct<>
-- !query 49 output
-- !query 44 output
org.apache.spark.sql.AnalysisException
cannot resolve '(+ array(1, 2))' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'array(1, 2)' is of array<int> type.; line 1 pos 7


-- !query 50
-- !query 45
select +named_struct('a', 1, 'b', 'spark')
-- !query 50 schema
-- !query 45 schema
struct<>
-- !query 50 output
-- !query 45 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) type, however, 'named_struct('a', 1, 'b', 'spark')' is of struct<a:int,b:string> type.; line 1 pos 7


-- !query 51
-- !query 46
select +X'1'
-- !query 51 schema
-- !query 46 schema
struct<>
-- !query 51 output
-- !query 46 output
org.apache.spark.sql.AnalysisException
cannot resolve '(+ X'01')' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'X'01'' is of binary type.; line 1 pos 7


-- !query 52
-- !query 47
select -date '1999-01-01'
-- !query 52 schema
-- !query 47 schema
struct<>
-- !query 52 output
-- !query 47 output
org.apache.spark.sql.AnalysisException
cannot resolve '(- DATE '1999-01-01')' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7


-- !query 53
-- !query 48
select -timestamp '1999-01-01'
-- !query 53 schema
-- !query 48 schema
struct<>
-- !query 53 output
-- !query 48 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) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of timestamp type.; line 1 pos 7


-- !query 54
-- !query 49
select -x'2379ACFe'
-- !query 54 schema
-- !query 49 schema
struct<>
-- !query 54 output
-- !query 49 output
org.apache.spark.sql.AnalysisException
cannot resolve '(- X'2379ACFE')' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'X'2379ACFE'' is of binary type.; line 1 pos 7
Expand Down
106 changes: 30 additions & 76 deletions sql/core/src/test/resources/sql-tests/results/literals.sql.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 55
-- Number of queries: 50


-- !query 0
Expand Down Expand Up @@ -393,135 +393,89 @@ struct<3.14:decimal(3,2),-3.14:decimal(3,2),3.14E8:double,3.14E-8:double,-3.14E8


-- !query 40
select integer '7'
-- !query 40 schema
struct<7:int>
-- !query 40 output
7


-- !query 41
select integer'7'
-- !query 41 schema
struct<7:int>
-- !query 41 output
7


-- !query 42
select integer '2147483648'
-- !query 42 schema
struct<>
-- !query 42 output
org.apache.spark.sql.catalyst.parser.ParseException

Cannot parse the Int value: 2147483648, java.lang.NumberFormatException: For input string: "2147483648"(line 1, pos 7)

== SQL ==
select integer '2147483648'
-------^^^


-- !query 43
select -integer '7'
-- !query 43 schema
struct<(- 7):int>
-- !query 43 output
-7


-- !query 44
select +integer '7'
-- !query 44 schema
struct<(+ 7):int>
-- !query 44 output
7


-- !query 45
select +date '1999-01-01'
-- !query 45 schema
-- !query 40 schema
struct<>
-- !query 45 output
-- !query 40 output
org.apache.spark.sql.AnalysisException
cannot resolve '(+ DATE '1999-01-01')' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7


-- !query 46
-- !query 41
select +timestamp '1999-01-01'
-- !query 46 schema
-- !query 41 schema
struct<>
-- !query 46 output
-- !query 41 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) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of timestamp type.; line 1 pos 7


-- !query 47
-- !query 42
select +interval '1 day'
-- !query 47 schema
-- !query 42 schema
struct<(+ INTERVAL '1 days'):interval>
-- !query 47 output
-- !query 42 output
1 days


-- !query 48
-- !query 43
select +map(1, 2)
-- !query 48 schema
-- !query 43 schema
struct<>
-- !query 48 output
-- !query 43 output
org.apache.spark.sql.AnalysisException
cannot resolve '(+ map(1, 2))' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'map(1, 2)' is of map<int,int> type.; line 1 pos 7


-- !query 49
-- !query 44
select +array(1,2)
-- !query 49 schema
-- !query 44 schema
struct<>
-- !query 49 output
-- !query 44 output
org.apache.spark.sql.AnalysisException
cannot resolve '(+ array(1, 2))' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'array(1, 2)' is of array<int> type.; line 1 pos 7


-- !query 50
-- !query 45
select +named_struct('a', 1, 'b', 'spark')
-- !query 50 schema
-- !query 45 schema
struct<>
-- !query 50 output
-- !query 45 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) type, however, 'named_struct('a', 1, 'b', 'spark')' is of struct<a:int,b:string> type.; line 1 pos 7


-- !query 51
-- !query 46
select +X'1'
-- !query 51 schema
-- !query 46 schema
struct<>
-- !query 51 output
-- !query 46 output
org.apache.spark.sql.AnalysisException
cannot resolve '(+ X'01')' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'X'01'' is of binary type.; line 1 pos 7


-- !query 52
-- !query 47
select -date '1999-01-01'
-- !query 52 schema
-- !query 47 schema
struct<>
-- !query 52 output
-- !query 47 output
org.apache.spark.sql.AnalysisException
cannot resolve '(- DATE '1999-01-01')' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'DATE '1999-01-01'' is of date type.; line 1 pos 7


-- !query 53
-- !query 48
select -timestamp '1999-01-01'
-- !query 53 schema
-- !query 48 schema
struct<>
-- !query 53 output
-- !query 48 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) type, however, 'TIMESTAMP '1999-01-01 00:00:00'' is of timestamp type.; line 1 pos 7


-- !query 54
-- !query 49
select -x'2379ACFe'
-- !query 54 schema
-- !query 49 schema
struct<>
-- !query 54 output
-- !query 49 output
org.apache.spark.sql.AnalysisException
cannot resolve '(- X'2379ACFE')' due to data type mismatch: argument 1 requires (numeric or interval) type, however, 'X'2379ACFE'' is of binary type.; line 1 pos 7
Expand Down