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 @@ -1926,6 +1926,7 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
case ("decimal", precision :: Nil) => DecimalType(precision.getText.toInt, 0)
case ("decimal", precision :: scale :: Nil) =>
DecimalType(precision.getText.toInt, scale.getText.toInt)
case ("interval", Nil) => CalendarIntervalType
case (dt, params) =>
val dtStr = if (params.nonEmpty) s"$dt(${params.mkString(",")})" else dt
throw new ParseException(s"DataType $dtStr is not supported.", ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class DataTypeParserSuite extends SparkFunSuite {
checkDataType("varchAr(20)", StringType)
checkDataType("cHaR(27)", StringType)
checkDataType("BINARY", BinaryType)
checkDataType("interval", CalendarIntervalType)

checkDataType("array<doublE>", ArrayType(DoubleType, true))
checkDataType("Array<map<int, tinYint>>", ArrayType(MapType(IntegerType, ByteType, true), true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ class StructTypeSuite extends SparkFunSuite {
assert(7 == schema.treeString(0).split("\n").length)
assert(7 == schema.treeString(-1).split("\n").length)
}

test("interval keyword in schema string") {
val interval = "`a` INTERVAL"
assert(fromDDL(interval).toDDL === interval)
}
}
4 changes: 4 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/cast.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ SELECT HEX(CAST(-123L AS binary));
DESC FUNCTION boolean;
DESC FUNCTION EXTENDED boolean;
-- TODO: migrate all cast tests here.

-- cast string to interval and interval to string
SELECT CAST('interval 3 month 1 hour' AS interval);
SELECT CAST(interval 3 month 1 hour AS string);
18 changes: 17 additions & 1 deletion sql/core/src/test/resources/sql-tests/results/cast.sql.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 33
-- Number of queries: 35


-- !query 0
Expand Down Expand Up @@ -271,3 +271,19 @@ Extended Usage:

Function: boolean
Usage: boolean(expr) - Casts the value `expr` to the target data type `boolean`.


-- !query 33
SELECT CAST('interval 3 month 1 hour' AS interval)
-- !query 33 schema
struct<CAST(interval 3 month 1 hour AS INTERVAL):interval>
-- !query 33 output
interval 3 months 1 hours


-- !query 34
SELECT CAST(interval 3 month 1 hour AS string)
-- !query 34 schema
struct<CAST(interval 3 months 1 hours AS STRING):string>
-- !query 34 output
interval 3 months 1 hours