-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-48843][FOLLOWUP] Adding a PySpark test. #47653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
65cf55d
New test_binding_parameters verifies no infinite loop in PySpark test…
nemanjapetr-db 5f4022f
Fix comment
nemanjapetr-db ac65442
Remove redundant tests.
nemanjapetr-db 3b1ab9e
Fix linter errors
nemanjapetr-db e21910e
Fix lint errors
nemanjapetr-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
from pyspark.sql import SparkSession | ||
from pyspark.testing.sqlutils import ReusedSQLTestCase | ||
|
||
|
||
class BindingParametersTests(ReusedSQLTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super(BindingParametersTests, cls).setUpClass() | ||
cls.spark = SparkSession.builder.getOrCreate() | ||
assert cls.spark is not None | ||
assert cls.spark._jvm.SparkSession.getDefaultSession().isDefined() | ||
|
||
def test_wrapping_plan_in_limit_node(self): | ||
# Test the following Scala equivalent | ||
# val df = spark.sql("EXECUTE IMMEDIATE 'SELECT SUM(c1) num_sum FROM VALUES (?), (?) | ||
# AS t(c1) ' USING 5, 6;") | ||
# val analyzedPlan = Limit(Literal.create(100), df.queryExecution.logical) | ||
# spark.sessionState.analyzer.executeAndCheck(analyzedPlan, df.queryExecution.tracker) | ||
sqlText = ( | ||
"""EXECUTE IMMEDIATE 'SELECT SUM(c1) num_sum FROM VALUES (?), (?) AS t(c1)' """ | ||
"""USING 5, 6;""" | ||
) | ||
df = self.spark.sql(sqlText) | ||
jvm = self.spark._jvm | ||
assert jvm is not None | ||
|
||
# Binds to jvm.org.apache.spark.sql.catalyst.expressions.Literal.create(), a version that | ||
# takes one input. | ||
boundMethodLiteralCreate = getattr( | ||
getattr(getattr(jvm.org.apache.spark.sql.catalyst.expressions, "Literal$"), "MODULE$"), | ||
"$anonfun$create$2", | ||
) | ||
|
||
# Binds Limit singleton. | ||
limitObj = getattr( | ||
getattr(jvm.org.apache.spark.sql.catalyst.plans.logical, "Limit$"), "MODULE$" | ||
) | ||
|
||
# It is not possible to call Limit singleton's constructor, calling apply() built-in | ||
# equivalent. | ||
analyzedplan = limitObj.apply( | ||
boundMethodLiteralCreate(100), # Equivalent to Literal.create(100) | ||
df._jdf.queryExecution().logical(), | ||
) | ||
self.spark._jsparkSession.sessionState().analyzer().executeAndCheck( | ||
analyzedplan, df._jdf.queryExecution().tracker() | ||
) | ||
|
||
self.assertEqual(self.spark.sql(sqlText).collect()[0][0], 11) | ||
self.assertEqual(self.spark.sql(sqlText).head().num_sum, 11) | ||
|
||
|
||
if __name__ == "__main__": | ||
import unittest | ||
from pyspark.sql.tests.test_binding_parameters import * # noqa: F401 | ||
|
||
try: | ||
import xmlrunner | ||
|
||
testRunner = xmlrunner.XMLTestRunner(output="target/test-reports", verbosity=2) | ||
except ImportError: | ||
testRunner = None | ||
unittest.main(testRunner=testRunner, verbosity=2) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we need a PySpark specific test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spark.sql
has no difference between Scala Spark and Python Spark, otherwise we will need to duplicate a lot of tests in pyspark.