Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ private[sql] class DataFrameImpl protected[sql](
def this(sqlContext: SQLContext, logicalPlan: LogicalPlan) = {
this(sqlContext, {
val qe = sqlContext.executePlan(logicalPlan)
qe.analyzed // This should force analysis and throw errors if there are any
if (sqlContext.conf.dataFrameEagerAnalysis) {
qe.analyzed // This should force analysis and throw errors if there are any
}
qe
})
}
Expand Down
6 changes: 6 additions & 0 deletions sql/core/src/main/scala/org/apache/spark/sql/SQLConf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ private[spark] object SQLConf {
// This is used to set the default data source
val DEFAULT_DATA_SOURCE_NAME = "spark.sql.default.datasource"

// Whether to perform eager analysis on a DataFrame.
val DATAFRAME_EAGER_ANALYSIS = "spark.sql.dataframe.eagerAnalysis"

object Deprecated {
val MAPRED_REDUCE_TASKS = "mapred.reduce.tasks"
}
Expand Down Expand Up @@ -173,6 +176,9 @@ private[sql] class SQLConf extends Serializable {
private[spark] def defaultDataSourceName: String =
getConf(DEFAULT_DATA_SOURCE_NAME, "org.apache.spark.sql.parquet")

private[spark] def dataFrameEagerAnalysis: Boolean =
getConf(DATAFRAME_EAGER_ANALYSIS, "true").toBoolean

/** ********************** SQLConf functionality methods ************ */

/** Set Spark SQL configuration properties. */
Expand Down
17 changes: 14 additions & 3 deletions sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@

package org.apache.spark.sql

import scala.language.postfixOps

import org.apache.spark.sql.Dsl._
import org.apache.spark.sql.types._

/* Implicits */
import org.apache.spark.sql.test.TestSQLContext
import org.apache.spark.sql.test.TestSQLContext.logicalPlanToSparkQuery
import org.apache.spark.sql.test.TestSQLContext.implicits._

import scala.language.postfixOps

class DataFrameSuite extends QueryTest {
import org.apache.spark.sql.TestData._

test("analysis error should be eagerly reported") {
val oldSetting = TestSQLContext.conf.dataFrameEagerAnalysis
// Eager analysis.
TestSQLContext.setConf(SQLConf.DATAFRAME_EAGER_ANALYSIS, "true")

intercept[Exception] { testData.select('nonExistentName) }
intercept[Exception] {
testData.groupBy('key).agg(Map("nonExistentName" -> "sum"))
Expand All @@ -40,6 +44,13 @@ class DataFrameSuite extends QueryTest {
intercept[Exception] {
testData.groupBy($"abcd").agg(Map("key" -> "sum"))
}

// No more eager analysis once the flag is turned off
TestSQLContext.setConf(SQLConf.DATAFRAME_EAGER_ANALYSIS, "false")
testData.select('nonExistentName)

// Set the flag back to original value before this test.
TestSQLContext.setConf(SQLConf.DATAFRAME_EAGER_ANALYSIS, oldSetting.toString)
}

test("table scan") {
Expand Down