[SPARK-3907][SQL] Add truncate table support

JIRA issue: [SPARK-3907]https://issues.apache.org/jira/browse/SPARK-3907

Add turncate table support
TRUNCATE TABLE table_name [PARTITION partition_spec];
partition_spec:
  : (partition_col = partition_col_value, partition_col = partiton_col_value, ...)
Removes all rows from a table or partition(s). Currently target table should be native/managed table or exception will be thrown. User can specify partial partition_spec for truncating multiple partitions at once and omitting partition_spec will truncate all partitions in the table.

Author: wangxiaojing <u9jing@gmail.com>

Closes #2770 from wangxiaojing/spark-3907 and squashes the following commits:

63dbd81 [wangxiaojing] change hive scalastyle
7a03707 [wangxiaojing] add comment
f6e710e [wangxiaojing] change truncate table
a1f692c [wangxiaojing] Correct spelling mistakes
3b20007 [wangxiaojing] add truncate can not support column err message
e483547 [wangxiaojing] add golden file
77b1f20 [wangxiaojing]  add truncate table support
This commit is contained in:
wangxiaojing 2014-10-27 22:00:36 -07:00 committed by Michael Armbrust
parent 27470d3406
commit 0c34fa5b4b
29 changed files with 9 additions and 1 deletions

View file

@ -767,6 +767,7 @@ class HiveCompatibilitySuite extends HiveQueryFileTest with BeforeAndAfter {
"touch",
"transform_ppr1",
"transform_ppr2",
"truncate_table",
"type_cast_1",
"type_widening",
"udaf_collect_set",

View file

@ -124,7 +124,8 @@ private[hive] object HiveQl {
// Commands that we do not need to explain.
protected val noExplainCommands = Seq(
"TOK_CREATETABLE",
"TOK_DESCTABLE"
"TOK_DESCTABLE",
"TOK_TRUNCATETABLE" // truncate table" is a NativeCommand, does not need to explain.
) ++ nativeCommands
protected val hqlParser = {
@ -490,6 +491,10 @@ private[hive] object HiveQl {
// If its not a "CREATE TABLE AS" like above then just pass it back to hive as a native command.
case Token("TOK_CREATETABLE", _) => NativePlaceholder
// Support "TRUNCATE TABLE table_name [PARTITION partition_spec]"
case Token("TOK_TRUNCATETABLE",
Token("TOK_TABLE_PARTITION",table)::Nil) => NativePlaceholder
case Token("TOK_QUERY",
Token("TOK_FROM", fromClause :: Nil) ::
insertClauses) =>