Skip to content

Commit df97df2

Browse files
committed
[SPARK-11644][SQL] Remove the option to turn off unsafe and codegen.
Author: Reynold Xin <[email protected]> Closes #9618 from rxin/SPARK-11644.
1 parent 27029bc commit df97df2

27 files changed

+257
-494
lines changed

sql/core/src/main/scala/org/apache/spark/sql/SQLConf.scala

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -252,24 +252,8 @@ private[spark] object SQLConf {
252252
"not be provided to ExchangeCoordinator.",
253253
isPublic = false)
254254

255-
val TUNGSTEN_ENABLED = booleanConf("spark.sql.tungsten.enabled",
256-
defaultValue = Some(true),
257-
doc = "When true, use the optimized Tungsten physical execution backend which explicitly " +
258-
"manages memory and dynamically generates bytecode for expression evaluation.")
259-
260-
val CODEGEN_ENABLED = booleanConf("spark.sql.codegen",
261-
defaultValue = Some(true), // use TUNGSTEN_ENABLED as default
262-
doc = "When true, code will be dynamically generated at runtime for expression evaluation in" +
263-
" a specific query.",
264-
isPublic = false)
265-
266-
val UNSAFE_ENABLED = booleanConf("spark.sql.unsafe.enabled",
267-
defaultValue = Some(true), // use TUNGSTEN_ENABLED as default
268-
doc = "When true, use the new optimized Tungsten physical execution backend.",
269-
isPublic = false)
270-
271255
val SUBEXPRESSION_ELIMINATION_ENABLED = booleanConf("spark.sql.subexpressionElimination.enabled",
272-
defaultValue = Some(true), // use CODEGEN_ENABLED as default
256+
defaultValue = Some(true),
273257
doc = "When true, common subexpressions will be eliminated.",
274258
isPublic = false)
275259

@@ -475,6 +459,9 @@ private[spark] object SQLConf {
475459
val MAPRED_REDUCE_TASKS = "mapred.reduce.tasks"
476460
val EXTERNAL_SORT = "spark.sql.planner.externalSort"
477461
val USE_SQL_AGGREGATE2 = "spark.sql.useAggregate2"
462+
val TUNGSTEN_ENABLED = "spark.sql.tungsten.enabled"
463+
val CODEGEN_ENABLED = "spark.sql.codegen"
464+
val UNSAFE_ENABLED = "spark.sql.unsafe.enabled"
478465
}
479466
}
480467

