-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24373][SQL] Add AnalysisBarrier to RelationalGroupedDataset's and KeyValueGroupedDataset's child #21432
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
+104
−8
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
fix also KeyValueGroupedDataset and other methods
- Loading branch information
commit e2132c9a45551e834228ebcf0b7fb51ce4df8f6c
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
98 changes: 98 additions & 0 deletions
98
sql/core/src/test/scala/org/apache/spark/sql/GroupedDatasetSuite.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,98 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import org.scalatest.Assertion | ||
|
|
||
| import org.apache.spark.api.python.PythonEvalType | ||
| import org.apache.spark.sql.catalyst.expressions.PythonUDF | ||
| import org.apache.spark.sql.catalyst.plans.logical.AnalysisBarrier | ||
| import org.apache.spark.sql.functions.udf | ||
| import org.apache.spark.sql.test.SharedSQLContext | ||
| import org.apache.spark.sql.types.{LongType, StructField, StructType} | ||
|
|
||
| class GroupedDatasetSuite extends QueryTest with SharedSQLContext { | ||
| import testImplicits._ | ||
|
|
||
| private val scalaUDF = udf((x: Long) => { x + 1 }) | ||
| private lazy val datasetWithUDF = spark.range(1).toDF("s").select($"s", scalaUDF($"s")) | ||
|
|
||
| private def assertContainsAnalysisBarrier(ds: Dataset[_], atLevel: Int = 1): Assertion = { | ||
| assert(atLevel >= 0) | ||
| var children = Seq(ds.queryExecution.logical) | ||
| (1 to atLevel).foreach { _ => | ||
| children = children.flatMap(_.children) | ||
| } | ||
| val barriers = children.collect { | ||
| case ab: AnalysisBarrier => ab | ||
| } | ||
| assert(barriers.nonEmpty, s"Plan does not contain AnalysisBarrier at level $atLevel:\n" + | ||
| ds.queryExecution.logical) | ||
| } | ||
|
|
||
| test("SPARK-24373: avoid running Analyzer rules twice on RelationalGroupedDataset") { | ||
| val groupByDataset = datasetWithUDF.groupBy() | ||
| val rollupDataset = datasetWithUDF.rollup("s") | ||
| val cubeDataset = datasetWithUDF.cube("s") | ||
| val pivotDataset = datasetWithUDF.groupBy().pivot("s", Seq(1, 2)) | ||
| datasetWithUDF.cache() | ||
| Seq(groupByDataset, rollupDataset, cubeDataset, pivotDataset).foreach { rgDS => | ||
| val df = rgDS.count() | ||
| assertContainsAnalysisBarrier(df) | ||
| assertCached(df) | ||
| } | ||
|
|
||
| val flatMapGroupsInRDF = datasetWithUDF.groupBy().flatMapGroupsInR( | ||
| Array.emptyByteArray, | ||
| Array.emptyByteArray, | ||
| Array.empty, | ||
| StructType(Seq(StructField("s", LongType)))) | ||
| val flatMapGroupsInPandasDF = datasetWithUDF.groupBy().flatMapGroupsInPandas(PythonUDF( | ||
| "pyUDF", | ||
| null, | ||
| StructType(Seq(StructField("s", LongType))), | ||
| Seq.empty, | ||
| PythonEvalType.SQL_GROUPED_MAP_PANDAS_UDF, | ||
| true)) | ||
| Seq(flatMapGroupsInRDF, flatMapGroupsInPandasDF).foreach { df => | ||
| assertContainsAnalysisBarrier(df, 2) | ||
| assertCached(df) | ||
| } | ||
| datasetWithUDF.unpersist(true) | ||
| } | ||
|
|
||
| test("SPARK-24373: avoid running Analyzer rules twice on KeyValueGroupedDataset") { | ||
| val kvDasaset = datasetWithUDF.groupByKey(_.getLong(0)) | ||
| datasetWithUDF.cache() | ||
| val mapValuesKVDataset = kvDasaset.mapValues(_.getLong(0)).reduceGroups(_ + _) | ||
| val keysKVDataset = kvDasaset.keys | ||
| val flatMapGroupsKVDataset = kvDasaset.flatMapGroups((k, _) => Seq(k)) | ||
| val aggKVDataset = kvDasaset.count() | ||
| val otherKVDataset = spark.range(1).groupByKey(_ + 1) | ||
| val cogroupKVDataset = kvDasaset.cogroup(otherKVDataset)((k, _, _) => Seq(k)) | ||
| Seq((mapValuesKVDataset, 1), | ||
| (keysKVDataset, 2), | ||
| (flatMapGroupsKVDataset, 2), | ||
| (aggKVDataset, 1), | ||
| (cogroupKVDataset, 2)).foreach { case (df, analysisBarrierDepth) => | ||
| assertContainsAnalysisBarrier(df, analysisBarrierDepth) | ||
| assertCached(df) | ||
| } | ||
| datasetWithUDF.unpersist(true) | ||
| } | ||
| } | ||
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
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.
withinLevel? From the test code, seems it doesn't expect a barrier exactly at the level but within the level?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.
Indeed, it expects a barrier exactly at level
atLeveland not within. May you please recheck the code?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.
Oh, I see. Sorry, you only take
childrenat the level. Thanks.Uh oh!
There was an error while loading. Please reload this page.
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: Is the returned
Assertionhere necessary?