-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-1968][SQL] SQL/HiveQL command for caching/uncaching tables #1038
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
15ec6d2
f0ffacc
3458a24
6f4ce42
ecb7194
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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.catalyst.plans.logical | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.{AttributeReference, Attribute} | ||
| import org.apache.spark.sql.catalyst.types.StringType | ||
|
|
||
| /** | ||
| * A logical node that represents a non-query command to be executed by the system. For example, | ||
| * commands can be used by parsers to represent DDL operations. | ||
| */ | ||
| abstract class Command extends LeafNode { | ||
| self: Product => | ||
| def output: Seq[Attribute] = Seq.empty // TODO: SPARK-2081 should fix this | ||
| } | ||
|
|
||
| /** | ||
| * Returned for commands supported by a given parser, but not catalyst. In general these are DDL | ||
| * commands that are passed directly to another system. | ||
| */ | ||
| case class NativeCommand(cmd: String) extends Command | ||
|
|
||
| /** | ||
| * Commands of the form "SET (key) (= value)". | ||
| */ | ||
| case class SetCommand(key: Option[String], value: Option[String]) extends Command { | ||
| override def output = Seq( | ||
| AttributeReference("key", StringType, nullable = false)(), | ||
| AttributeReference("value", StringType, nullable = false)() | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Returned by a parser when the users only wants to see what query plan would be executed, without | ||
| * actually performing the execution. | ||
| */ | ||
| case class ExplainCommand(plan: LogicalPlan) extends Command { | ||
| override def output = Seq(AttributeReference("plan", StringType, nullable = false)()) | ||
| } | ||
|
|
||
| /** | ||
| * Returned for the "CACHE TABLE tableName" and "UNCACHE TABLE tableName" command. | ||
| */ | ||
| case class CacheCommand(tableName: String, doCache: Boolean) extends Command | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,3 +65,26 @@ case class ExplainCommandPhysical(child: SparkPlan, output: Seq[Attribute]) | |
|
|
||
| override def otherCopyArgs = context :: Nil | ||
| } | ||
|
|
||
| /** | ||
| * :: DeveloperApi :: | ||
| */ | ||
| @DeveloperApi | ||
| case class CacheCommandPhysical(tableName: String, doCache: Boolean)(@transient context: SQLContext) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to be updated to some standard command interface in a follow up PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, just as described in SPARK-2094. |
||
| extends LeafNode { | ||
|
|
||
| lazy val commandSideEffect = { | ||
| if (doCache) { | ||
| context.cacheTable(tableName) | ||
| } else { | ||
| context.uncacheTable(tableName) | ||
| } | ||
| } | ||
|
|
||
| override def execute(): RDD[Row] = { | ||
| commandSideEffect | ||
| context.emptyResult | ||
| } | ||
|
|
||
| override def output: Seq[Attribute] = Seq.empty | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,4 +56,20 @@ class CachedTableSuite extends HiveComparisonTest { | |
| TestHive.uncacheTable("src") | ||
| } | ||
| } | ||
|
|
||
| test("'CACHE TABLE' and 'UNCACHE TABLE' HiveQL statement") { | ||
| TestHive.hql("CACHE TABLE src") | ||
| TestHive.table("src").queryExecution.executedPlan match { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, actually it's used below. I left the verbose version here to prevent both |
||
| case _: InMemoryColumnarTableScan => // Found evidence of caching | ||
| case _ => fail(s"Table 'src' should be cached") | ||
| } | ||
| assert(TestHive.isCached("src"), "Table 'src' should be cached") | ||
|
|
||
| TestHive.hql("UNCACHE TABLE src") | ||
| TestHive.table("src").queryExecution.executedPlan match { | ||
| case _: InMemoryColumnarTableScan => fail(s"Table 'src' should not be cached") | ||
| case _ => // Found evidence of uncaching | ||
| } | ||
| assert(!TestHive.isCached("src"), "Table 'src' should not be cached") | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Returns true if the table is currently cached in-memory. */There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.