You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ru...@apache.org on 2025/07/23 08:30:33 UTC
(spark) branch master updated: [SPARK-52751][PYTHON][CONNECT] Don't eagerly validate column name in `dataframe['col_name']`
This is an automated email from the ASF dual-hosted git repository.
ruifengz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 19cedecc36f8 [SPARK-52751][PYTHON][CONNECT] Don't eagerly validate column name in `dataframe['col_name']`
19cedecc36f8 is described below
commit 19cedecc36f8fae324a1e847799ff440c7e680d7
Author: Ruifeng Zheng <ru...@apache.org>
AuthorDate: Wed Jul 23 16:30:14 2025 +0800
[SPARK-52751][PYTHON][CONNECT] Don't eagerly validate column name in `dataframe['col_name']`
### What changes were proposed in this pull request?
Don't eagerly validate column name in `dataframe['col_name']`
### Why are the changes needed?
to save ANALYZE RPC, fail the query on connect server side
### Does this PR introduce _any_ user-facing change?
yes, `df['bad_column']` will fail on analysis or execution
### How was this patch tested?
updated tests
### Was this patch authored or co-authored using generative AI tooling?
no
Closes #51400 from zhengruifeng/test_fail_col.
Authored-by: Ruifeng Zheng <ru...@apache.org>
Signed-off-by: Ruifeng Zheng <ru...@apache.org>
---
python/docs/source/migration_guide/pyspark_upgrade.rst | 2 ++
python/pyspark/sql/connect/dataframe.py | 5 ++++-
python/pyspark/sql/tests/test_column.py | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/python/docs/source/migration_guide/pyspark_upgrade.rst b/python/docs/source/migration_guide/pyspark_upgrade.rst
index 453fd3917ceb..50a2488bd3ea 100644
--- a/python/docs/source/migration_guide/pyspark_upgrade.rst
+++ b/python/docs/source/migration_guide/pyspark_upgrade.rst
@@ -22,6 +22,8 @@ Upgrading PySpark
Upgrading from PySpark 4.0 to 4.1
---------------------------------
+* In Spark 4.1, ``DataFrame['name']`` on Spark Connect Python Client no longer eagerly validate the column name. To restore the legacy behavior, set ``PYSPARK_VALIDATE_COLUMN_NAME_LEGACY`` environment variable to ``1``.
+
* In Spark 4.1, Arrow-optimized Python UDF supports UDT input / output instead of falling back to the regular UDF. To restore the legacy behavior, set ``spark.sql.execution.pythonUDF.arrow.legacy.fallbackOnUDT`` to ``true``.
* In Spark 4.1, unnecessary conversion to pandas instances is removed when ``spark.sql.execution.pythonUDF.arrow.enabled`` is enabled. As a result, the type coercion changes when the produced output has a schema different from the specified schema. To restore the previous behavior, enable ``spark.sql.legacy.execution.pythonUDF.pandas.conversion.enabled``.
diff --git a/python/pyspark/sql/connect/dataframe.py b/python/pyspark/sql/connect/dataframe.py
index 4f958074514d..799816797602 100644
--- a/python/pyspark/sql/connect/dataframe.py
+++ b/python/pyspark/sql/connect/dataframe.py
@@ -44,6 +44,7 @@ from typing import (
)
import copy
+import os
import sys
import random
import pyarrow as pa
@@ -1740,7 +1741,9 @@ class DataFrame(ParentDataFrame):
# }
# validate the column name
- if not hasattr(self._session, "is_mock_session"):
+ if os.environ.get("PYSPARK_VALIDATE_COLUMN_NAME_LEGACY") == "1" and not hasattr(
+ self._session, "is_mock_session"
+ ):
from pyspark.sql.connect.types import verify_col_name
# Try best to verify the column name with cached schema
diff --git a/python/pyspark/sql/tests/test_column.py b/python/pyspark/sql/tests/test_column.py
index 5f1991973d27..7e69690ba4eb 100644
--- a/python/pyspark/sql/tests/test_column.py
+++ b/python/pyspark/sql/tests/test_column.py
@@ -133,8 +133,8 @@ class ColumnTestsMixin:
self.assertTrue(isinstance(df["key"], Column))
self.assertTrue(isinstance(df[0], Column))
self.assertRaises(IndexError, lambda: df[2])
- self.assertRaises(AnalysisException, lambda: df["bad_key"])
self.assertRaises(TypeError, lambda: df[{}])
+ self.assertRaises(AnalysisException, lambda: df.select(df["bad_key"]).schema)
def test_column_name_with_non_ascii(self):
columnName = "数量"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org