@@ -541,14 +528,10 @@ private[sql] class SQLConf extends Serializable with CatalystConf {
541528

542529
private[spark] def sortMergeJoinEnabled: Boolean = getConf(SORTMERGE_JOIN)
543530

544-
private[spark] def codegenEnabled: Boolean = getConf(CODEGEN_ENABLED, getConf(TUNGSTEN_ENABLED))
545-
546531
def caseSensitiveAnalysis: Boolean = getConf(SQLConf.CASE_SENSITIVE)
547532

548-
private[spark] def unsafeEnabled: Boolean = getConf(UNSAFE_ENABLED, getConf(TUNGSTEN_ENABLED))
549-
550533
private[spark] def subexpressionEliminationEnabled: Boolean =
551-
getConf(SUBEXPRESSION_ELIMINATION_ENABLED, codegenEnabled)
534+
getConf(SUBEXPRESSION_ELIMINATION_ENABLED)
552535

553536
private[spark] def autoBroadcastJoinThreshold: Int = getConf(AUTO_BROADCASTJOIN_THRESHOLD)
554537

sql/core/src/main/scala/org/apache/spark/sql/execution/Exchange.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ case class Exchange(
5858
* Returns true iff we can support the data type, and we are not doing range partitioning.
5959
*/
6060
private lazy val tungstenMode: Boolean = {
61-
unsafeEnabled && codegenEnabled && GenerateUnsafeProjection.canSupport(child.schema) &&
61+
GenerateUnsafeProjection.canSupport(child.schema) &&
6262
!newPartitioning.isInstanceOf[RangePartitioning]
6363
}
6464

sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class QueryExecution(val sqlContext: SQLContext, val logical: LogicalPlan) {
7777
|${stringOrError(optimizedPlan)}
7878
|== Physical Plan ==
7979
|${stringOrError(executedPlan)}
80-
|Code Generation: ${stringOrError(executedPlan.codegenEnabled)}
8180
""".stripMargin.trim
8281
}
8382
}

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala

Lines changed: 45 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,8 @@ abstract class SparkPlan extends QueryPlan[SparkPlan] with Logging with Serializ
5454
protected def sparkContext = sqlContext.sparkContext
5555

5656
// sqlContext will be null when we are being deserialized on the slaves. In this instance
57-
// the value of codegenEnabled/unsafeEnabled will be set by the desserializer after the
57+
// the value of subexpressionEliminationEnabled will be set by the desserializer after the
5858
// constructor has run.
59-
val codegenEnabled: Boolean = if (sqlContext != null) {
60-
sqlContext.conf.codegenEnabled
61-
} else {
62-
false
63-
}
64-
val unsafeEnabled: Boolean = if (sqlContext != null) {
65-
sqlContext.conf.unsafeEnabled
66-
} else {
67-
false
68-
}
6959
val subexpressionEliminationEnabled: Boolean = if (sqlContext != null) {
7060
sqlContext.conf.subexpressionEliminationEnabled
7161
} else {
@@ -233,83 +223,63 @@ abstract class SparkPlan extends QueryPlan[SparkPlan] with Logging with Serializ
233223

234224
protected def newProjection(
235225
expressions: Seq[Expression], inputSchema: Seq[Attribute]): Projection = {
236-
log.debug(
237-
s"Creating Projection: $expressions, inputSchema: $inputSchema, codegen:$codegenEnabled")
238-
if (codegenEnabled) {
239-
try {
240-
GenerateProjection.generate(expressions, inputSchema)
241-
} catch {
242-
case e: Exception =>
243-
if (isTesting) {
244-
throw e
245-
} else {
246-
log.error("Failed to generate projection, fallback to interpret", e)
247-
new InterpretedProjection(expressions, inputSchema)
248-
}
249-
}
250-
} else {
251-
new InterpretedProjection(expressions, inputSchema)
226+
log.debug(s"Creating Projection: $expressions, inputSchema: $inputSchema")
227+
try {
228+
GenerateProjection.generate(expressions, inputSchema)
229+
} catch {
230+
case e: Exception =>
231+
if (isTesting) {
232+
throw e
233+
} else {
234+
log.error("Failed to generate projection, fallback to interpret", e)
235+
new InterpretedProjection(expressions, inputSchema)
236+
}
252237
}
253238
}
254239

255240
protected def newMutableProjection(
256-
expressions: Seq[Expression],
257-
inputSchema: Seq[Attribute]): () => MutableProjection = {
258-
log.debug(
259-
s"Creating MutableProj: $expressions, inputSchema: $inputSchema, codegen:$codegenEnabled")
260-
if(codegenEnabled) {
261-
try {
262-
GenerateMutableProjection.generate(expressions, inputSchema)
263-
} catch {
264-
case e: Exception =>
265-
if (isTesting) {
266-
throw e
267-
} else {
268-
log.error("Failed to generate mutable projection, fallback to interpreted", e)
269-
() => new InterpretedMutableProjection(expressions, inputSchema)
270-
}
271-
}
272-
} else {
273-
() => new InterpretedMutableProjection(expressions, inputSchema)
241+
expressions: Seq[Expression], inputSchema: Seq[Attribute]): () => MutableProjection = {
242+
log.debug(s"Creating MutableProj: $expressions, inputSchema: $inputSchema")
243+
try {
244+
GenerateMutableProjection.generate(expressions, inputSchema)
245+
} catch {
246+
case e: Exception =>
247+
if (isTesting) {
248+
throw e
249+
} else {
250+
log.error("Failed to generate mutable projection, fallback to interpreted", e)
251+
() => new InterpretedMutableProjection(expressions, inputSchema)
252+
}
274253
}
275254
}
276255

277256
protected def newPredicate(
278257
expression: Expression, inputSchema: Seq[Attribute]): (InternalRow) => Boolean = {
279-
if (codegenEnabled) {
280-
try {
281-
GeneratePredicate.generate(expression, inputSchema)
282-
} catch {
283-
case e: Exception =>
284-
if (isTesting) {
285-
throw e
286-
} else {
287-
log.error("Failed to generate predicate, fallback to interpreted", e)
288-
InterpretedPredicate.create(expression, inputSchema)
289-
}
290-
}
291-
} else {
292-
InterpretedPredicate.create(expression, inputSchema)
258+
try {
259+
GeneratePredicate.generate(expression, inputSchema)
260+
} catch {
261+
case e: Exception =>
262+
if (isTesting) {
263+
throw e
264+
} else {
265+
log.error("Failed to generate predicate, fallback to interpreted", e)
266+
InterpretedPredicate.create(expression, inputSchema)
267+
}
293268
}
294269
}
295270

296271
protected def newOrdering(
297-
order: Seq[SortOrder],
298-
inputSchema: Seq[Attribute]): Ordering[InternalRow] = {
299-
if (codegenEnabled) {
300-
try {
301-
GenerateOrdering.generate(order, inputSchema)
302-
} catch {
303-
case e: Exception =>
304-
if (isTesting) {
305-
throw e
306-
} else {
307-
log.error("Failed to generate ordering, fallback to interpreted", e)
308-
new InterpretedOrdering(order, inputSchema)
309-
}
310-
}
311-
} else {
312-
new InterpretedOrdering(order, inputSchema)
272+
order: Seq[SortOrder], inputSchema: Seq[Attribute]): Ordering[InternalRow] = {
273+
try {
274+
GenerateOrdering.generate(order, inputSchema)
275+
} catch {
276+
case e: Exception =>
277+
if (isTesting) {
278+
throw e
279+
} else {
280+
log.error("Failed to generate ordering, fallback to interpreted", e)
281+
new InterpretedOrdering(order, inputSchema)
282+
}
313283
}
314284
}
315285
/**

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlanner.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ import org.apache.spark.sql.execution.datasources.DataSourceStrategy
2727
class SparkPlanner(val sqlContext: SQLContext) extends SparkStrategies {
2828
val sparkContext: SparkContext = sqlContext.sparkContext
2929

30-
def codegenEnabled: Boolean = sqlContext.conf.codegenEnabled
31-
32-
def unsafeEnabled: Boolean = sqlContext.conf.unsafeEnabled
33-
3430
def numPartitions: Int = sqlContext.conf.numShufflePartitions
3531

3632
def strategies: Seq[Strategy] =

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] {
327327
* if necessary.
328328
*/
329329
def getSortOperator(sortExprs: Seq[SortOrder], global: Boolean, child: SparkPlan): SparkPlan = {
330-
if (sqlContext.conf.unsafeEnabled && sqlContext.conf.codegenEnabled &&
331-
TungstenSort.supportsSchema(child.schema)) {
330+
if (TungstenSort.supportsSchema(child.schema)) {
332331
execution.TungstenSort(sortExprs, global, child)
333332
} else {
334333
execution.Sort(sortExprs, global, child)
@@ -368,8 +367,7 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] {
368367
case logical.Project(projectList, child) =>
369368
// If unsafe mode is enabled and we support these data types in Unsafe, use the
370369
// Tungsten project. Otherwise, use the normal project.
371-
if (sqlContext.conf.unsafeEnabled &&
372-
UnsafeProjection.canSupport(projectList) && UnsafeProjection.canSupport(child.schema)) {
370+
if (UnsafeProjection.canSupport(projectList) && UnsafeProjection.canSupport(child.schema)) {
373371
execution.TungstenProject(projectList, planLater(child)) :: Nil
374372
} else {
375373
execution.Project(projectList, planLater(child)) :: Nil

sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/utils.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,10 @@ object Utils {
5959
resultExpressions: Seq[NamedExpression],
6060
child: SparkPlan): Seq[SparkPlan] = {
6161
// Check if we can use TungstenAggregate.
62-
val usesTungstenAggregate =
63-
child.sqlContext.conf.unsafeEnabled &&
64-
TungstenAggregate.supportsAggregate(
62+
val usesTungstenAggregate = TungstenAggregate.supportsAggregate(
6563
groupingExpressions,
6664
aggregateExpressions.flatMap(_.aggregateFunction.aggBufferAttributes))
6765

68-
6966
// 1. Create an Aggregate Operator for partial aggregations.
7067

7168
val groupingAttributes = groupingExpressions.map(_.toAttribute)
@@ -144,11 +141,9 @@ object Utils {
144141
child: SparkPlan): Seq[SparkPlan] = {
145142

146143
val aggregateExpressions = functionsWithDistinct ++ functionsWithoutDistinct
147-
val usesTungstenAggregate =
148-
child.sqlContext.conf.unsafeEnabled &&
149-
TungstenAggregate.supportsAggregate(
150-
groupingExpressions,
151-
aggregateExpressions.flatMap(_.aggregateFunction.aggBufferAttributes))
144+
val usesTungstenAggregate = TungstenAggregate.supportsAggregate(
145+
groupingExpressions,
146+
aggregateExpressions.flatMap(_.aggregateFunction.aggBufferAttributes))
152147

153148
// functionsWithDistinct is guaranteed to be non-empty. Even though it may contain more than one
154149
// DISTINCT aggregate function, all of those functions will have the same column expression.

sql/core/src/main/scala/org/apache/spark/sql/execution/commands.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,33 @@ case class SetCommand(kv: Option[(String, Option[String])]) extends RunnableComm
121121
}
122122
(keyValueOutput, runFunc)
123123

124+
case Some((SQLConf.Deprecated.TUNGSTEN_ENABLED, Some(value))) =>
125+
val runFunc = (sqlContext: SQLContext) => {
126+
logWarning(
127+
s"Property ${SQLConf.Deprecated.TUNGSTEN_ENABLED} is deprecated and " +
128+
s"will be ignored. Tungsten will continue to be used.")
129+
Seq(Row(SQLConf.Deprecated.TUNGSTEN_ENABLED, "true"))
130+
}
131+
(keyValueOutput, runFunc)
132+
133+
case Some((SQLConf.Deprecated.CODEGEN_ENABLED, Some(value))) =>
134+
val runFunc = (sqlContext: SQLContext) => {
135+
logWarning(
136+
s"Property ${SQLConf.Deprecated.CODEGEN_ENABLED} is deprecated and " +
137+
s"will be ignored. Codegen will continue to be used.")
138+
Seq(Row(SQLConf.Deprecated.CODEGEN_ENABLED, "true"))
139+
}
140+
(keyValueOutput, runFunc)
141+
142+
case Some((SQLConf.Deprecated.UNSAFE_ENABLED, Some(value))) =>
143+
val runFunc = (sqlContext: SQLContext) => {
144+
logWarning(
145+
s"Property ${SQLConf.Deprecated.UNSAFE_ENABLED} is deprecated and " +
146+
s"will be ignored. Unsafe mode will continue to be used.")
147+
Seq(Row(SQLConf.Deprecated.UNSAFE_ENABLED, "true"))
148+
}
149+
(keyValueOutput, runFunc)
150+
124151
// Configures a single property.
125152
case Some((key, Some(value))) =>
126153
val runFunc = (sqlContext: SQLContext) => {

sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashJoin.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ trait HashJoin {
4545
override def output: Seq[Attribute] = left.output ++ right.output
4646

4747
protected[this] def isUnsafeMode: Boolean = {
48-
(self.codegenEnabled && self.unsafeEnabled
49-
&& UnsafeProjection.canSupport(buildKeys)
50-
&& UnsafeProjection.canSupport(self.schema))
48+
UnsafeProjection.canSupport(buildKeys) && UnsafeProjection.canSupport(self.schema)
5149
}
5250

5351
override def outputsUnsafeRows: Boolean = isUnsafeMode

sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashOuterJoin.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ trait HashOuterJoin {
6565
}
6666

6767
protected[this] def isUnsafeMode: Boolean = {
68-
(self.codegenEnabled && self.unsafeEnabled && joinType != FullOuter
69-
&& UnsafeProjection.canSupport(buildKeys)
70-
&& UnsafeProjection.canSupport(self.schema))
68+
joinType != FullOuter &&
69+
UnsafeProjection.canSupport(buildKeys) &&
70+
UnsafeProjection.canSupport(self.schema)
7171
}
7272

7373
override def outputsUnsafeRows: Boolean = isUnsafeMode

0 commit comments

Comments
 (0)