Skip to content

Commit

Permalink
Merge pull request #13 from jingchen2222/feat/support_create_time_index
Browse files Browse the repository at this point in the history
Feat/support create time index
  • Loading branch information
jingchen2222 authored May 25, 2021
2 parents 86e7be0 + 6a76def commit a2436a3
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 27 deletions.
1 change: 1 addition & 0 deletions zetasql/parser/ast_node_kind.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ enum ASTNodeKind {
AST_IMPORT_STATEMENT,
AST_IN_EXPRESSION,
AST_IN_LIST,
AST_INDEX_DEFINITION,
AST_INDEX_ITEM_LIST,
AST_INDEX_STORING_EXPRESSION_LIST,
AST_INDEX_UNNEST_EXPRESSION_LIST,
Expand Down
14 changes: 12 additions & 2 deletions zetasql/parser/bison_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ using zetasql::ASTDropStatement;
%token KW_INTERVAL "INTERVAL"
%token KW_INTO "INTO"
%token KW_IS "IS"
%token KW_INDEX "INDEX"
%token KW_JOIN "JOIN"
%token KW_LAST "LAST"
%token KW_LEFT "LEFT"
Expand Down Expand Up @@ -834,7 +835,6 @@ using zetasql::ASTDropStatement;
%token KW_IMMUTABLE "IMMUTABLE"
%token KW_IMPORT "IMPORT"
%token KW_INCLUDE "INCLUDE"
%token KW_INDEX "INDEX"
%token KW_INOUT "INOUT"
%token KW_INSERT "INSERT"
%token KW_INVOKER "INVOKER"
Expand Down Expand Up @@ -1282,6 +1282,7 @@ using zetasql::ASTDropStatement;
%type <node> table_column_definition
%type <node> table_column_schema
%type <node> table_constraint_definition
%type <node> table_index_definition
%type <node> table_constraint_spec
%type <node> table_element
%type <node> table_element_list
Expand Down Expand Up @@ -2624,9 +2625,18 @@ table_element_list_prefix:
//
table_element:
table_column_definition
| table_index_definition
| table_constraint_definition
;

table_index_definition:
opt_unique "INDEX" opt_identifier options_list /* HybridSE index constraint index(key=(c1),ts=c4,ttl=0m, ttl_type=absolute) */
{
auto* node = MAKE_NODE(ASTIndexDefinition, @$, {$3, nullptr, $4});
node->set_is_unique($1);
$$ = node;
}
;
table_column_definition:
identifier table_column_schema opt_column_attributes opt_options_list
{
Expand Down Expand Up @@ -7070,6 +7080,7 @@ reserved_keyword_rule:
| "INTERVAL"
| "INTO"
| "IS"
| "INDEX"
| "JOIN"
| "LAST"
| "LEFT"
Expand Down Expand Up @@ -7198,7 +7209,6 @@ keyword_as_identifier:
| "IMMUTABLE"
| "IMPORT"
| "INCLUDE"
| "INDEX"
| "INSERT"
| "INOUT"
| "INVOKER"
Expand Down
2 changes: 1 addition & 1 deletion zetasql/parser/keywords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ constexpr KeywordInfoPOD kAllKeywords[] = {
{"in", KW_IN, KeywordInfo::kReserved},
{"include", KW_INCLUDE},
{"inout", KW_INOUT},
{"index", KW_INDEX},
{"index", KW_INDEX, KeywordInfo::kReserved},
{"inner", KW_INNER, KeywordInfo::kReserved},
{"insert", KW_INSERT},
{"instance_not_in_window", KW_INSTANCE_NOT_IN_WINDOW, KeywordInfo::kReserved},
Expand Down
2 changes: 1 addition & 1 deletion zetasql/parser/keywords_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ TEST(ParserTest, DontAddNewReservedKeywords) {
// allows new queries to work that will not work on older code.
// Before changing this, co-ordinate with all engines to make sure the change
// is done safely.
EXPECT_EQ(98 /* CAUTION */, num_reserved);
EXPECT_EQ(99 /* CAUTION */, num_reserved);
}

} // namespace
Expand Down
1 change: 1 addition & 0 deletions zetasql/parser/parse_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ static absl::flat_hash_map<ASTNodeKind, std::string> CreateNodeNamesMap() {
map[AST_IMPORT_STATEMENT] = "ImportStatement";
map[AST_IN_EXPRESSION] = "InExpression";
map[AST_IN_LIST] = "InList";
map[AST_INDEX_DEFINITION] = "IndexDefinition";
map[AST_INDEX_ITEM_LIST] = "IndexItemList";
map[AST_INDEX_STORING_EXPRESSION_LIST] = "IndexStoringExpressionList";
map[AST_INDEX_UNNEST_EXPRESSION_LIST] = "IndexUnnestExpressionList";
Expand Down
32 changes: 30 additions & 2 deletions zetasql/parser/parse_tree_manual.h
Original file line number Diff line number Diff line change
Expand Up @@ -5577,8 +5577,8 @@ class ASTGeneratedColumnInfo final : public ASTNode {
StoredMode stored_mode_ = StoredMode::NON_STORED;
};

// Base class for CREATE TABLE elements, including column definitions and
// table constraints.
// Base class for CREATE TABLE elements, including column definitions,
// table indexs and table constraints.
class ASTTableElement : public ASTNode {
public:
explicit ASTTableElement(ASTNodeKind kind) : ASTNode(kind) {}
Expand Down Expand Up @@ -5703,6 +5703,34 @@ class ASTCheckConstraint final : public ASTTableConstraint {
bool is_enforced_ = true;
};

class ASTIndexDefinition final : public ASTTableElement {
public:
static constexpr ASTNodeKind kConcreteNodeKind = AST_INDEX_DEFINITION;

ASTIndexDefinition() : ASTTableElement(kConcreteNodeKind) {}
void Accept(ParseTreeVisitor* visitor, void* data) const override;
zetasql_base::StatusOr<VisitResult> Accept(
NonRecursiveParseTreeVisitor* visitor) const override;

const ASTIdentifier* name() const { return name_; }
const ASTColumnList* column_key_list() const { return column_key_list_; }
const ASTOptionsList* options_list() const { return options_list_; }

bool is_unique() const { return is_unique_; }
void set_is_unique(bool is_unique) { is_unique_ = is_unique; }
private:
void InitFields() final {
FieldLoader fl(this);
fl.AddOptional(&name_, AST_IDENTIFIER);
fl.AddOptional(&column_key_list_, AST_COLUMN_LIST);
fl.AddOptional(&options_list_, AST_OPTIONS_LIST);
}
const ASTIdentifier* name_ = nullptr;
const ASTColumnList* column_key_list_ = nullptr;
const ASTOptionsList* options_list_ = nullptr;
bool is_unique_ = false;
};

class ASTTableElementList final : public ASTNode {
public:
static constexpr ASTNodeKind kConcreteNodeKind = AST_TABLE_ELEMENT_LIST;
Expand Down
2 changes: 1 addition & 1 deletion zetasql/parser/testdata/create_external_table.test
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ create external table projectid.datasetid.tablename(x int64, y int64)
create external table a.b.c.T()
options ()
--
ERROR: Syntax error: Unexpected ")" [at 1:31]
ERROR: Syntax error: Expected keyword INDEX but got ")" [at 1:31]
create external table a.b.c.T()
^
==
Expand Down
Loading

0 comments on commit a2436a3

Please sign in to comment.