[SPARK-35774][SQL] Parse any year-month interval types in SQL
### What changes were proposed in this pull request? This PR extends the parser rules to be able to parse the following types: * INTERVAL YEAR * INTERVAL YEAR TO MONTH * INTERVAL MONTH ### Why are the changes needed? For ANSI compliance. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? New assertion. Closes #32922 from sarutak/parse-any-year-month. Authored-by: Kousuke Saruta <sarutak@oss.nttdata.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
This commit is contained in:
parent
aaa8a80c9d
commit
4530760c40
|
@ -904,7 +904,7 @@ dataType
|
|||
: complex=ARRAY '<' dataType '>' #complexDataType
|
||||
| complex=MAP '<' dataType ',' dataType '>' #complexDataType
|
||||
| complex=STRUCT ('<' complexColTypeList? '>' | NEQ) #complexDataType
|
||||
| INTERVAL YEAR TO MONTH #yearMonthIntervalDataType
|
||||
| INTERVAL from=(YEAR | MONTH) (TO to=MONTH)? #yearMonthIntervalDataType
|
||||
| INTERVAL from=(DAY | HOUR | MINUTE | SECOND)
|
||||
(TO to=(HOUR | MINUTE | SECOND))? #dayTimeIntervalDataType
|
||||
| identifier ('(' INTEGER_VALUE (',' INTEGER_VALUE)* ')')? #primitiveDataType
|
||||
|
|
|
@ -2514,8 +2514,13 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
|
|||
}
|
||||
|
||||
override def visitYearMonthIntervalDataType(ctx: YearMonthIntervalDataTypeContext): DataType = {
|
||||
// TODO(SPARK-35774): Parse any year-month interval types in SQL
|
||||
YearMonthIntervalType()
|
||||
val start = YearMonthIntervalType.stringToField(ctx.from.getText.toLowerCase(Locale.ROOT))
|
||||
val end = if (ctx.to != null) {
|
||||
YearMonthIntervalType.stringToField(ctx.to.getText.toLowerCase(Locale.ROOT))
|
||||
} else {
|
||||
start
|
||||
}
|
||||
YearMonthIntervalType(start, end)
|
||||
}
|
||||
|
||||
override def visitDayTimeIntervalDataType(ctx: DayTimeIntervalDataTypeContext): DataType = {
|
||||
|
|
|
@ -256,7 +256,7 @@ class DataTypeSuite extends SparkFunSuite {
|
|||
checkDataTypeFromJson(VarcharType(10))
|
||||
checkDataTypeFromDDL(VarcharType(11))
|
||||
|
||||
checkDataTypeFromDDL(YearMonthIntervalType())
|
||||
yearMonthIntervalTypes.foreach(checkDataTypeFromDDL)
|
||||
dayTimeIntervalTypes.foreach(checkDataTypeFromDDL)
|
||||
|
||||
val metadata = new MetadataBuilder()
|
||||
|
|
Loading…
Reference in a new issue