Skip to content

[SPARK-51404][SQL] Parse the time(n) type as TimeType(n) #50384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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 @@ -174,7 +174,7 @@ object DataType {
def fromJson(json: String): DataType = parseDataType(parse(json))

private val otherTypes = {
Seq(
(Seq(
NullType,
DateType,
TimestampType,
Expand Down Expand Up @@ -202,7 +202,8 @@ object DataType {
YearMonthIntervalType(MONTH),
YearMonthIntervalType(YEAR, MONTH),
TimestampNTZType,
VariantType)
VariantType) ++
(TimeType.MIN_PRECISION to TimeType.MAX_PRECISION).map(TimeType(_)))
.map(t => t.typeName -> t)
.toMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.json4s.jackson.JsonMethods

import org.apache.spark.{SparkException, SparkFunSuite, SparkIllegalArgumentException}
import org.apache.spark.sql.catalyst.analysis.{caseInsensitiveResolution, caseSensitiveResolution}
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser
import org.apache.spark.sql.catalyst.parser.{CatalystSqlParser, ParseException}
import org.apache.spark.sql.catalyst.types.DataTypeUtils
import org.apache.spark.sql.catalyst.util.{CollationFactory, StringConcat}
import org.apache.spark.sql.types.DataTypeTestUtils.{dayTimeIntervalTypes, yearMonthIntervalTypes}
Expand Down Expand Up @@ -1393,4 +1393,25 @@ class DataTypeSuite extends SparkFunSuite {
)
}
}

test("Parse time(n) as TimeType(n)") {
0 to 6 foreach { n =>
assert(DataType.fromJson(s"\"time($n)\"") == TimeType(n))
val expectedStructType = StructType(Seq(StructField("t", TimeType(n))))
assert(DataType.fromDDL(s"t time($n)") == expectedStructType)
}

checkError(
exception = intercept[SparkIllegalArgumentException] {
DataType.fromJson("\"time(9)\"")
},
condition = "INVALID_JSON_DATA_TYPE",
parameters = Map("invalidType" -> "time(9)"))
checkError(
exception = intercept[ParseException] {
DataType.fromDDL("t time(-1)")
},
condition = "PARSE_SYNTAX_ERROR",
parameters = Map("error" -> "'time'", "hint" -> ""))
}
}