Skip to content
Snippets Groups Projects
Commit 3b68cb04 authored by Michael Armbrust's avatar Michael Armbrust
Browse files

[SPARK-6743] [SQL] Fix empty projections of cached data

Author: Michael Armbrust <michael@databricks.com>

Closes #6165 from marmbrus/wrongColumn and squashes the following commits:

4fad158 [Michael Armbrust] Merge remote-tracking branch 'origin/master' into wrongColumn
aad7eab [Michael Armbrust] rxins comments
f1e8df1 [Michael Armbrust] [SPARK-6743][SQL] Fix empty projections of cached data
parent 4e5220c3
No related branches found
No related tags found
No related merge requests found
......@@ -324,6 +324,7 @@ object Hive {
|import org.apache.spark.sql.functions._
|import org.apache.spark.sql.hive._
|import org.apache.spark.sql.hive.test.TestHive._
|import org.apache.spark.sql.hive.test.TestHive.implicits._
|import org.apache.spark.sql.types._""".stripMargin,
cleanupCommands in console := "sparkContext.stop()",
// Some of our log4j jars make it impossible to submit jobs from this JVM to Hive Map/Reduce
......
......@@ -55,6 +55,9 @@ object Row {
// TODO: Improve the performance of this if used in performance critical part.
new GenericRow(rows.flatMap(_.toSeq).toArray)
}
/** Returns an empty row. */
val empty = apply()
}
......
......@@ -314,7 +314,7 @@ private[sql] case class InMemoryColumnarTableScan(
columnAccessors(i).extractTo(nextRow, i)
i += 1
}
nextRow
if (attributes.isEmpty) Row.empty else nextRow
}
override def hasNext: Boolean = columnAccessors(0).hasNext
......
......@@ -39,6 +39,19 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
import org.apache.spark.sql.test.TestSQLContext.implicits._
val sqlCtx = TestSQLContext
test("SPARK-6743: no columns from cache") {
Seq(
(83, 0, 38),
(26, 0, 79),
(43, 81, 24)
).toDF("a", "b", "c").registerTempTable("cachedData")
cacheTable("cachedData")
checkAnswer(
sql("SELECT t1.b FROM cachedData, cachedData t1 GROUP BY t1.b"),
Row(0) :: Row(81) :: Nil)
}
test("self join with aliases") {
Seq(1,2,3).map(i => (i, i.toString)).toDF("int", "str").registerTempTable("df")
......@@ -142,7 +155,7 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
sql("SELECT ABS(2.5)"),
Row(2.5))
}
test("aggregation with codegen") {
val originalValue = conf.codegenEnabled
setConf(SQLConf.CODEGEN_ENABLED, "true")
......@@ -194,7 +207,7 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
"SELECT value, sum(key) FROM testData3x GROUP BY value",
(1 to 100).map(i => Row(i.toString, 3 * i)))
testCodeGen(
"SELECT sum(key), SUM(CAST(key as Double)) FROM testData3x",
"SELECT sum(key), SUM(CAST(key as Double)) FROM testData3x",
Row(5050 * 3, 5050 * 3.0) :: Nil)
// AVERAGE
testCodeGen(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment