Repository navigation
[SPARK-60294][SQL] Disable Arrow-backed columnar input to Python UDFs by default #59551
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
9c9a900
[SPARK-60294][SQL] Copy the pass-through columns of Arrow-backed inpu…
HyukjinKwon c6bcd01
Skip batches with list views, guard copies against task completion, a…
HyukjinKwon 91aa31b
Disable Arrow-backed columnar input to Python UDFs by default instead…
HyukjinKwon 21eb5b5
Enable columnar input in the tests of Arrow Python UDFs over the Arro…
HyukjinKwon a37bb49
Check the configuration in doExecute too, and document the new default
HyukjinKwon 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
85 changes: 85 additions & 0 deletions
85
...core/src/test/scala/org/apache/spark/sql/execution/python/ArrowCachedPythonUDFSuite.scala
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,85 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.execution.python | ||
|
|
||
| import org.apache.spark.SparkConf | ||
| import org.apache.spark.sql.IntegratedUDFTestUtils | ||
| import org.apache.spark.sql.execution.columnar.{ArrowCachedBatchSerializer, InMemoryRelation} | ||
| import org.apache.spark.sql.internal.{SQLConf, StaticSQLConf} | ||
| import org.apache.spark.sql.test.SharedSparkSession | ||
| import org.apache.spark.sql.types.StringType | ||
|
|
||
| /** | ||
| * Tests Arrow Python UDFs over the Arrow cache, whose scan returns rows or Arrow-backed batches, | ||
| * and closes the root of the previous batch when it returns the next one. | ||
| */ | ||
| class ArrowCachedPythonUDFSuite extends SharedSparkSession { | ||
|
|
||
| import IntegratedUDFTestUtils._ | ||
|
|
||
| override protected def sparkConf: SparkConf = super.sparkConf | ||
| .set(StaticSQLConf.SPARK_CACHE_SERIALIZER.key, classOf[ArrowCachedBatchSerializer].getName) | ||
|
|
||
| // The serializer of the cache is kept for the JVM once it is used. | ||
| override def beforeAll(): Unit = { | ||
| InMemoryRelation.clearSerializer() | ||
| super.beforeAll() | ||
| } | ||
|
|
||
| override def afterAll(): Unit = { | ||
| try { | ||
| super.afterAll() | ||
| } finally { | ||
| InMemoryRelation.clearSerializer() | ||
| } | ||
| } | ||
|
|
||
| test("Arrow Python UDFs over the Arrow cache with the default configuration") { | ||
| assume(shouldTestPandasUDFs) | ||
| // The scan of the Arrow cache also returns rows, so no ColumnarToRowExec is added below | ||
| // ArrowEvalPythonExec, whose child still supports columnar: it must still read rows when | ||
| // columnar input is disabled, as it is by default. | ||
| withSQLConf(SQLConf.ARROW_EXECUTION_MAX_RECORDS_PER_BATCH.key -> "1000") { | ||
| val pandasUDF = TestScalarPandasUDF( | ||
| name = "cached_str_udf", returnType = Some(StringType)) | ||
| registerTestUDF(pandasUDF, spark) | ||
|
|
||
| val cached = spark.range(0, 200000, 1, 1).selectExpr("id", "CAST(id AS STRING) AS s") | ||
| .cache() | ||
| try { | ||
| // The test UDF casts its input to string, which is removed on a string column. | ||
| val result = cached.selectExpr("id", "s", "cached_str_udf(s) AS u") | ||
| val arrowExec = result.queryExecution.executedPlan.collect { | ||
| case exec: ArrowEvalPythonExec => exec | ||
| } | ||
| assert(arrowExec.nonEmpty && arrowExec.head.child.supportsColumnar && | ||
| !arrowExec.head.supportsColumnar) | ||
|
|
||
| val rows = result.collect() | ||
| assert(rows.map(_.getLong(0)).toSeq == (0L until 200000L)) | ||
| rows.foreach { row => | ||
| val id = row.getLong(0) | ||
| assert(row.getString(1) == id.toString, s"pass-through mismatch for id $id") | ||
| assert(row.getString(2) == id.toString, s"UDF result mismatch for id $id") | ||
| } | ||
| } finally { | ||
| cached.unpersist() | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
nit:
batchSizeonly applies whenreuseVectorsis true.ArrowBackedPartitionReaderstill usesBATCH_SIZE, soreadArrowSource(batchSize = ...)withoutreuseVectorsignores it without saying so. Could the existing reader take it too, or could the option say that it only applies to the reusing reader?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.
Done in c6bcd01:
ArrowBackedPartitionReadertakesbatchSizetoo.