-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-11009] [SQL] fix wrong result of Window function in cluster mode #9050
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
Changes from all commits
35b7b22
39b99b8
2d55882
bc566fa
153140a
89c1401
3aec389
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import org.scalatest.time.SpanSugar._ | |
|
|
||
| import org.apache.spark._ | ||
| import org.apache.spark.sql.{SQLContext, QueryTest} | ||
| import org.apache.spark.sql.expressions.Window | ||
| import org.apache.spark.sql.hive.test.{TestHive, TestHiveContext} | ||
| import org.apache.spark.sql.test.ProcessTestUtils.ProcessOutputCapturer | ||
| import org.apache.spark.sql.types.DecimalType | ||
|
|
@@ -107,6 +108,16 @@ class HiveSparkSubmitSuite | |
| runSparkSubmit(args) | ||
| } | ||
|
|
||
| test("SPARK-11009 fix wrong result of Window function in cluster mode") { | ||
| val unusedJar = TestUtils.createJarWithClasses(Seq.empty) | ||
| val args = Seq( | ||
| "--class", SPARK_11009.getClass.getName.stripSuffix("$"), | ||
| "--name", "SparkSQLConfTest", | ||
| "--master", "local-cluster[2,1,1024]", | ||
| unusedJar.toString) | ||
| runSparkSubmit(args) | ||
| } | ||
|
|
||
| // NOTE: This is an expensive operation in terms of time (10 seconds+). Use sparingly. | ||
| // This is copied from org.apache.spark.deploy.SparkSubmitSuite | ||
| private def runSparkSubmit(args: Seq[String]): Unit = { | ||
|
|
@@ -320,3 +331,31 @@ object SPARK_9757 extends QueryTest { | |
| } | ||
| } | ||
| } | ||
|
|
||
| object SPARK_11009 extends QueryTest { | ||
| import org.apache.spark.sql.functions._ | ||
|
|
||
| protected var sqlContext: SQLContext = _ | ||
|
|
||
| def main(args: Array[String]): Unit = { | ||
| Utils.configTestLog4j("INFO") | ||
|
|
||
| val sparkContext = new SparkContext( | ||
| new SparkConf() | ||
| .set("spark.ui.enabled", "false") | ||
| .set("spark.sql.shuffle.partitions", "100")) | ||
|
|
||
| val hiveContext = new TestHiveContext(sparkContext) | ||
| sqlContext = hiveContext | ||
|
|
||
| try { | ||
| val df = sqlContext.range(1 << 20) | ||
| val df2 = df.select((df("id") % 1000).alias("A"), (df("id") / 1000).alias("B")) | ||
| val ws = Window.partitionBy(df2("A")).orderBy(df2("B")) | ||
| val df3 = df2.select(df2("A"), df2("B"), rowNumber().over(ws).alias("rn")).filter("rn < 0") | ||
| assert(df3.rdd.count() === 0) | ||
|
Contributor
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. We have to throw an exception at here. Otherwise, even this assertion fails, the test will pass (because we are running an application at here).
Contributor
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. Will fix it while I merging it. |
||
| } finally { | ||
| sparkContext.stop() | ||
| } | ||
| } | ||
| } | ||
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.
Is it true that the input row of this projection has more elements than
child.output? Maybe it is not very easy to understand this subtle change?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.
Currently, we put all the
windowResulton the right side ofchild.output, patchedWindowExpression will be pointed to them.