You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "monkeyboy123 (via GitHub)" <gi...@apache.org> on 2023/12/13 12:04:11 UTC
[PR] [SPARK-46392][SQL] Push down Cast expression [spark]
monkeyboy123 opened a new pull request, #44333:
URL: https://github.com/apache/spark/pull/44333
<!--
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.
-->
Push down Cast expression
### 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.
-->
Push down Cast expression to accurate compution.
### 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'.
-->
Considering table blow:
```
CREATE TABLE `tableA`(
s string)
PARTITIONED BY (
`dt` string COMMENT '日期, yyyyMMdd',
`hour` string COMMENT '小时, HH')
```
if we execute sql:
```
select * from where dt=20231212 and hour=22
```
After V2ScanRelationPushDown Rule been applyed,
Only IsNotNull(dt), IsNotNull(hour) be pushed to datasource, log like this:
Pushing operators to tableA
Pushed Filters: IsNotNull(dt), IsNotNull(hour)
Post-Scan Filters: (cast(dt#520 as int) = 20231212),(cast(hour#521 as int) = 10)
But what we need is IsNotNull(dt), IsNotNull(hour), EqualTo(dt,20231212), EqualTo(hour,10) shoule been pushed to dataSource, log like blow:
Pushing operators to tableA
Pushed Filters: IsNotNull(dt), IsNotNull(hour), EqualTo(dt,20231212), EqualTo(hour,10)
Post-Scan Filters:
### 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.
-->
NO UT
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
--
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
Re: [PR] [SPARK-46392][SQL] Push down Cast expression in DSv2 [spark]
Posted by "monkeyboy123 (via GitHub)" <gi...@apache.org>.
monkeyboy123 commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1855477343
> How do I do that? It's not from the `EXPLAIN` output, it seems.
Just run the sql and you will find the log in driver log.
--
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
Re: [PR] [WIP] [SPARK-46392][SQL]Push down Cast expression in DSv2 [spark]
Posted by "monkeyboy123 (via GitHub)" <gi...@apache.org>.
monkeyboy123 commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1862533623
I will close this as it is unreasonable.
--
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
Re: [PR] [WIP] [SPARK-46392][SQL]Push down Cast expression in DSv2 [spark]
Posted by "monkeyboy123 (via GitHub)" <gi...@apache.org>.
monkeyboy123 commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1862533166
I will close this as it is unreasonable.
--
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
Re: [PR] [SPARK-46392][SQL] Push down Cast expression in DSv2 [spark]
Posted by "monkeyboy123 (via GitHub)" <gi...@apache.org>.
monkeyboy123 commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1857105731
> Anyway, I don't mean to waste your time. I was just trying to reproduce the issue, but it seems there are more details involved that I don't follow.
Thanks for your review, i will task times to describe this issue more details, maybe it take some days.
--
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
Re: [PR] [SPARK-46392][SQL] Push down Cast expression in DSv2 [spark]
Posted by "monkeyboy123 (via GitHub)" <gi...@apache.org>.
monkeyboy123 commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1857130063
> And if I try another table, but this time `USING parquet`, I see `PartitionFilters` accepts the cast without issue:
BTW, What is your Final Physical Plan? is FileSourceScanExec?, the PR described here is BatchScanExec
--
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
Re: [PR] [SPARK-46392][SQL] Push down Cast expression in DSv2 [spark]
Posted by "monkeyboy123 (via GitHub)" <gi...@apache.org>.
monkeyboy123 commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1855267099
> Could you update your example with a working reproduction? This create table statement is invalid. It partitions on two columns `dt` and `hour` that do not exist in the column declaration. And the subsequent `select` is also invalid.; it's missing a table name.
create table statement:
```CREATE TABLE `tableA`(
`user_id` string COMMENT 'from deserializer')
PARTITIONED BY (
`dt` string COMMENT '日期, yyyyMMdd',
`hour` string COMMENT '小时, HH')
ROW FORMAT SERDE
'org.apache.paimon.hive.PaimonSerDe'
STORED BY
'org.apache.paimon.hive.PaimonStorageHandler'
WITH SERDEPROPERTIES (
'serialization.format'='1')
LOCATION
'xxxx'
TBLPROPERTIES (
'bucket'='50',
'bucketing_version'='2',
'bukect-key'='user_id',
'file.format'='parquet',
'merge-engine'='partial-update',
'partial-update.ignore-delete'='true',
'primary-key'='user_id',
'transient_lastDdlTime'='1701679855',
'write-only'='false')
```
It is a Paimon table, but it does not matter.
--
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
Re: [PR] [SPARK-46392][SQL] Push down Cast expression in DSv2 [spark]
Posted by "nchammas (via GitHub)" <gi...@apache.org>.
nchammas commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1856245494
Hmm, I am seeing a different plan:
```sql
spark-sql (default)> CREATE TABLE test (
> s string
> )
> PARTITIONED BY (
> dt string,
> hour string
> );
Time taken: 0.222 seconds
spark-sql (default)> explain select * from test where dt=20231212 and hour=22;
== Physical Plan ==
Scan hive spark_catalog.default.test (1)
(1) Scan hive spark_catalog.default.test
Output [3]: [s#0, dt#1, hour#2]
Arguments: [s#0, dt#1, hour#2],
HiveTableRelation [
`spark_catalog`.`default`.`test`, org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe,
Data Cols: [s#0], Partition Cols: [dt#1, hour#2], Pruned Partitions: []
], [isnotnull(dt#1), isnotnull(hour#2), (cast(dt#1 as int) = 20231212), (cast(hour#2 as int) = 22)]
```
And if I try another table, but this time `USING parquet`, I see `PartitionFilters` accepts the cast without issue:
```sql
spark-sql (default)> CREATE TABLE test (
> s string
> )
> USING parquet
> PARTITIONED BY (
> dt string,
> hour string
> );
Time taken: 0.1 seconds
spark-sql (default)> explain select * from test where dt=20231212 and hour=22;
== Physical Plan ==
*(1) ColumnarToRow
+- FileScan parquet spark_catalog.default.test[s#19,dt#20,hour#21] Batched: true, DataFilters: [], Format: Parquet,
Location: InMemoryFileIndex(0 paths)[],
PartitionFilters: [isnotnull(dt#20), isnotnull(hour#21), (cast(dt#20 as int) = 20231212), (cast(hour#21 as int) = 22)],
PushedFilters: [], ReadSchema: struct<s:string>
```
Anyway, I don't mean to waste your time. I was just trying to reproduce the issue, but it seems there are more details involved that I don't follow.
--
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
Re: [PR] [SPARK-46392][SQL] Push down Cast expression in DSv2 [spark]
Posted by "nchammas (via GitHub)" <gi...@apache.org>.
nchammas commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1858299366
I see this if I enable additional logging:
```
23/12/15 13:09:47 INFO FileSourceScanExec: Planning scan with bin packing, max size: 4194304 bytes, open cost is considered as scanning 4194304 bytes.
```
I guess I need to change the table format to force a `BatchScanExec`.
--
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
Re: [PR] [WIP] [SPARK-46392][SQL]Push down Cast expression in DSv2 [spark]
Posted by "monkeyboy123 (via GitHub)" <gi...@apache.org>.
monkeyboy123 closed pull request #44333: [WIP] [SPARK-46392][SQL]Push down Cast expression in DSv2
URL: https://github.com/apache/spark/pull/44333
--
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
Re: [PR] [SPARK-46392][SQL] Push down Cast expression in DSv2 [spark]
Posted by "nchammas (via GitHub)" <gi...@apache.org>.
nchammas commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1855242821
> CREATE TABLE `tableA`(
> s string)
> PARTITIONED BY (
> `dt` string COMMENT '日期, yyyyMMdd',
> `hour` string COMMENT '小时, HH')
Could you update your example with a working reproduction? This create table statement is invalid. It partitions on two columns `dt` and `hour` that do not exist in the column declaration. And the subsequent `select` is also invalid.; it's missing a table name.
--
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
Re: [PR] [SPARK-46392][SQL] Push down Cast expression in DSv2 [spark]
Posted by "nchammas (via GitHub)" <gi...@apache.org>.
nchammas commented on PR #44333:
URL: https://github.com/apache/spark/pull/44333#issuecomment-1855319808
My apologies. It looks like I made some mistake trying to run a similar `CREATE TABLE` statement. Your original statement was fine.
By the way, if I want to reproduce this log you shared:
> ```
> Pushing operators to tableA
> Pushed Filters: IsNotNull(dt), IsNotNull(hour)
> Post-Scan Filters: (cast(dt#520 as int) = 20231212),(cast(hour#521 as int) = 10)
> ```
How do I do that? It's not from the `EXPLAIN` output, it seems.
--
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