This is an automated email from the ASF dual-hosted git repository.
HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git
The following commit(s) were added to refs/heads/master by this push:
new 7591b1ae [SPARK-61632][CONNECT][PYTHON] Replace the view in
register_temp_table and raise PySpark's error for a classic SQLContext, as
PySpark does, in Spark Connect Rust
7591b1ae is described below
commit 7591b1ae912f2996a9e0729300320ec6e6afd791
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Fri Nov 13 20:26:20 2026 +0900
[SPARK-61632][CONNECT][PYTHON] Replace the view in register_temp_table and
raise PySpark's error for a classic SQLContext, as PySpark does, in Spark
Connect Rust
### What changes were proposed in this pull request?
A survey looked for one class of mistake: a parity reference to the wrong
code, such as a deprecated API, classic instead of Connect code, full pyspark
instead of pyspark-client, or another version. The native ML is excluded, since
it is being moved off the deprecated `pyspark.ml.connect` separately. This PR
fixes what the survey found:
- `DataFrame::register_temp_table` in the Rust client calls
`create_or_replace_temp_view`. It called `create_temp_view`, which fails for an
existing name, while PySpark 4.3.0's `registerTempTable` is
`createOrReplaceTempView` with a FutureWarning. The drop-in's Python binding
was already right.
- The classic `pyspark.sql.SQLContext` and `HiveContext` shims behave as
pyspark-client 4.3.0's: they give PySpark's deprecation warnings, then raise
`PySparkAttributeError` with `JVM_ATTRIBUTE_NOT_SUPPORTED` for `_jsc` on a
session. Before, they raised `NOT_IMPLEMENTED` with an invented message.
- Three comments in `functions.py` that cited PySpark 4.2.0 now cite 4.3.0.
The `_FN_COL_ARGS` table already matched 4.3.0, all 170 entries.
- `test_functions_bucket` asserts the deprecation warning of `F.bucket`.
### Why are the changes needed?
For parity with PySpark 4.3.0:
- After `df.createOrReplaceTempView("v")`, `other.register_temp_table("v")`
failed with `TEMP_TABLE_OR_VIEW_ALREADY_EXISTS`. Now it replaces the view, as
PySpark's `registerTempTable` does.
- `SQLContext(spark)` raised `NOT_IMPLEMENTED`. pyspark-client 4.3.0 raises
`JVM_ATTRIBUTE_NOT_SUPPORTED` (`attr_name=_jsc`). The class, condition,
parameters and message now match the reference for `SQLContext(spark)`,
`HiveContext(spark, spark)` and `SQLContext(None)`.
The survey checked these as matching the reference already:
- about 30 deprecated APIs, with their warnings, categories, texts and
timing;
- every remote-only branch: `sparkContext`, `_jsc`, `_jvm`, the DataFrame
JVM attributes, and `hasattr` of `SparkContext`, `RDD` and `SQLContext`;
- the error timing of about 20 eager or lazy cases;
- the version claims in the docs.
### Does this PR introduce _any_ user-facing change?
Yes. In the Rust API, `register_temp_table` replaces an existing temporary
view instead of failing. In the Python client, `SQLContext(session)` and
`HiveContext(session)` raise PySpark's error and give its deprecation warnings.
### How was this patch tested?
- New tests, each checked to fail without the fix:
- Rust e2e: `register_temp_table_replaces_existing_view`;
- offline: `test_classic_sql_context_on_session_raises_jvm_attribute`.
- The `SQLContext(None)` test now expects the reference's error, and
`test_functions_bucket` asserts the warning.
- Also passing, with `TZ=UTC`:
- the Rust lib tests and the `--no-run` builds;
- `e2e_new_methods` and `e2e_coverage` against Spark 4.3.0;
- CI's offline Python set: 3532 passed;
- `cargo fmt`, the stub audit and ruff.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
This pull request and its description were written by Isaac.
Closes #636 from HyukjinKwon/SPARK-61632-wrong-references.
Authored-by: Hyukjin Kwon <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
---
crates/spark-connect/src/dataframe.rs | 4 ++--
crates/spark-connect/tests/e2e_new_methods.rs | 27 +++++++++++++++++++++++++++
python/pyspark/sql/context.py | 23 ++++++++++++++++-------
python/pyspark/sql/functions.py | 6 +++---
python/tests/test_dropin_offline.py | 26 ++++++++++++++++++++++++--
5 files changed, 72 insertions(+), 14 deletions(-)
diff --git a/crates/spark-connect/src/dataframe.rs
b/crates/spark-connect/src/dataframe.rs
index 0827bf02..45bbaa2a 100644
--- a/crates/spark-connect/src/dataframe.rs
+++ b/crates/spark-connect/src/dataframe.rs
@@ -2935,9 +2935,9 @@ impl DataFrame {
Ok(DataFrame::new(self.session.clone(), plan))
}
- /// Register this DataFrame as a temporary table (deprecated - use
createTempView).
+ /// Deprecated alias for create_or_replace_temp_view, as PySpark's
registerTempTable.
pub fn register_temp_table(&self, name: &str) -> Result<()> {
- self.create_temp_view(name)?;
+ self.create_or_replace_temp_view(name)?;
Ok(())
}
diff --git a/crates/spark-connect/tests/e2e_new_methods.rs
b/crates/spark-connect/tests/e2e_new_methods.rs
index a643d520..c6e124bf 100644
--- a/crates/spark-connect/tests/e2e_new_methods.rs
+++ b/crates/spark-connect/tests/e2e_new_methods.rs
@@ -50,6 +50,33 @@ fn temp_views_and_register() {
let _ = spark.sql("SELECT * FROM e2e_rtt").and_then(|d| d.collect());
}
+#[test]
+fn register_temp_table_replaces_existing_view() {
+ if !should_run() {
+ return;
+ }
+ let spark = session();
+ spark
+ .range_full(0, 5, 1, None)
+ .expect("range")
+ .create_temp_view("e2e_rtt_rep")
+ .expect("create_temp_view");
+
+ // registerTempTable is createOrReplaceTempView in PySpark, so it replaces
the view.
+ spark
+ .range_full(0, 2, 1, None)
+ .expect("range")
+ .register_temp_table("e2e_rtt_rep")
+ .expect("register_temp_table over an existing view");
+ let rows = spark
+ .sql("SELECT count(*) AS c FROM e2e_rtt_rep")
+ .expect("sql")
+ .collect()
+ .expect("collect");
+ assert_eq!(rows.len(), 1);
+ assert_eq!(rows[0].get(0), Some(&spark_connect::row::Value::Long(2)));
+}
+
#[test]
fn checkpoints_and_input_files_local() {
if !should_run() {
diff --git a/python/pyspark/sql/context.py b/python/pyspark/sql/context.py
index 7f5787b1..f70021d6 100644
--- a/python/pyspark/sql/context.py
+++ b/python/pyspark/sql/context.py
@@ -42,13 +42,14 @@ class SQLContext:
_instantiatedContext: ClassVar[Optional[Any]] = None
def __init__(self, sparkContext: Any, sparkSession: Any = None,
jsqlContext: Any = None):
- raise PySparkNotImplementedError(
- errorClass="NOT_IMPLEMENTED",
- messageParameters={
- "feature": f"{type(self).__name__}(sparkContext) in Spark
Connect; "
- f"use {type(self).__name__}.getOrCreate()"
- },
- )
+ if sparkSession is None:
+ warnings.warn(
+ "Deprecated in 3.0.0. Use SparkSession.builder.getOrCreate()
instead.",
+ FutureWarning,
+ )
+ # As in PySpark, the first thing the constructor reads is the JVM
SparkContext, which
+ # a Spark Connect session does not have: this raises
JVM_ATTRIBUTE_NOT_SUPPORTED.
+ self._jsc = sparkContext._jsc
@classmethod
def getOrCreate(cls, sc: Any = None) -> Any:
@@ -94,6 +95,14 @@ class HiveContext(SQLContext):
Use SparkSession.builder.enableHiveSupport().getOrCreate().
"""
+ def __init__(self, sparkContext: Any, sparkSession: Any = None,
jhiveContext: Any = None):
+ warnings.warn(
+ "HiveContext is deprecated in Spark 2.0.0. Please use "
+ + "SparkSession.builder.enableHiveSupport().getOrCreate()
instead.",
+ FutureWarning,
+ )
+ super().__init__(sparkContext, sparkSession, jhiveContext)
+
def _get_active_session_or_create() -> Any:
"""Mirror ``SparkSession._getActiveSessionOrCreate`` for the Rust-backed
session: the
diff --git a/python/pyspark/sql/functions.py b/python/pyspark/sql/functions.py
index 26f09e21..4eb9ac5b 100644
--- a/python/pyspark/sql/functions.py
+++ b/python/pyspark/sql/functions.py
@@ -66,7 +66,7 @@ def _wrap(obj):
"""Wrap the result from _call_function as a Column."""
return obj
-# Auto-derived from PySpark 4.2.0 signatures: for generated functions, which
positional
+# Auto-derived from PySpark 4.3.0 signatures: for generated functions, which
positional
# args are ColumnOrName (a bare str is a COLUMN NAME). Functions NOT listed
here have
# ALL args as columns. Value = (column_positions, variadic_col_start_or_None).
_FN_COL_ARGS = {
@@ -327,7 +327,7 @@ from pyspark.sql.udtf import (
# Hand-written special functions. Thin wrappers so the public parameter names
match
-# the reference PySpark 4.2.0 signatures (keyword-call parity), forwarding to
the native
+# the reference PySpark 4.3.0 signatures (keyword-call parity), forwarding to
the native
# bindings whose Rust arg names differ.
def col(col):
"""Returns a Column based on the given column name."""
@@ -1310,7 +1310,7 @@ __all__ = [
# Leave no loop variables behind, as PySpark has no `functions.name` or
`functions.obj`.
del name
-# Expose the `builtin` submodule at ``pyspark.sql.functions.builtin``.
Upstream v4.2.0 splits
+# Expose the `builtin` submodule at ``pyspark.sql.functions.builtin``.
Upstream v4.3.0 splits
# functions into a package whose ``builtin`` submodule holds the actual
functions and whose
# ``__init__`` re-exports them; here this module IS the implementation, so
register a synthetic
# ``builtin`` submodule mirroring it (so ``import
pyspark.sql.functions.builtin`` and
diff --git a/python/tests/test_dropin_offline.py
b/python/tests/test_dropin_offline.py
index 4bcb1822..accd641e 100644
--- a/python/tests/test_dropin_offline.py
+++ b/python/tests/test_dropin_offline.py
@@ -7335,7 +7335,8 @@ def test_functions_bucket():
from pyspark.sql import functions as F
c = F.col("x")
- result = F.bucket(10, c)
+ with pytest.warns(FutureWarning, match="Deprecated in 4.0.0, use
partitioning.bucket instead"):
+ result = F.bucket(10, c)
assert type(result).__name__ == "Column"
@@ -20491,7 +20492,7 @@ def test_sql_context_connect_backed():
HiveContext.getOrCreate()
with pytest.raises(PySparkNotImplementedError):
cctx.HiveContext(spark)
- with pytest.raises(PySparkNotImplementedError):
+ with pytest.raises(AttributeError, match="'NoneType' object has no
attribute '_jsc'"):
SQLContext(None)
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
@@ -20510,6 +20511,27 @@ def test_sql_context_connect_backed():
spark.stop()
+def test_classic_sql_context_on_session_raises_jvm_attribute():
+ from pyspark.errors import PySparkAttributeError
+ from pyspark.sql import HiveContext, SQLContext
+
+ spark = _offline_session()
+ try:
+ # As PySpark 4.3.0: the constructor reads sparkContext._jsc, which a
session lacks.
+ with pytest.warns(FutureWarning, match="Deprecated in 3.0.0"):
+ with pytest.raises(PySparkAttributeError) as e:
+ SQLContext(spark)
+ assert e.value.getCondition() == "JVM_ATTRIBUTE_NOT_SUPPORTED"
+ assert e.value.getMessageParameters() == {"attr_name": "_jsc"}
+ with pytest.warns(FutureWarning, match="HiveContext is deprecated in
Spark 2.0.0"):
+ with pytest.raises(PySparkAttributeError) as e:
+ HiveContext(spark, spark)
+ assert e.value.getCondition() == "JVM_ATTRIBUTE_NOT_SUPPORTED"
+ assert e.value.getMessageParameters() == {"attr_name": "_jsc"}
+ finally:
+ spark.stop()
+
+
def test_execution_info_and_operation_id():
from pyspark.errors import AnalysisException
from pyspark.errors.exceptions.connect import (
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]