-
Notifications
You must be signed in to change notification settings - Fork 232
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
Add test for selecting a single complex field array and its parent struct array [databricks] #9018
Merged
razajafri
merged 6 commits into
NVIDIA:branch-23.10
from
razajafri:SP-8712-schema-pruning-test
Aug 18, 2023
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0520fb9
added tests for orc/parquet schema evolution
razajafri 87a7c9c
Signing off
razajafri 84bd061
Addressed review comments
razajafri 8c5a637
Merge remote-tracking branch 'origin/branch-23.10' into SP-8712-schem…
razajafri 7188e3c
addressed review comments
razajafri 620ed84
addressed review comments
razajafri 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 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
22 changes: 22 additions & 0 deletions
22
sql-plugin/src/main/scala/com/nvidia/spark/rapids/AdaptiveSparkPlanHelperImpl.scala
This file contains 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,22 @@ | ||
/* | ||
* Copyright (c) 2023, NVIDIA CORPORATION. | ||
* | ||
* Licensed 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 com.nvidia.spark.rapids | ||
|
||
import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper | ||
import org.apache.spark.sql.rapids.AdaptiveSparkPlanHelperShim | ||
|
||
class AdaptiveSparkPlanHelperImpl extends AdaptiveSparkPlanHelperShim with AdaptiveSparkPlanHelper |
This file contains 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 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 |
---|---|---|
|
@@ -20,7 +20,7 @@ import scala.collection.convert.ImplicitConversions.`collection AsScalaIterable` | |
import scala.collection.mutable.{ArrayBuffer, Map => MutableMap} | ||
import scala.util.matching.Regex | ||
|
||
import com.nvidia.spark.rapids.{PlanShims, PlanUtils} | ||
import com.nvidia.spark.rapids.{PlanShims, PlanUtils, ShimLoader} | ||
|
||
import org.apache.spark.sql.{DataFrame, SparkSession} | ||
import org.apache.spark.sql.catalyst.expressions.Expression | ||
|
@@ -83,6 +83,45 @@ object ExecutionPlanCaptureCallback { | |
fallbackCpuClassList.foreach(fallbackCpuClass => assertDidFallBack(gpuPlans, fallbackCpuClass)) | ||
} | ||
|
||
/** | ||
* This method is used by the Python integration tests. | ||
* The method checks the schemata used in the GPU and CPU executed plans and compares it to the | ||
* expected schemata to make sure we are not reading more data than needed | ||
*/ | ||
def assertSchemataMatch(cpuDf: DataFrame, gpuDf: DataFrame, expectedSchema: String): Unit = { | ||
import org.apache.spark.sql.execution.FileSourceScanExec | ||
import org.apache.spark.sql.types.StructType | ||
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser | ||
|
||
val adaptiveSparkPlanHelper = ShimLoader.newAdaptiveSparkPlanHelperShim() | ||
val cpuFileSourceScanSchemata = | ||
adaptiveSparkPlanHelper.collect(cpuDf.queryExecution.executedPlan) { | ||
case scan: FileSourceScanExec => scan.requiredSchema | ||
} | ||
val gpuFileSourceScanSchemata = | ||
adaptiveSparkPlanHelper.collect(gpuDf.queryExecution.executedPlan) { | ||
case scan: GpuFileSourceScanExec => scan.requiredSchema | ||
} | ||
assert(cpuFileSourceScanSchemata.size == gpuFileSourceScanSchemata.size, | ||
s"Found ${cpuFileSourceScanSchemata.size} file sources in dataframe, " + | ||
s"but expected ${gpuFileSourceScanSchemata.size}") | ||
|
||
cpuFileSourceScanSchemata.zip(gpuFileSourceScanSchemata).foreach { | ||
case (cpuScanSchema, gpuScanSchema) => | ||
cpuScanSchema match { | ||
case otherType: StructType => | ||
assert(gpuScanSchema.sameType(otherType)) | ||
val expectedStructType = CatalystSqlParser.parseDataType(expectedSchema) | ||
assert(gpuScanSchema.sameType(expectedStructType), | ||
s"Type GPU schema ${gpuScanSchema.toDDL} doesn't match $expectedSchema") | ||
assert(cpuScanSchema.sameType(expectedStructType), | ||
s"Type CPU schema ${cpuScanSchema.toDDL} doesn't match $expectedSchema") | ||
case otherType => assert(false, s"The expected type $cpuScanSchema" + | ||
s" doesn't match the actual type $otherType") | ||
} | ||
} | ||
} | ||
|
||
def assertCapturedAndGpuFellBack(fallbackCpuClass: String, timeoutMs: Long = 2000): Unit = { | ||
val gpuPlans = getResultsWithTimeout(timeoutMs = timeoutMs) | ||
assert(gpuPlans.nonEmpty, "Did not capture a plan") | ||
|
@@ -209,4 +248,8 @@ class ExecutionPlanCaptureCallback extends QueryExecutionListener { | |
|
||
override def onFailure(funcName: String, qe: QueryExecution, exception: Exception): Unit = | ||
captureIfNeeded(qe) | ||
} | ||
|
||
trait AdaptiveSparkPlanHelperShim { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AdaptiveSparkPlanHelperShim.class needs to be added to dist/unshimmed-common-from-spark311.txt. |
||
def collect[B](p: SparkPlan)(pf: PartialFunction[SparkPlan, B]): Seq[B] | ||
} |
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: we can do this already in parametrize
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.
For some reason, pytest doesn't like it when I mark one of the parameters namely
pytest.param(("select name.middle, address from {} where p=2", "struct<name:struct<middle:string>,address:string>"), marks=pytest.mark.skip(reason='https://github.com/NVIDIA/spark-rapids/issues/8788')),
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.
it looks like you are passing a pair to pytest,param, it should be varargs https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest-param