-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-25224][SQL] Improvement of Spark SQL ThriftServer memory management #22219
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
7adcb16
1da407f
9b675bd
5f52297
6aa2f65
aa0cb41
c4c2177
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ import java.util.{Arrays, Map => JMap, UUID} | |
import java.util.concurrent.RejectedExecutionException | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.collection.SeqView | ||
import scala.collection.mutable.ArrayBuffer | ||
import scala.util.control.NonFatal | ||
|
||
|
@@ -35,6 +36,7 @@ import org.apache.hive.service.cli.session.HiveSession | |
import org.apache.spark.SparkContext | ||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.sql.{DataFrame, Row => SparkRow, SQLContext} | ||
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateSafeProjection | ||
import org.apache.spark.sql.execution.HiveResult | ||
import org.apache.spark.sql.execution.command.SetCommand | ||
import org.apache.spark.sql.internal.SQLConf | ||
|
@@ -55,7 +57,7 @@ private[hive] class SparkExecuteStatementOperation( | |
// We cache the returned rows to get iterators again in case the user wants to use FETCH_FIRST. | ||
// This is only used when `spark.sql.thriftServer.incrementalCollect` is set to `false`. | ||
// In case of `true`, this will be `None` and FETCH_FIRST will trigger re-execution. | ||
private var resultList: Option[Array[SparkRow]] = _ | ||
private var resultList: Option[Seq[SparkRow]] = _ | ||
|
||
private var iter: Iterator[SparkRow] = _ | ||
private var dataTypes: Array[DataType] = _ | ||
|
@@ -122,7 +124,12 @@ private[hive] class SparkExecuteStatementOperation( | |
result.toLocalIterator.asScala | ||
} else { | ||
if (resultList.isEmpty) { | ||
resultList = Some(result.collect()) | ||
|
||
resultList = if (sqlContext.getConf( | ||
SQLConf.THRIFTSERVER_INCREMENTAL_DESERIALIZE.key).toBoolean) { | ||
Some(result.collectAsSeqView()) | ||
} else { | ||
Some(result.collect()) | ||
} | ||
} | ||
resultList.get.iterator | ||
} | ||
|
@@ -245,7 +252,12 @@ private[hive] class SparkExecuteStatementOperation( | |
resultList = None | ||
result.toLocalIterator.asScala | ||
} else { | ||
resultList = Some(result.collect()) | ||
resultList = if (sqlContext.getConf( | ||
SQLConf.THRIFTSERVER_INCREMENTAL_DESERIALIZE.key).toBoolean) { | ||
Some(result.collectAsSeqView()) | ||
} else { | ||
Some(result.collect()) | ||
} | ||
resultList.get.iterator | ||
} | ||
} | ||
|
@@ -291,6 +303,23 @@ private[hive] class SparkExecuteStatementOperation( | |
sqlContext.sparkContext.cancelJobGroup(statementId) | ||
} | ||
} | ||
|
||
private implicit class DataFrameWrapper(df: DataFrame) { | ||
/** | ||
* Returns a SeqView that contains all rows in this Dataset. | ||
* | ||
* The SeqView will consume as much memory as the total size of serialized results which can be | ||
* limited with the config 'spark.driver.maxResultSize'. Rows are deserialized when iterating | ||
* rows with iterator of returned SeqView. | ||
*/ | ||
def collectAsSeqView(): SeqView[SparkRow, Array[SparkRow]] = | ||
df.withAction("collectAsSeqView", df.queryExecution) { plan => | ||
val objProj = GenerateSafeProjection.generate(df.deserializer :: Nil) | ||
plan.executeCollectSeqView().map(row => | ||
objProj(row).get(0, null).asInstanceOf[SparkRow] | ||
).asInstanceOf[SeqView[SparkRow, Array[SparkRow]]] | ||
} | ||
} | ||
} | ||
|
||
object SparkExecuteStatementOperation { | ||
|
Uh oh!
There was an error while loading. Please reload this page.