You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/06/14 08:07:17 UTC
[GitHub] [spark] sarutak opened a new pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
sarutak opened a new pull request #32893:
URL: https://github.com/apache/spark/pull/32893
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
This PR add a feature which allow the parser parse any day-time interval types in SQL.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
To comply with ANSI standard, we additionally need to support the following types.
* INTERVAL DAY
* INTERVAL DAY TO HOUR
* INTERVAL DAY TO MINUTE
* INTERVAL HOUR
* INTERVAL HOUR TO MINUTE
* INTERVAL HOUR TO SECOND
* INTERVAL MINUTE
* INTERVAL MINUTE TO SECOND
* INTERVAL SECOND
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
-->
New tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #32893:
URL: https://github.com/apache/spark/pull/32893#issuecomment-860131750
cc @MaxGekk @yaooqinn FYI
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA removed a comment on pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #32893:
URL: https://github.com/apache/spark/pull/32893#issuecomment-860094182
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins removed a comment on pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #32893:
URL: https://github.com/apache/spark/pull/32893#issuecomment-860106820
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] SparkQA commented on pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #32893:
URL: https://github.com/apache/spark/pull/32893#issuecomment-860094182
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] AmplabJenkins commented on pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #32893:
URL: https://github.com/apache/spark/pull/32893#issuecomment-860106820
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] MaxGekk commented on pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
Posted by GitBox <gi...@apache.org>.
MaxGekk commented on pull request #32893:
URL: https://github.com/apache/spark/pull/32893#issuecomment-860270913
+1, LGTM. GA passed. Merging to master.
<img width="753" alt="Screenshot 2021-06-14 at 00 11 46" src="https://user-images.githubusercontent.com/1580697/121821994-3ffac000-cca5-11eb-9ecb-d94d9a88258c.png">
Thank you, @sarutak .
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] MaxGekk closed pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
Posted by GitBox <gi...@apache.org>.
MaxGekk closed pull request #32893:
URL: https://github.com/apache/spark/pull/32893
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] sarutak commented on a change in pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
Posted by GitBox <gi...@apache.org>.
sarutak commented on a change in pull request #32893:
URL: https://github.com/apache/spark/pull/32893#discussion_r650562825
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -2514,8 +2514,19 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
}
override def visitDayTimeIntervalDataType(ctx: DayTimeIntervalDataTypeContext): DataType = {
- // TODO(SPARK-35736): Parse any day-time interval types in SQL
- DayTimeIntervalType()
+ def strToFieldIndex(str: String): Byte = str match {
Review comment:
Seems better. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] MaxGekk commented on a change in pull request #32893: [SPARK-35736][SQL] Parse any day-time interval types in SQL
Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #32893:
URL: https://github.com/apache/spark/pull/32893#discussion_r650556913
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -2514,8 +2514,19 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
}
override def visitDayTimeIntervalDataType(ctx: DayTimeIntervalDataTypeContext): DataType = {
- // TODO(SPARK-35736): Parse any day-time interval types in SQL
- DayTimeIntervalType()
+ def strToFieldIndex(str: String): Byte = str match {
Review comment:
You could avoid hardcoded constants:
```scala
val strToFieldIndex = dayTimeFields.map(i => fieldToString(i) -> i).toMap
```
##########
File path: sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala
##########
@@ -258,6 +258,15 @@ class DataTypeSuite extends SparkFunSuite {
checkDataTypeFromDDL(YearMonthIntervalType)
checkDataTypeFromDDL(DayTimeIntervalType())
+ checkDataTypeFromDDL(DayTimeIntervalType(DayTimeIntervalType.DAY, DayTimeIntervalType.MINUTE))
+ checkDataTypeFromDDL(DayTimeIntervalType(DayTimeIntervalType.DAY, DayTimeIntervalType.HOUR))
+ checkDataTypeFromDDL(DayTimeIntervalType(DayTimeIntervalType.DAY, DayTimeIntervalType.DAY))
+ checkDataTypeFromDDL(DayTimeIntervalType(DayTimeIntervalType.HOUR, DayTimeIntervalType.SECOND))
+ checkDataTypeFromDDL(DayTimeIntervalType(DayTimeIntervalType.HOUR, DayTimeIntervalType.MINUTE))
+ checkDataTypeFromDDL(DayTimeIntervalType(DayTimeIntervalType.HOUR, DayTimeIntervalType.HOUR))
+ checkDataTypeFromDDL(DayTimeIntervalType(DayTimeIntervalType.MINUTE, DayTimeIntervalType.SECOND))
+ checkDataTypeFromDDL(DayTimeIntervalType(DayTimeIntervalType.MINUTE, DayTimeIntervalType.MINUTE))
+ checkDataTypeFromDDL(DayTimeIntervalType(DayTimeIntervalType.SECOND, DayTimeIntervalType.SECOND))
Review comment:
Please, replace:
```suggestion
dayTimeIntervalTypes.foreach(checkDataTypeFromDDL)
```
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -2514,8 +2514,19 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
}
override def visitDayTimeIntervalDataType(ctx: DayTimeIntervalDataTypeContext): DataType = {
- // TODO(SPARK-35736): Parse any day-time interval types in SQL
- DayTimeIntervalType()
+ def strToFieldIndex(str: String): Byte = str match {
+ case "day" => 0
Review comment:
Could you replace the magic numbers by the constants from:
https://github.com/apache/spark/blob/d53831ff5cef618cfbc08dcea84ca9bb61ed9903/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DayTimeIntervalType.scala#L85-L88
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -2514,8 +2514,19 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
}
override def visitDayTimeIntervalDataType(ctx: DayTimeIntervalDataTypeContext): DataType = {
- // TODO(SPARK-35736): Parse any day-time interval types in SQL
- DayTimeIntervalType()
+ def strToFieldIndex(str: String): Byte = str match {
+ case "day" => 0
+ case "hour" => 1
+ case "minute" => 2
+ case "second" => 3
+ }
+ val from = strToFieldIndex(ctx.from.getText.toLowerCase(Locale.ROOT))
+ val to = if (ctx.to != null ) {
+ strToFieldIndex(ctx.to.getText.toLowerCase(Locale.ROOT))
+ } else {
+ from
+ }
+ DayTimeIntervalType(from, to)
Review comment:
Could you use `start` and `end` as in the SQL standard.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org