-
Notifications
You must be signed in to change notification settings - Fork 28k
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
[WIP][SPARK-35680][SQL] Support units by the year-month interval type #32825
Conversation
Kubernetes integration test starting |
Kubernetes integration test status success |
Test build #139499 has finished for PR 32825 at commit
|
.map(t => t.typeName -> t).toMap | ||
} | ||
|
||
/** Given the string representation of a type, return its DataType */ | ||
private def nameToType(name: String): DataType = { | ||
name match { | ||
case "decimal" => DecimalType.USER_DEFAULT | ||
case "interval year to month" => YearMonthIntervalType() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we follow FIXED_DECIMAL
and write a regex to support different units?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just stub to pass compiler errors. I don't think manually parsing is the right approach. I do believe that:
- Having two type parsers is bad idea
- We should use existing SQL parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to see a refactor here to use the SQL parser instead.
case (YEAR, MONTH) => "interval year to month" | ||
case (YEAR, YEAR) => "interval year" | ||
case (MONTH, MONTH) => "interval month" | ||
case _ => throw new AnalysisException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IllegalArgumentException
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's user-facing, can we put it in QueryCompilationError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the existing approach:
spark/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DecimalType.scala
Lines 47 to 55 in 0494dc9
if (scale > precision) { | |
throw new AnalysisException( | |
s"Decimal scale ($scale) cannot be greater than precision ($precision).") | |
} | |
if (precision > DecimalType.MAX_PRECISION) { | |
throw new AnalysisException( | |
s"${DecimalType.simpleString} can only support precision up to ${DecimalType.MAX_PRECISION}") | |
} |
* | ||
* @since 3.2.0 | ||
*/ | ||
@Unstable | ||
case object YearMonthIntervalType extends YearMonthIntervalType | ||
object YearMonthIntervalType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we follow DecinalType
and extends AbstractDataType
? This is useful when a function accepts all kinds of year month intervals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand this. Could you explain me, please. For now, the code works:
test("aaa") {
def f(y: YearMonthIntervalType): Int = {
y.defaultSize
}
f(YearMonthIntervalType(0, 1))
}
@cloud-fan or mean a different use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean ExpectsInputTypes.inputTypes
. The "function" I mentioned is SQL function (expression).
where is the SQL parser change to fill the units? |
This is WIP PR. Changes are coming. |
What changes were proposed in this pull request?
Extend YearMonthIntervalType to support:
Why are the changes needed?
Does this PR introduce any user-facing change?
How was this patch tested?