Skip to content

Commit

Permalink
feat: add optional options for deploy statement (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghaohit authored Feb 21, 2022
1 parent 3963378 commit 4af08ff
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions zetasql/parser/bison_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -8297,9 +8297,9 @@ on_path_expression:
;

deploy_statement:
"DEPLOY" opt_if_not_exists identifier unterminated_sql_statement
"DEPLOY" opt_if_not_exists identifier opt_options_list unterminated_sql_statement
{
auto deploy_stmt = MAKE_NODE(ASTDeployStatement, @$, {$3, $4});
auto deploy_stmt = MAKE_NODE(ASTDeployStatement, @$, {$3, $4, $5});
deploy_stmt->set_is_if_not_exists($2);
$$ = deploy_stmt;
}
Expand Down
3 changes: 3 additions & 0 deletions zetasql/parser/parse_tree_manual.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ class ASTDeployStatement final : public ASTStatement {

const ASTIdentifier* name() const { return name_; }
const ASTStatement* stmt() const { return stmt_; }
const ASTOptionsList* options_list() const { return options_list_; }

bool is_if_not_exists() const { return is_if_not_exists_; }
void set_is_if_not_exists(bool value) { is_if_not_exists_ = value; }
Expand All @@ -663,11 +664,13 @@ class ASTDeployStatement final : public ASTStatement {
void InitFields() final {
FieldLoader fl(this);
fl.AddRequired(&name_);
fl.AddOptional(&options_list_, AST_OPTIONS_LIST);
fl.AddRequired(&stmt_);
}
const ASTIdentifier* name_ = nullptr;
const ASTStatement* stmt_ = nullptr;
bool is_if_not_exists_ = false;
const ASTOptionsList* options_list_ = nullptr;
};

class ASTStopStatement final : public ASTStatement {
Expand Down
21 changes: 21 additions & 0 deletions zetasql/parser/testdata/deploy.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ SELECT
1
==

DEPLOY IF NOT EXISTS data_service_1 OPTIONS(long_windows="w1:100,w2:100s") SELECT 1;
--
DeployStatement [0-83]
Identifier(data_service_1) [21-35]
OptionsList [43-74]
OptionsEntry [44-73]
Identifier(long_windows) [44-56]
StringLiteral("w1:100,w2:100s") [57-73]
QueryStatement [75-83]
Query [75-83]
Select [75-83]
SelectList [82-83]
SelectColumn [82-83]
IntLiteral(1) [82-83]
--
DEPLOY IF NOT EXISTS data_service_1 OPTIONS(long_windows = "w1:100,w2:100s")
SELECT
1
==


DEPLOY deploy create table t1 (a int32, b string);
--
DeployStatement [0-49]
Expand Down
5 changes: 5 additions & 0 deletions zetasql/parser/unparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,11 @@ void Unparser::visitASTDeployStatement(const ASTDeployStatement *node, void *dat
print("IF NOT EXISTS");
}
node->name()->Accept(this, data);

if (node->options_list() != nullptr) {
print("OPTIONS");
node->options_list()->Accept(this, data);
}
node->stmt()->Accept(this, data);
}

Expand Down

0 comments on commit 4af08ff

Please sign in to comment.