Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Jun 8, 2021

What changes were proposed in this pull request?

Extend YearMonthIntervalType to support:

  • INTERVAL YEAR
  • INTERVAL MONTH
  • INTERVAL YEAR TO MONTH

Why are the changes needed?

Does this PR introduce any user-facing change?

How was this patch tested?

@github-actions github-actions bot added the SQL label Jun 8, 2021
@SparkQA
Copy link

SparkQA commented Jun 8, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44022/

@SparkQA
Copy link

SparkQA commented Jun 8, 2021

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/44022/

@SparkQA
Copy link

SparkQA commented Jun 8, 2021

Test build #139499 has finished for PR 32825 at commit ef97d29.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

.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()
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IllegalArgumentException?

Copy link
Contributor

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?

Copy link
Member Author

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:

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 {
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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).

@cloud-fan
Copy link
Contributor

where is the SQL parser change to fill the units?

@MaxGekk
Copy link
Member Author

MaxGekk commented Jun 9, 2021

where is the SQL parser change to fill the units?

This is WIP PR. Changes are coming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants