You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "puchengy (via GitHub)" <gi...@apache.org> on 2023/05/26 16:11:57 UTC

[GitHub] [spark] puchengy opened a new pull request, #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

puchengy opened a new pull request, #41332:
URL: https://github.com/apache/spark/pull/41332

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### 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.
   -->
   Support unwrap date type to string type in UnwrapCastInBinaryComparison. This is similar idea to other instances in UnwrapCastInBinaryComparison. And there is an implementation already but closed later on https://github.com/apache/spark/pull/40294/files.
   
   ### 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.
   -->
   Such that filter such as `dt = date '2023-01-01'` where dt is a string column can be pushed down to file scan operator.
   
   ### 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.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   Unit test.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] puchengy commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "puchengy (via GitHub)" <gi...@apache.org>.
puchengy commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1590248826

   @wangyum Yes. We won't push out a change that will produce incorrect result.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] wangyum commented on a diff in pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on code in PR #41332:
URL: https://github.com/apache/spark/pull/41332#discussion_r1228837517


##########
sql/core/src/test/scala/org/apache/spark/sql/UnwrapCastInComparisonEndToEndSuite.scala:
##########
@@ -264,5 +264,30 @@ class UnwrapCastInComparisonEndToEndSuite extends QueryTest with SharedSparkSess
     }
   }
 
+  test("SPARK-43801: Support unwrap date type to string type in UnwrapCastInBinaryComparison") {
+    val dt1 = "2023-01-01"
+    val dt2 = "2023-01-02"

Review Comment:
   Could you add another test?
   ```scala
   val dt3 = "2023-1-03"
   
   checkAnswer(df.where("dt = date'2023-01-03'"), Seq(dt3).map(Row(_)))
   ```



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] github-actions[bot] closed pull request #41332: [WIP][SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #41332: [WIP][SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison
URL: https://github.com/apache/spark/pull/41332


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] cloud-fan commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1571676096

   A reminder: for predicate like `dt = date'2020-01-01'`, it can match more than one string values, such as `2020`, `2020-1`, `2020-01`, `2020-01-1`, etc.
   
   We need to carefully do a reverse of `DateTimeUtils.stringToDate`, which is hard to get right.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] puchengy commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "puchengy (via GitHub)" <gi...@apache.org>.
puchengy commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1590459675

   @wangyum Yes, I know current version is not working. Will change the title to WIP to indicate this is not ready for review.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] wangyum commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1590349150

   > @wangyum Yes. We won't push out a change that will produce incorrect result.
   
   It seems the result is not correct after this patch:
   ```
   scala> spark.sql("CREATE TABLE t1(id int) PARTITIONED BY (dt string);")
   res0: org.apache.spark.sql.DataFrame = []
   
   scala> spark.sql("insert into t1 partition(dt = '2023-1-01') select 1;")
   res1: org.apache.spark.sql.DataFrame = []
   
   scala> spark.sql("select * from t1 where dt = date '2023-01-01';").show
   +---+---+
   | id| dt|
   +---+---+
   +---+---+
   
   scala> spark.sql("set spark.sql.optimizer.excludedRules=org.apache.spark.sql.catalyst.optimizer.UnwrapCastInBinaryComparison")
   res3: org.apache.spark.sql.DataFrame = [key: string, value: string]
   
   scala> spark.sql("select * from t1 where dt = date '2023-01-01';").show
   +---+---------+                                                                 
   | id|       dt|
   +---+---------+
   |  1|2023-1-01|
   +---+---------+
   
   ```


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] puchengy commented on a diff in pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "puchengy (via GitHub)" <gi...@apache.org>.
puchengy commented on code in PR #41332:
URL: https://github.com/apache/spark/pull/41332#discussion_r1228838136


##########
sql/core/src/test/scala/org/apache/spark/sql/UnwrapCastInComparisonEndToEndSuite.scala:
##########
@@ -264,5 +264,30 @@ class UnwrapCastInComparisonEndToEndSuite extends QueryTest with SharedSparkSess
     }
   }
 
+  test("SPARK-43801: Support unwrap date type to string type in UnwrapCastInBinaryComparison") {
+    val dt1 = "2023-01-01"
+    val dt2 = "2023-01-02"

Review Comment:
   Sure, will add this once we have a agreed solution, right now I am stuck due to lack of agreed solution



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] cloud-fan commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1581902802

   > Is this the right way to solve the problem?
   
   In my opinion, it is not. I don't think a large OR predicate is helpful in the pushdown case. As I said, if you believe your string-type "timestamp" column always contains standard timestamp strings, then you can manually do string comparison without OR.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] cloud-fan commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1575962729

   My suggestion for this problem is not to abuse the string type. If the column holds timestamp values, it should be timestamp type. If you know that your string-type "timestamp" type always contains standard timestamp string, you can also manually rewrite your predicate to just compare strings.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] puchengy commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "puchengy (via GitHub)" <gi...@apache.org>.
puchengy commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1564624051

   @wangyum @sunchao @sunchao @cloud-fan Hello, I wonder if you can take a look? Thanks. Previously there was an attempt already but closed later on https://github.com/apache/spark/pull/40294, now I am trying to continue the work.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] puchengy commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "puchengy (via GitHub)" <gi...@apache.org>.
puchengy commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1583011527

   @cloud-fan Thank you, but 
   
   > if you believe your string-type "timestamp" column always contains standard timestamp strings, then you can manually do string comparison
   
   Aren't we looking for a generic solution here? Wouldn't this create issues if the string-type "timestamp" column do not always contains standard timestamp string?
   
   My goal is merge this change, what change I need to implement to achieve? Would you please suggest, 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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] puchengy commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "puchengy (via GitHub)" <gi...@apache.org>.
puchengy commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1589721770

   @cloud-fan gentle ping, may I have your insights on how to make this PR work? 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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] wangyum commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "wangyum (via GitHub)" <gi...@apache.org>.
wangyum commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1590223150

   @puchengy Could you guarantee that the result returned by the following query is correct?
   ```sql
   CREATE TABLE t1(id int) PARTITIONED BY (dt string);
   
   insert into t1 partition(dt = '2023-1-01') select 1;
   insert into t1 partition(dt = '2023-01-02') select 2;
   
   select * from t1 where dt = date '2023-01-01';
   ```


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] github-actions[bot] commented on pull request #41332: [WIP][SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1738270070

   We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
   If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] puchengy commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "puchengy (via GitHub)" <gi...@apache.org>.
puchengy commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1571137648

   @wangyum Hi, sorry I did not get a chance to look into this. Will take a look as soon as possible.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] puchengy commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "puchengy (via GitHub)" <gi...@apache.org>.
puchengy commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1581471186

   @cloud-fan Hi, thanks for the suggestion.
   
   > We need to carefully do a reverse of DateTimeUtils.stringToDate, which is hard to get right.
   
   Is this the right way to solve the problem? To have a reverse of `stringToDate` function called `DateToPossibleStrings`. Then instead of having `Literal.create(date.toString, StringType)`, have a bunch of expression and OR them together. The expression will look like `Literal.create(possibleString_1, StringType) or Literal.create(possibleString_2, StringType) ...`
   
   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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] cloud-fan commented on pull request #41332: [WIP][SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1596844463

   > Aren't we looking for a generic solution here? Wouldn't this create issues if the string-type "timestamp" column do not always contains standard timestamp string?
   
   My take is for a general solution, the generated predicate will be very complicated to handle non-standard timestamp strings, probably with a lot of `Or` predicates, and the file source pushdown may not work well with such predicates.


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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] wForget commented on pull request #41332: [SPARK-43801][SQL] Support unwrap date type to string type in UnwrapCastInBinaryComparison

Posted by "wForget (via GitHub)" <gi...@apache.org>.
wForget commented on PR #41332:
URL: https://github.com/apache/spark/pull/41332#issuecomment-1575952608

   I found the same problem in hive data source, the partition filter cannot be pushed down due to the cast expression. Can we push down date type filter in `Shim_v0_13#getPartitionsByFilter`? In addition, is it possible to use unquoted date string to pass date filter? Hive metastore will parse unquoted date string into a date type. Refer to https://github.com/apache/hive/blob/7cd3107a76d633ef5fae2ffb8ec16953ac968092/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/parser/Filter.g#L546


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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

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