-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-23195] [SQL] Keep the Hint of Cached Data #20368
Changes from all commits
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 |
---|---|---|
|
@@ -63,7 +63,7 @@ case class InMemoryRelation( | |
tableName: Option[String])( | ||
@transient var _cachedColumnBuffers: RDD[CachedBatch] = null, | ||
val batchStats: LongAccumulator = child.sqlContext.sparkContext.longAccumulator, | ||
statsOfPlanToCache: Statistics = null) | ||
statsOfPlanToCache: Statistics) | ||
extends logical.LeafNode with MultiInstanceRelation { | ||
|
||
override protected def innerChildren: Seq[SparkPlan] = Seq(child) | ||
|
@@ -77,7 +77,7 @@ case class InMemoryRelation( | |
// Underlying columnar RDD hasn't been materialized, use the stats from the plan to cache | ||
statsOfPlanToCache | ||
} else { | ||
Statistics(sizeInBytes = batchStats.value.longValue) | ||
Statistics(sizeInBytes = batchStats.value.longValue, hints = statsOfPlanToCache.hints) | ||
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. Why don't you simply 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. That is misleading. Conceptually, that is wrong. The values should be filled by the actual values from the materialized results. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,22 @@ class BroadcastJoinSuite extends QueryTest with SQLTestUtils { | |
} | ||
} | ||
|
||
test("broadcast hint is retained in a cached plan") { | ||
Seq(true, false).foreach { materialized => | ||
withSQLConf(SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "-1") { | ||
val df1 = spark.createDataFrame(Seq((1, "4"), (2, "2"))).toDF("key", "value") | ||
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. Is 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. That should not matter. |
||
val df2 = spark.createDataFrame(Seq((1, "1"), (2, "2"))).toDF("key", "value") | ||
broadcast(df2).cache() | ||
if (materialized) df2.collect() | ||
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. This PR #19864 accidentally fixes the issue when the plan is not materialized. However, it does not resolve the issue when the cached plan is materialized. |
||
val df3 = df1.join(df2, Seq("key"), "inner") | ||
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.
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. That should not matter. 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. I tend to agree that tests are also examples for Spark users, we should pick the recommended usages. 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. All the other cases are creating Dataframes like this. Anyway, I changed all of them in the new PR. |
||
val numBroadCastHashJoin = df3.queryExecution.executedPlan.collect { | ||
case b: BroadcastHashJoinExec => b | ||
}.size | ||
assert(numBroadCastHashJoin === 1) | ||
} | ||
} | ||
} | ||
|
||
private def assertBroadcastJoin(df : Dataset[Row]) : Unit = { | ||
val df1 = spark.createDataFrame(Seq((1, "4"), (2, "2"))).toDF("key", "value") | ||
val joined = df1.join(df, Seq("key"), "inner") | ||
|
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.
leave no default value is fine, we do not any default value actually
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.
Setting
null
by default is risky, because we might hitNullPointerException
.