Skip to content

Commit

Permalink
feat: support truncate table statement
Browse files Browse the repository at this point in the history
  • Loading branch information
dl239 committed Oct 8, 2023
1 parent 9190ecf commit e5a777e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cases/plan/cmd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,22 @@ cases:
+-cmd_type: drop function
+-if_exists: true
+-args: [func1]
- id: truncate_stmt
desc: truncate
sql: TRUNCATE TABLE t1;
expect:
node_tree_str: |
+-node[CMD]
+-cmd_type: truncate table
+-args: [t1]
- id: truncate_stmt_db
desc: truncate
sql: TRUNCATE TABLE db1.t1;
expect:
node_tree_str: |
+-node[CMD]
+-cmd_type: truncate table
+-args: [db1, t1]
- id: exit_stmt
desc: exit statement
sql: EXIT;
Expand Down
1 change: 1 addition & 0 deletions hybridse/include/node/node_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ enum CmdType {
kCmdShowFunctions,
kCmdDropFunction,
kCmdShowJobLog,
kCmdTruncate,
kCmdFake, // not a real cmd, for testing purpose only
kLastCmd = kCmdFake,
};
Expand Down
1 change: 1 addition & 0 deletions hybridse/src/node/sql_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static absl::flat_hash_map<CmdType, absl::string_view> CreateCmdTypeNamesMap() {
{CmdType::kCmdDropFunction, "drop function"},
{CmdType::kCmdShowFunctions, "show functions"},
{CmdType::kCmdShowJobLog, "show joblog"},
{CmdType::kCmdTruncate, "truncate table"},
};
for (auto kind = 0; kind < CmdType::kLastCmd; ++kind) {
DCHECK(map.find(static_cast<CmdType>(kind)) != map.end());
Expand Down
10 changes: 10 additions & 0 deletions hybridse/src/planv2/ast_node_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,16 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node
*output = node;
break;
}
case zetasql::AST_TRUNCATE_STATEMENT: {
const zetasql::ASTTruncateStatement* truncate_statement =
statement->GetAsOrNull<zetasql::ASTTruncateStatement>();
std::vector<std::string> names;
CHECK_STATUS(AstPathExpressionToStringList(truncate_statement->target_path(), names));
auto node =
dynamic_cast<node::CmdNode*>(node_manager->MakeCmdNode(node::CmdType::kCmdTruncate, names));
*output = node;
break;
}
case zetasql::AST_DROP_FUNCTION_STATEMENT: {
const zetasql::ASTDropFunctionStatement* drop_fun_statement =
statement->GetAsOrNull<zetasql::ASTDropFunctionStatement>();
Expand Down

0 comments on commit e5a777e

Please sign in to comment.