Skip to content

[python alternative] pyspark require Python2, failing if system default is Py3 from shell.py - #399

Closed
abhishekkr wants to merge 1 commit into
apache:masterfrom
ChaosCloud:pyspark_shell
Closed

abhishekkr wants to merge 1 commit into
apache:masterfrom
ChaosCloud:pyspark_shell

Conversation

@abhishekkr

Copy link
Copy Markdown
Contributor

Python alternative for #392; managed from shell.py

@AmplabJenkins

Copy link
Copy Markdown

Can one of the admins verify this patch?

@rxin

rxin commented Apr 17, 2014

Copy link
Copy Markdown
Contributor

Jenkins, test this please.

@rxin

rxin commented Apr 17, 2014

Copy link
Copy Markdown
Contributor

thanks. will merge once jenkins is happy.

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. All automated tests passed.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/14192/

@rxin

rxin commented Apr 17, 2014

Copy link
Copy Markdown
Contributor

Thanks. Merged.

@asfgit asfgit closed this in bb76eae Apr 17, 2014
asfgit pushed a commit that referenced this pull request Apr 17, 2014
…lt is Py3 from shell.py

Python alternative for #392; managed from shell.py

Author: AbhishekKr <abhikumar163@gmail.com>

Closes #399 from abhishekkr/pyspark_shell and squashes the following commits:

134bdc9 [AbhishekKr] pyspark require Python2, failing if system default is Py3 from shell.py

(cherry picked from commit bb76eae)
Signed-off-by: Reynold Xin <rxin@apache.org>
@abhishekkr
abhishekkr deleted the pyspark_shell branch April 17, 2014 03:24
pwendell added a commit to pwendell/spark that referenced this pull request May 12, 2014
Disable shuffle file consolidation by default

After running various performance tests for the 0.9 release, this still seems to have performance issues even on XFS. So let's keep this off-by-default for 0.9 and users can experiment with it depending on their disk configurations.
pdeyhim pushed a commit to pdeyhim/spark-1 that referenced this pull request Jun 25, 2014
…lt is Py3 from shell.py

Python alternative for apache#392; managed from shell.py

Author: AbhishekKr <abhikumar163@gmail.com>

Closes apache#399 from abhishekkr/pyspark_shell and squashes the following commits:

134bdc9 [AbhishekKr] pyspark require Python2, failing if system default is Py3 from shell.py
mccheah pushed a commit to mccheah/spark that referenced this pull request Nov 28, 2018
[SPARK-24434][K8S] pod template files
bzhaoopenstack pushed a commit to bzhaoopenstack/spark that referenced this pull request Sep 11, 2019
…support

Add jobs of openshift origin + public clouds
dongjoon-hyun added a commit that referenced this pull request Nov 19, 2026
…nal UDF twice without pruning any partition

### What changes were proposed in this pull request?

This PR fixes `PartitionPruning` so that it does not insert a dynamic partition pruning (DPP) filter on a join key that has a UDF which only the "Extract UDFs" batch can plan: a scalar Python UDF or an external UDF (`ExternalUserDefinedFunction`).

- `getFilterableTableScan` now returns no scan when the join key, as written in the join condition, has such a UDF.
- `needsUDFExtraction` now takes the expressions to check, so that the existing filtering side check and the new join key check share it.

### Why are the changes needed?

`PartitionPruning` inserts `Filter(DynamicPruningSubquery(pruningKey, ...), factScan)` when the pruning key refers only to partition columns. It checks the filtering side for such UDFs (SPARK-61824), but not the pruning key. For example:

```sql
SELECT f.date_id, f.store_id
FROM fact_sk f JOIN dim_store s ON pyudf(f.store_id) = s.store_id
WHERE s.country = 'NL'
```

The pruning key is `pyudf(store_id)`. `CleanupDynamicPruningFilters` keeps the DPP filter, as it is directly over the scan. Then the "Extract UDFs" batch, which runs after both rules, evaluates the UDF of the DPP filter in an evaluation node between the filter and the scan, and the UDF of the join key in another one:

```
BroadcastHashJoin [cast(pythonUDF0#5264 as int)], [store_id#5256], Inner, BuildRight, false, false
:- BatchEvalPython [pyudf(cast(store_id#5255 as string))], [date_id#5252, store_id#5255], [pythonUDF0#5264]
:  +- Project [date_id#5252, store_id#5255]
:     +- Filter dynamicpruningexpression(cast(pythonUDF0#5263 as int) IN dynamicpruning#5262)
:        :  +- SubqueryBroadcast dynamicpruning#5262, [0], [store_id#5256], [id=#399]
:        +- BatchEvalPython [pyudf(cast(store_id#5255 as string))], [date_id#5252, store_id#5255], [pythonUDF0#5263]
:           +- ColumnarToRow
:              +- FileScan parquet spark_catalog.default.fact_sk[date_id#5252,store_id#5255] ..., PartitionFilters: [], ...
+- ReusedExchange [store_id#5256], BroadcastExchange ...
```

As a result:
- The V1 and Hive scans and the V2 runtime filters no longer see the DPP filter, so it prunes no partition.
- The DPP filter runs as a row-level `FilterExec`.
- The UDF is evaluated on every row of the scan for the DPP filter, and again on the rows that pass it for the join key.
- Without a broadcast to reuse, and with `spark.sql.optimizer.dynamicPartitionPruning.reuseBroadcastOnly=false`, a standalone DPP subquery reads the filtering side again just for that row-level filter.

The query results are correct. This has been so since DPP was added in Apache Spark 3.0.0. The behavior above was confirmed with PySpark on Apache Spark 4.0.5, 4.1.4, 4.2.1 and 4.3.0.

With this PR, the plan has no DPP filter and one evaluation node, which evaluates the UDF once on every row of the scan.

The removed filter dropped, before the join, rows that the join drops anyway. So work between the scan and the join, such as another UDF column of a subquery, now runs on every row of the scan. This is the same trade-off that `CleanupDynamicPruningFilters` makes when it removes a DPP filter that is not pushed down to a scan.

This PR checks the join key as written, not the expression that the key refers to in the scan (its lineage). So it keeps the DPP filter of a key that has such a UDF only through an alias in a subquery, for example `(SELECT date_id, pyudf(store_id) AS store_id FROM fact_sk) f JOIN dim_store s ON f.store_id = s.store_id`:
- With `spark.sql.optimizer.avoidDoubleFilterEval=true` (default), the filter stays above the projection that evaluates the UDF. So it adds no evaluation of the UDF, and still drops rows before the join.
- If the pruning side is a union, the filter is pushed down into every branch, and a branch with a plain partition column, such as `UNION ALL SELECT date_id, store_id FROM fact_stats`, still prunes its partitions. A check on the lineage would look only at the first branch, so such a union would lose the pruning of every branch, depending on the order of its branches.

### Does this PR introduce _any_ user-facing change?

No in terms of query results. A query that joins on a partition column wrapped in a scalar Python UDF or an external UDF in the join condition no longer gets a DPP filter that prunes no partition. So the UDF is evaluated once instead of twice on the rows that match the join, and no standalone DPP subquery runs for it.

### How was this patch tested?

Pass the CIs with the newly added test cases in `DynamicPartitionPruningSuiteBase`, which run in the V1, V2 and Hive scan suites with and without AQE.
- `SPARK-62052: no DPP filter on a pruning key with a Python UDF` checks that no DPP filter is left above the scan and that the plan has one evaluation node.
- `SPARK-62052: no DPP filter on a pruning key with an external UDF` checks that the optimized plan has no `DynamicPruningSubquery`.
- `SPARK-62052: keep DPP on a pruning key with a Python UDF only through an alias` checks that a union whose first branch has the UDF in an alias of the key still prunes the partitions of its second branch.

The first two fail without the fix in all `DynamicPartitionPruning*Suite*` suites of `sql/core`. The last one passes without the fix, and fails with a check on the lineage instead of the join key.

