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 fbe1bf3b [SPARK-61471][CONNECT][TESTS] Test that a deep plan over a 
deep expression is analyzed from a thread with a small stack
fbe1bf3b is described below

commit fbe1bf3b453c5437f3466af3689b56b5ff077a49
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Thu Nov 12 09:40:46 2026 +0900

    [SPARK-61471][CONNECT][TESTS] Test that a deep plan over a deep expression 
is analyzed from a thread with a small stack
    
    ### What changes were proposed in this pull request?
    
    An offline regression test, 
`test_a_plan_over_a_deep_expression_is_analyzed_from_a_thread_with_a_small_stack`
 in `python/tests/test_dropin_offline.py`. In a subprocess, a Python thread of 
512 KiB analyzes a DataFrame of 300 `withColumn` levels over a column of 700 
additions: it reads `schema`, `dtypes` and `isStreaming`, and calls 
`explain()`. The mock server sets the plan compression conf that a real server 
sets. The test checks that the process exits cleanly and that each analysis i 
[...]
    
    ### Why are the changes needed?
    
    That shape crashed the process with SIGBUS (exit 138) on master before 
#522, although each depth is within its own bound. With the plan compression of 
a real server, the encoded size of the plan is measured on the thread of the 
call. SPARK-61469 (#522) fixed it by driving the future of a blocking call from 
the heap. The existing small-stack tests cover a deep plan and a deep 
expression only separately, and without the plan compression conf, so they did 
not catch it. This test does: it [...]
    
    This is a follow-up of SPARK-61400 (#494).
    
    ### Does this PR introduce _any_ user-facing change?
    
    No, test only.
    
    ### How was this patch tested?
    
    The new test fails on master before #522 (returncode -10, SIGBUS) and 
passes with #522. The offline suite (1836 passed) and the e2e suite against a 
Spark 4.3.0 server (261 passed) pass, as do the Rust library tests, the 
`--no-run` builds, `cargo fmt --check`, `scripts/audit_no_stubs.sh` and the 
ruff gates. The repro shapes 300/700, 100/740, 600/700, 300/740 and 600/740 
(relation levels/additions) crash on a 512 KiB thread before #522, and all exit 
cleanly after it, for `schema`, `expl [...]
    
    ### 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 #533 from HyukjinKwon/SPARK-61471-deep-analyze-test.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 python/tests/test_dropin_offline.py | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/python/tests/test_dropin_offline.py 
b/python/tests/test_dropin_offline.py
index 63fdc5af..0f4891bf 100644
--- a/python/tests/test_dropin_offline.py
+++ b/python/tests/test_dropin_offline.py
@@ -10875,6 +10875,49 @@ thread.join()
     assert len(service.analyze_requests) == 1
 
 
+def 
test_a_plan_over_a_deep_expression_is_analyzed_from_a_thread_with_a_small_stack(mock_connect):
+    # The levels of a plan and the additions of an expression under it are one 
request: 300
+    # levels over a column of 700 additions overflowed the stack of the 
analyzing thread (SIGBUS),
+    # though each part is within its bound. The server sets the plan 
compression that a real one
+    # does, whose encoded size is measured on the thread of the call.
+    import subprocess
+    import sys
+
+    _, service = mock_connect
+    service.confs = _plan_confs(str(10 << 20))
+    script = """
+import threading
+from pyspark.sql import SparkSession, functions as F
+spark = SparkSession.builder.remote(REMOTE_URL).getOrCreate()
+
+def work():
+    c = F.col("id")
+    for _ in range(700):
+        c = c + 1
+    df = spark.range(1).withColumn("deep", c)
+    for x in range(300):
+        df = df.withColumn(f"col{x}", F.lit(x))
+    print("schema", len(df.schema.fields), flush=True)
+    print("dtypes", len(df.dtypes), flush=True)
+    print("streaming", df.isStreaming, flush=True)
+    df.explain()
+    print("explained", flush=True)
+
+threading.stack_size(512 * 1024)
+thread = threading.Thread(target=work)
+thread.start()
+thread.join()
+""".replace("REMOTE_URL", repr(service.remote))
+    result = subprocess.run(
+        [sys.executable, "-c", script], env=dict(os.environ, TZ="UTC"),
+        capture_output=True, text=True, timeout=300)
+    assert result.returncode == 0, result.stderr
+    assert "schema 1" in result.stdout, result.stdout
+    assert "explained" in result.stdout, result.stdout
+    # dtypes reads the schema that schema analyzed, so three requests are 
analyzed.
+    assert len(service.analyze_requests) == 3
+
+
 def 
test_create_dataframe_raises_recursion_error_for_a_value_that_contains_itself():
     class Node:
         def __init__(self):


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to