forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SQL] SPARK-1372 Support for caching and uncaching tables in a SQLCon…
…text. This doesn't yet support different databases in Hive (though you can probably workaround this by calling `USE <dbname>`). However, given the time constraints for 1.0 I think its probably worth including this now and extending the functionality in the next release. Author: Michael Armbrust <[email protected]> Closes apache#282 from marmbrus/cacheTables and squashes the following commits: 83785db [Michael Armbrust] Support for caching and uncaching tables in a SQLContext.
- Loading branch information
Showing
7 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
sql/core/src/test/scala/org/apache/spark/sql/CachedTableSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql | ||
|
||
import org.scalatest.FunSuite | ||
import org.apache.spark.sql.TestData._ | ||
import org.apache.spark.sql.test.TestSQLContext | ||
import org.apache.spark.sql.execution.SparkLogicalPlan | ||
import org.apache.spark.sql.columnar.InMemoryColumnarTableScan | ||
|
||
class CachedTableSuite extends QueryTest { | ||
TestData // Load test tables. | ||
|
||
test("read from cached table and uncache") { | ||
TestSQLContext.cacheTable("testData") | ||
|
||
checkAnswer( | ||
TestSQLContext.table("testData"), | ||
testData.collect().toSeq | ||
) | ||
|
||
TestSQLContext.table("testData").queryExecution.analyzed match { | ||
case SparkLogicalPlan(_ : InMemoryColumnarTableScan) => // Found evidence of caching | ||
case noCache => fail(s"No cache node found in plan $noCache") | ||
} | ||
|
||
TestSQLContext.uncacheTable("testData") | ||
|
||
checkAnswer( | ||
TestSQLContext.table("testData"), | ||
testData.collect().toSeq | ||
) | ||
|
||
TestSQLContext.table("testData").queryExecution.analyzed match { | ||
case cachePlan @ SparkLogicalPlan(_ : InMemoryColumnarTableScan) => | ||
fail(s"Table still cached after uncache: $cachePlan") | ||
case noCache => // Table uncached successfully | ||
} | ||
} | ||
|
||
test("correct error on uncache of non-cached table") { | ||
intercept[IllegalArgumentException] { | ||
TestSQLContext.uncacheTable("testData") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
sql/hive/src/test/resources/golden/read from cached table-0-ce3797dc14a603cba2a5e58c8612de5b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
238 val_238 |
1 change: 1 addition & 0 deletions
1
...ive/src/test/resources/golden/read from uncached table-0-ce3797dc14a603cba2a5e58c8612de5b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
238 val_238 |
58 changes: 58 additions & 0 deletions
58
sql/hive/src/test/scala/org/apache/spark/sql/hive/CachedTableSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.hive | ||
|
||
import org.apache.spark.sql.execution.SparkLogicalPlan | ||
import org.apache.spark.sql.columnar.InMemoryColumnarTableScan | ||
import org.apache.spark.sql.hive.execution.HiveComparisonTest | ||
|
||
class CachedTableSuite extends HiveComparisonTest { | ||
TestHive.loadTestTable("src") | ||
|
||
test("cache table") { | ||
TestHive.cacheTable("src") | ||
} | ||
|
||
createQueryTest("read from cached table", | ||
"SELECT * FROM src LIMIT 1") | ||
|
||
test("check that table is cached and uncache") { | ||
TestHive.table("src").queryExecution.analyzed match { | ||
case SparkLogicalPlan(_ : InMemoryColumnarTableScan) => // Found evidence of caching | ||
case noCache => fail(s"No cache node found in plan $noCache") | ||
} | ||
TestHive.uncacheTable("src") | ||
} | ||
|
||
createQueryTest("read from uncached table", | ||
"SELECT * FROM src LIMIT 1") | ||
|
||
test("make sure table is uncached") { | ||
TestHive.table("src").queryExecution.analyzed match { | ||
case cachePlan @ SparkLogicalPlan(_ : InMemoryColumnarTableScan) => | ||
fail(s"Table still cached after uncache: $cachePlan") | ||
case noCache => // Table uncached successfully | ||
} | ||
} | ||
|
||
test("correct error on uncache of non-cached table") { | ||
intercept[IllegalArgumentException] { | ||
TestHive.uncacheTable("src") | ||
} | ||
} | ||
} |