```
$ build/sbt 'sql/testOnly org.apache.spark.sql.DynamicPartitionPruning* org.apache.spark.sql.InjectRuntimeFilterSuite'
$ build/sbt -Phive 'hive/testOnly org.apache.spark.sql.hive.DynamicPartitionPruningHiveScanSuite*'
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 5.5

Closes #60696 from dongjoon-hyun/SPARK-62052.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>


skip-checks: true
dongjoon-hyun added a commit that referenced this pull request Nov 19, 2026
…nal UDF twice without pruning any partition

### What changes were proposed in this pull request?

This PR fixes `PartitionPruning` so that it does not insert a dynamic partition pruning (DPP) filter on a join key that has a UDF which only the "Extract UDFs" batch can plan: a scalar Python UDF or an external UDF (`ExternalUserDefinedFunction`).

- `getFilterableTableScan` now returns no scan when the join key, as written in the join condition, has such a UDF.
- `needsUDFExtraction` now takes the expressions to check, so that the existing filtering side check and the new join key check share it.

### Why are the changes needed?

`PartitionPruning` inserts `Filter(DynamicPruningSubquery(pruningKey, ...), factScan)` when the pruning key refers only to partition columns. It checks the filtering side for such UDFs (SPARK-61824), but not the pruning key. For example:

```sql
SELECT f.date_id, f.store_id
FROM fact_sk f JOIN dim_store s ON pyudf(f.store_id) = s.store_id
WHERE s.country = 'NL'
```

The pruning key is `pyudf(store_id)`. `CleanupDynamicPruningFilters` keeps the DPP filter, as it is directly over the scan. Then the "Extract UDFs" batch, which runs after both rules, evaluates the UDF of the DPP filter in an evaluation node between the filter and the scan, and the UDF of the join key in another one:

```
BroadcastHashJoin [cast(pythonUDF0#5264 as int)], [store_id#5256], Inner, BuildRight, false, false
:- BatchEvalPython [pyudf(cast(store_id#5255 as string))], [date_id#5252, store_id#5255], [pythonUDF0#5264]
:  +- Project [date_id#5252, store_id#5255]
:     +- Filter dynamicpruningexpression(cast(pythonUDF0#5263 as int) IN dynamicpruning#5262)
:        :  +- SubqueryBroadcast dynamicpruning#5262, [0], [store_id#5256], [id=#399]
:        +- BatchEvalPython [pyudf(cast(store_id#5255 as string))], [date_id#5252, store_id#5255], [pythonUDF0#5263]
:           +- ColumnarToRow
:              +- FileScan parquet spark_catalog.default.fact_sk[date_id#5252,store_id#5255] ..., PartitionFilters: [], ...
+- ReusedExchange [store_id#5256], BroadcastExchange ...
```

As a result:
- The V1 and Hive scans and the V2 runtime filters no longer see the DPP filter, so it prunes no partition.
- The DPP filter runs as a row-level `FilterExec`.
- The UDF is evaluated on every row of the scan for the DPP filter, and again on the rows that pass it for the join key.
- Without a broadcast to reuse, and with `spark.sql.optimizer.dynamicPartitionPruning.reuseBroadcastOnly=false`, a standalone DPP subquery reads the filtering side again just for that row-level filter.

The query results are correct. This has been so since DPP was added in Apache Spark 3.0.0. The behavior above was confirmed with PySpark on Apache Spark 4.0.5, 4.1.4, 4.2.1 and 4.3.0.

With this PR, the plan has no DPP filter and one evaluation node, which evaluates the UDF once on every row of the scan.

The removed filter dropped, before the join, rows that the join drops anyway. So work between the scan and the join, such as another UDF column of a subquery, now runs on every row of the scan. This is the same trade-off that `CleanupDynamicPruningFilters` makes when it removes a DPP filter that is not pushed down to a scan.

This PR checks the join key as written, not the expression that the key refers to in the scan (its lineage). So it keeps the DPP filter of a key that has such a UDF only through an alias in a subquery, for example `(SELECT date_id, pyudf(store_id) AS store_id FROM fact_sk) f JOIN dim_store s ON f.store_id = s.store_id`:
- With `spark.sql.optimizer.avoidDoubleFilterEval=true` (default), the filter stays above the projection that evaluates the UDF. So it adds no evaluation of the UDF, and still drops rows before the join.
- If the pruning side is a union, the filter is pushed down into every branch, and a branch with a plain partition column, such as `UNION ALL SELECT date_id, store_id FROM fact_stats`, still prunes its partitions. A check on the lineage would look only at the first branch, so such a union would lose the pruning of every branch, depending on the order of its branches.

### Does this PR introduce _any_ user-facing change?

No in terms of query results. A query that joins on a partition column wrapped in a scalar Python UDF or an external UDF in the join condition no longer gets a DPP filter that prunes no partition. So the UDF is evaluated once instead of twice on the rows that match the join, and no standalone DPP subquery runs for it.

### How was this patch tested?

Pass the CIs with the newly added test cases in `DynamicPartitionPruningSuiteBase`, which run in the V1, V2 and Hive scan suites with and without AQE.
- `SPARK-62052: no DPP filter on a pruning key with a Python UDF` checks that no DPP filter is left above the scan and that the plan has one evaluation node.
- `SPARK-62052: no DPP filter on a pruning key with an external UDF` checks that the optimized plan has no `DynamicPruningSubquery`.
- `SPARK-62052: keep DPP on a pruning key with a Python UDF only through an alias` checks that a union whose first branch has the UDF in an alias of the key still prunes the partitions of its second branch.

The first two fail without the fix in all `DynamicPartitionPruning*Suite*` suites of `sql/core`. The last one passes without the fix, and fails with a check on the lineage instead of the join key.

```
$ build/sbt 'sql/testOnly org.apache.spark.sql.DynamicPartitionPruning* org.apache.spark.sql.InjectRuntimeFilterSuite'
$ build/sbt -Phive 'hive/testOnly org.apache.spark.sql.hive.DynamicPartitionPruningHiveScanSuite*'
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 5.5

Closes #60696 from dongjoon-hyun/SPARK-62052.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>

(cherry picked from commit 58f55ad)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>


skip-checks: true
dongjoon-hyun added a commit that referenced this pull request Nov 19, 2026
…nal UDF twice without pruning any partition

### What changes were proposed in this pull request?

This PR fixes `PartitionPruning` so that it does not insert a dynamic partition pruning (DPP) filter on a join key that has a UDF which only the "Extract UDFs" batch can plan: a scalar Python UDF or an external UDF (`ExternalUserDefinedFunction`).

- `getFilterableTableScan` now returns no scan when the join key, as written in the join condition, has such a UDF.
- `needsUDFExtraction` now takes the expressions to check, so that the existing filtering side check and the new join key check share it.

### Why are the changes needed?

`PartitionPruning` inserts `Filter(DynamicPruningSubquery(pruningKey, ...), factScan)` when the pruning key refers only to partition columns. It checks the filtering side for such UDFs (SPARK-61824), but not the pruning key. For example:

```sql
SELECT f.date_id, f.store_id
FROM fact_sk f JOIN dim_store s ON pyudf(f.store_id) = s.store_id
WHERE s.country = 'NL'
```

The pruning key is `pyudf(store_id)`. `CleanupDynamicPruningFilters` keeps the DPP filter, as it is directly over the scan. Then the "Extract UDFs" batch, which runs after both rules, evaluates the UDF of the DPP filter in an evaluation node between the filter and the scan, and the UDF of the join key in another one:

```
BroadcastHashJoin [cast(pythonUDF0#5264 as int)], [store_id#5256], Inner, BuildRight, false, false
:- BatchEvalPython [pyudf(cast(store_id#5255 as string))], [date_id#5252, store_id#5255], [pythonUDF0#5264]
:  +- Project [date_id#5252, store_id#5255]
:     +- Filter dynamicpruningexpression(cast(pythonUDF0#5263 as int) IN dynamicpruning#5262)
:        :  +- SubqueryBroadcast dynamicpruning#5262, [0], [store_id#5256], [id=#399]
:        +- BatchEvalPython [pyudf(cast(store_id#5255 as string))], [date_id#5252, store_id#5255], [pythonUDF0#5263]
:           +- ColumnarToRow
:              +- FileScan parquet spark_catalog.default.fact_sk[date_id#5252,store_id#5255] ..., PartitionFilters: [], ...
+- ReusedExchange [store_id#5256], BroadcastExchange ...
```

As a result:
- The V1 and Hive scans and the V2 runtime filters no longer see the DPP filter, so it prunes no partition.
- The DPP filter runs as a row-level `FilterExec`.
- The UDF is evaluated on every row of the scan for the DPP filter, and again on the rows that pass it for the join key.
- Without a broadcast to reuse, and with `spark.sql.optimizer.dynamicPartitionPruning.reuseBroadcastOnly=false`, a standalone DPP subquery reads the filtering side again just for that row-level filter.

The query results are correct. This has been so since DPP was added in Apache Spark 3.0.0. The behavior above was confirmed with PySpark on Apache Spark 4.0.5, 4.1.4, 4.2.1 and 4.3.0.

With this PR, the plan has no DPP filter and one evaluation node, which evaluates the UDF once on every row of the scan.

The removed filter dropped, before the join, rows that the join drops anyway. So work between the scan and the join, such as another UDF column of a subquery, now runs on every row of the scan. This is the same trade-off that `CleanupDynamicPruningFilters` makes when it removes a DPP filter that is not pushed down to a scan.

This PR checks the join key as written, not the expression that the key refers to in the scan (its lineage). So it keeps the DPP filter of a key that has such a UDF only through an alias in a subquery, for example `(SELECT date_id, pyudf(store_id) AS store_id FROM fact_sk) f JOIN dim_store s ON f.store_id = s.store_id`:
- With `spark.sql.optimizer.avoidDoubleFilterEval=true` (default), the filter stays above the projection that evaluates the UDF. So it adds no evaluation of the UDF, and still drops rows before the join.
- If the pruning side is a union, the filter is pushed down into every branch, and a branch with a plain partition column, such as `UNION ALL SELECT date_id, store_id FROM fact_stats`, still prunes its partitions. A check on the lineage would look only at the first branch, so such a union would lose the pruning of every branch, depending on the order of its branches.

### Does this PR introduce _any_ user-facing change?

No in terms of query results. A query that joins on a partition column wrapped in a scalar Python UDF or an external UDF in the join condition no longer gets a DPP filter that prunes no partition. So the UDF is evaluated once instead of twice on the rows that match the join, and no standalone DPP subquery runs for it.

### How was this patch tested?

Pass the CIs with the newly added test cases in `DynamicPartitionPruningSuiteBase`, which run in the V1, V2 and Hive scan suites with and without AQE.
- `SPARK-62052: no DPP filter on a pruning key with a Python UDF` checks that no DPP filter is left above the scan and that the plan has one evaluation node.
- `SPARK-62052: no DPP filter on a pruning key with an external UDF` checks that the optimized plan has no `DynamicPruningSubquery`.
- `SPARK-62052: keep DPP on a pruning key with a Python UDF only through an alias` checks that a union whose first branch has the UDF in an alias of the key still prunes the partitions of its second branch.

The first two fail without the fix in all `DynamicPartitionPruning*Suite*` suites of `sql/core`. The last one passes without the fix, and fails with a check on the lineage instead of the join key.

```
$ build/sbt 'sql/testOnly org.apache.spark.sql.DynamicPartitionPruning* org.apache.spark.sql.InjectRuntimeFilterSuite'
$ build/sbt -Phive 'hive/testOnly org.apache.spark.sql.hive.DynamicPartitionPruningHiveScanSuite*'
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 5.5

Closes #60696 from dongjoon-hyun/SPARK-62052.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>

(cherry picked from commit 58f55ad)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants