Commit ab8570f9 authored by unknown's avatar unknown
Browse files

merge1

No related merge requests found
Showing with 118 additions and 6 deletions
+118 -6
......@@ -22,7 +22,7 @@ using namespace ast;
// keywords
%token SHOW TABLES CREATE TABLE DROP DESC INSERT INTO VALUES DELETE FROM ASC ORDER BY
WHERE UPDATE SET SELECT INT CHAR FLOAT INDEX AND JOIN EXIT HELP TXN_BEGIN TXN_COMMIT TXN_ABORT TXN_ROLLBACK ORDER_BY ENABLE_NESTLOOP ENABLE_SORTMERGE
WHERE UPDATE SET SELECT INT CHAR FLOAT INDEX AND JOIN EXIT HELP TXN_BEGIN TXN_COMMIT TXN_ABORT TXN_ROLLBACK ORDER_BY ENABLE_NESTLOOP ENABLE_SORTMERGE COUNT SUM MAX MIN AS GROUPBY HAVING
// non-keywords
%token LEQ NEQ GEQ T_EOF
......@@ -41,7 +41,7 @@ WHERE UPDATE SET SELECT INT CHAR FLOAT INDEX AND JOIN EXIT HELP TXN_BEGIN TXN_CO
%type <sv_expr> expr
%type <sv_val> value
%type <sv_vals> valueList
%type <sv_str> tbName colName
%type <sv_str> tbName colName otherName
%type <sv_strs> tableList colNameList
%type <sv_col> col
%type <sv_cols> colList selector
......@@ -52,7 +52,13 @@ WHERE UPDATE SET SELECT INT CHAR FLOAT INDEX AND JOIN EXIT HELP TXN_BEGIN TXN_CO
%type <sv_orderby> order_clause opt_order_clause
%type <sv_orderby_dir> opt_asc_desc
%type <sv_setKnobType> set_knob_type
%type <sv_target> target
%type <sv_aggregates> aggregates
%type <sv_aggregate> aggregate
%type <sv_aggregate_type> aggregate_type
%type <sv_cols> group_by_list
%type <sv_having> having_expr
%type <sv_havings> having_exprs
%%
start:
stmt ';'
......@@ -154,14 +160,34 @@ dml:
{
$$ = std::make_shared<UpdateStmt>($2, $4, $5);
}
| SELECT selector FROM tableList optWhereClause opt_order_clause
| SHOW INDEX FROM tbName
{
$$ = std::make_shared<ShowIndex>($4);
}
| SELECT target FROM tableList optWhereClause opt_order_clause
{
$$ = std::make_shared<SelectStmt>($2, $4, $5, $6);
}
| SHOW INDEX FROM tbName
| SELECT target FROM tableList optWhereClause GROUPBY group_by_list opt_order_clause
{
$$ = std::make_shared<ShowIndex>($4);
$$ = std::make_shared<SelectStmt>($2,$4, $5, $7, $8);
}
| SELECT target FROM tableList optWhereClause GROUPBY group_by_list HAVING having_exprs opt_order_clause
{
$$ = std::make_shared<SelectStmt>($2,$4, $5, $7, $9,$10);
}
;
target :
selector
{
$$ = std::make_shared<Target>($1, std::vector<std::shared_ptr<AggregateExpr>>{});
}
| aggregates
{
$$ = std::make_shared<Target>(std::vector<std::shared_ptr<Col>>{}, $1);
}
;
fieldList:
......@@ -379,6 +405,91 @@ order_clause:
$$ = std::make_shared<OrderBy>($1, $2);
}
;
aggregates:
aggregate
{
$$ =std::vector<std::shared_ptr<AggregateExpr>>{ $1 };
}
| aggregates ',' aggregate
{
$$.push_back($3);
}
;
aggregate:
aggregate_type '(''*'')' AS IDENTIFIER
{
$$ = std::make_shared<AggregateExpr>($1, "*", $6);
}
|aggregate_type '('otherName')' AS IDENTIFIER
{
$$ = std::make_shared<AggregateExpr>($1, $3, $6);
}
|aggregate_type '(''*'')'
{
$$ = std::make_shared<AggregateExpr>($1, "*");
}
|aggregate_type '('otherName')'
{
$$ = std::make_shared<AggregateExpr>($1, $3);
}
| colList ',' aggregate_type '(''*'')' AS IDENTIFIER
{
$$ = std::make_shared<AggregateExpr>($1, $3,"*", $8);
}
| colList ',' aggregate_type '('otherName')' AS IDENTIFIER
{
$$ = std::make_shared<AggregateExpr>($1, $3,$5, $8);
}
;
group_by_list:
col
{
$$ = std::vector<std::shared_ptr<Col>>{$1};
}
|group_by_list ',' col
{
$$.push_back($3);
}
;
having_exprs:
having_expr
{
$$ = std::vector<std::shared_ptr<HavingStmt>>{$1};
}
| having_exprs AND having_expr
{
$$.push_back($3);
}
;
having_expr:
aggregate op expr
{
$$ = std::make_shared<HavingStmt>($1, $2, $3);
}
;
aggregate_type:
SUM
{
$$ =ast::SUM;
}
| MAX
{
$$ = ast::MAX;
}
| MIN
{
$$ = ast::MIN;
}
| COUNT
{
$$ = ast::COUNT;
}
;
opt_asc_desc:
ASC { $$ = OrderBy_ASC; }
......@@ -394,4 +505,5 @@ set_knob_type:
tbName: IDENTIFIER;
colName: IDENTIFIER;
otherName: IDENTIFIER;
%%
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment