Commit 0124d617 authored by cznic's avatar cznic

Verify grammar supporting issue 155 has no conflicts. Updates #155.

parent bd2055c7
......@@ -1738,7 +1738,7 @@
// The result can be filtered using a WhereClause and orderd by the OrderBy
// clause.
//
// SelectStmt = "SELECT" [ "DISTINCT" ] ( "*" | FieldList ) "FROM" RecordSetList
// SelectStmt = "SELECT" [ "DISTINCT" ] ( "*" | FieldList ) [ "FROM" RecordSetList ]
// [ JoinClause ] [ WhereClause ] [ GroupByClause ] [ OrderBy ] [ Limit ] [ Offset ].
//
// JoinClause = ( "LEFT" | "RIGHT" | "FULL" ) [ "OUTER" ] "JOIN" RecordSet "ON" Expression .
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -187,11 +187,11 @@ import (
SelectStmt "SELECT statement"
SelectStmtDistinct "SELECT statement optional DISTINCT clause"
SelectStmtFieldList "SELECT statement field list"
SelectStmtLimit "SELECT statement optional LIMIT clause"
SelectStmtWhere "SELECT statement optional WHERE clause"
SelectStmtGroup "SELECT statement optional GROUP BY clause"
SelectStmtLimit "SELECT statement optional LIMIT clause"
SelectStmtOffset "SELECT statement optional OFFSET clause"
SelectStmtOrder "SELECT statement optional ORDER BY clause"
SelectStmtWhere "SELECT statement optional WHERE clause"
Slice "string slice"
Statement "statement"
StatementList "statement list"
......@@ -204,7 +204,9 @@ import (
UpdateStmt1 "UPDATE statement optional WHERE clause"
WhereClause "WHERE clause"
%type <list> RecordSetList
%type <list>
RecordSetList
SelectStmtFrom "SELECT statement optional FROM clause"
%start Start
......@@ -1044,14 +1046,14 @@ JoinClauseOpt:
| JoinClause
SelectStmt:
"SELECT" SelectStmtDistinct SelectStmtFieldList "FROM" RecordSetList
CommaOpt JoinClauseOpt SelectStmtWhere SelectStmtGroup SelectStmtOrder
"SELECT" SelectStmtDistinct SelectStmtFieldList SelectStmtFrom
JoinClauseOpt SelectStmtWhere SelectStmtGroup SelectStmtOrder
SelectStmtLimit SelectStmtOffset
{
x := yylex.(*lexer)
n := len(x.agg)
join := &joinRset{sources: $5}
if o := $7; o != nil {
join := &joinRset{sources: $4}
if o := $5; o != nil {
o := o.([]interface{})
join.typ = o[0].(int)
join.sources = append(join.sources, o[1].([]interface{}))
......@@ -1062,15 +1064,24 @@ SelectStmt:
flds: $3.([]*fld),
from: join,
hasAggregates: x.agg[n-1],
where: $8.(*whereRset),
group: $9.(*groupByRset),
order: $10.(*orderByRset),
limit: $11.(*limitRset),
offset: $12.(*offsetRset),
where: $6.(*whereRset),
group: $7.(*groupByRset),
order: $8.(*orderByRset),
limit: $9.(*limitRset),
offset: $10.(*offsetRset),
}
x.agg = x.agg[:n-1]
}
SelectStmtFrom:
{
$$ = nil
}
| "FROM" RecordSetList CommaOpt
{
$$ = $2
}
SelectStmtLimit:
{
$$ = (*limitRset)(nil)
......@@ -1311,6 +1322,14 @@ WhereClause:
{
$$ = &whereRset{expr: expr($2)}
}
| "WHERE" "EXISTS" '(' SelectStmt ')'
{
$$ = &whereRset{exists: true, sel:($4.(*selectStmt))}
}
| "WHERE" "NOT" "EXISTS" '(' SelectStmt ')'
{
$$ = &whereRset{sel:($5.(*selectStmt))}
}
SetOpt:
......
......@@ -165,7 +165,7 @@ RecordSet = (
) [ "AS" identifier ] .
RecordSetList = RecordSet { "," RecordSet } [ "," ] .
RollbackStmt = "ROLLBACK" .
SelectStmt = "SELECT" [ "DISTINCT" ] ( "*" | FieldList ) "FROM" RecordSetList [ JoinClause ] [ WhereClause ] [ GroupByClause ] [ OrderBy ] [ Limit ] [ Offset ] .
SelectStmt = "SELECT" [ "DISTINCT" ] ( "*" | FieldList ) [ "FROM" RecordSetList ] [ JoinClause ] [ WhereClause ] [ GroupByClause ] [ OrderBy ] [ Limit ] [ Offset ] .
Slice = "[" [ Expression ] ":" [ Expression ] "]" .
Statement = EmptyStmt
| AlterTableStmt
......
......@@ -330,8 +330,10 @@ func (r *orderByRset) plan(ctx *execCtx) (plan, error) {
}
type whereRset struct {
expr expression
src plan
expr expression
src plan
sel *selectStmt
exists bool
}
func (r *whereRset) planBinOp(x *binaryOperation) (plan, error) {
......@@ -567,6 +569,10 @@ type selectRset struct {
}
func (r *selectRset) plan(ctx *execCtx) (plan, error) {
if r.src == nil {
return nil, nil
}
var flds2 []*fld
if len(r.flds) != 0 {
m := map[string]struct{}{}
......@@ -1712,6 +1718,10 @@ func (r *joinRset) plan(ctx *execCtx) (plan, error) {
return rsets[0], nil
}
if len(rsets) == 0 {
return nil, nil
}
right := len(rsets[len(rsets)-1].fieldNames())
switch r.typ {
case crossJoin:
......
......@@ -3,7 +3,7 @@
//TODO Put your favorite license here
// yacc source generated by ebnf2y[1]
// at 2017-01-26 13:18:06.609096166 +0100 CET
// at 2017-03-26 14:36:35.113818408 +0200 CEST
//
// $ ebnf2y -o ql.y -oe ql.ebnf -start StatementList -pkg ql -p _
//
......@@ -239,6 +239,7 @@ import (
SelectStmt6
SelectStmt7
SelectStmt8
SelectStmt9
Slice
Slice1
Slice2
......@@ -1112,9 +1113,9 @@ RollbackStmt:
}
SelectStmt:
_SELECT SelectStmt1 SelectStmt2 _FROM RecordSetList SelectStmt3 SelectStmt4 SelectStmt5 SelectStmt6 SelectStmt7 SelectStmt8
_SELECT SelectStmt1 SelectStmt2 SelectStmt3 SelectStmt4 SelectStmt5 SelectStmt6 SelectStmt7 SelectStmt8 SelectStmt9
{
$$ = []SelectStmt{"SELECT", $2, $3, "FROM", $5, $6, $7, $8, $9, $10, $11} //TODO 167
$$ = []SelectStmt{"SELECT", $2, $3, $4, $5, $6, $7, $8, $9, $10} //TODO 167
}
SelectStmt1:
......@@ -1142,9 +1143,9 @@ SelectStmt3:
{
$$ = nil //TODO 172
}
| JoinClause
| _FROM RecordSetList
{
$$ = $1 //TODO 173
$$ = []SelectStmt3{"FROM", $2} //TODO 173
}
SelectStmt4:
......@@ -1152,7 +1153,7 @@ SelectStmt4:
{
$$ = nil //TODO 174
}
| WhereClause
| JoinClause
{
$$ = $1 //TODO 175
}
......@@ -1162,7 +1163,7 @@ SelectStmt5:
{
$$ = nil //TODO 176
}
| GroupByClause
| WhereClause
{
$$ = $1 //TODO 177
}
......@@ -1172,7 +1173,7 @@ SelectStmt6:
{
$$ = nil //TODO 178
}
| OrderBy
| GroupByClause
{
$$ = $1 //TODO 179
}
......@@ -1182,7 +1183,7 @@ SelectStmt7:
{
$$ = nil //TODO 180
}
| Limit
| OrderBy
{
$$ = $1 //TODO 181
}
......@@ -1192,347 +1193,357 @@ SelectStmt8:
{
$$ = nil //TODO 182
}
| Offset
| Limit
{
$$ = $1 //TODO 183
}
SelectStmt9:
/* EMPTY */
{
$$ = nil //TODO 184
}
| Offset
{
$$ = $1 //TODO 185
}
Slice:
'[' Slice1 ':' Slice2 ']'
{
$$ = []Slice{"[", $2, ":", $4, "]"} //TODO 184
$$ = []Slice{"[", $2, ":", $4, "]"} //TODO 186
}
Slice1:
/* EMPTY */
{
$$ = nil //TODO 185
$$ = nil //TODO 187
}
| Expression
{
$$ = $1 //TODO 186
$$ = $1 //TODO 188
}
Slice2:
/* EMPTY */
{
$$ = nil //TODO 187
$$ = nil //TODO 189
}
| Expression
{
$$ = $1 //TODO 188
$$ = $1 //TODO 190
}
Start:
StatementList
{
_parserResult = $1 //TODO 189
_parserResult = $1 //TODO 191
}
Statement:
EmptyStmt
{
$$ = $1 //TODO 190
$$ = $1 //TODO 192
}
| AlterTableStmt
{
$$ = $1 //TODO 191
$$ = $1 //TODO 193
}
| BeginTransactionStmt
{
$$ = $1 //TODO 192
$$ = $1 //TODO 194
}
| CommitStmt
{
$$ = $1 //TODO 193
$$ = $1 //TODO 195
}
| CreateIndexStmt
{
$$ = $1 //TODO 194
$$ = $1 //TODO 196
}
| CreateTableStmt
{
$$ = $1 //TODO 195
$$ = $1 //TODO 197
}
| DeleteFromStmt
{
$$ = $1 //TODO 196
$$ = $1 //TODO 198
}
| DropIndexStmt
{
$$ = $1 //TODO 197
$$ = $1 //TODO 199
}
| DropTableStmt
{
$$ = $1 //TODO 198
$$ = $1 //TODO 200
}
| InsertIntoStmt
{
$$ = $1 //TODO 199
$$ = $1 //TODO 201
}
| RollbackStmt
{
$$ = $1 //TODO 200
$$ = $1 //TODO 202
}
| SelectStmt
{
$$ = $1 //TODO 201
$$ = $1 //TODO 203
}
| TruncateTableStmt
{
$$ = $1 //TODO 202
$$ = $1 //TODO 204
}
| UpdateStmt
{
$$ = $1 //TODO 203
$$ = $1 //TODO 205
}
| ExplainStmt
{
$$ = $1 //TODO 204
$$ = $1 //TODO 206
}
StatementList:
Statement StatementList1
{
$$ = []StatementList{$1, $2} //TODO 205
$$ = []StatementList{$1, $2} //TODO 207
}
StatementList1:
/* EMPTY */
{
$$ = []StatementList1(nil) //TODO 206
$$ = []StatementList1(nil) //TODO 208
}
| StatementList1 ';' Statement
{
$$ = append($1.([]StatementList1), ";", $3) //TODO 207
$$ = append($1.([]StatementList1), ";", $3) //TODO 209
}
TableName:
_IDENTIFIER
{
$$ = $1 //TODO 208
$$ = $1 //TODO 210
}
Term:
Factor Term1
{
$$ = []Term{$1, $2} //TODO 209
$$ = []Term{$1, $2} //TODO 211
}
Term1:
/* EMPTY */
{
$$ = []Term1(nil) //TODO 210
$$ = []Term1(nil) //TODO 212
}
| Term1 Term11 Factor
{
$$ = append($1.([]Term1), $2, $3) //TODO 211
$$ = append($1.([]Term1), $2, $3) //TODO 213
}
Term11:
_ANDAND
{
$$ = $1 //TODO 212
$$ = $1 //TODO 214
}
| _AND
{
$$ = "AND" //TODO 213
$$ = "AND" //TODO 215
}
TruncateTableStmt:
_TRUNCATE _TABLE TableName
{
$$ = []TruncateTableStmt{"TRUNCATE", "TABLE", $3} //TODO 214
$$ = []TruncateTableStmt{"TRUNCATE", "TABLE", $3} //TODO 216
}
Type:
_BIGINT
{
$$ = "bigint" //TODO 215
$$ = "bigint" //TODO 217
}
| _BIGRAT
{
$$ = "bigrat" //TODO 216
$$ = "bigrat" //TODO 218
}
| _BLOB
{
$$ = "blob" //TODO 217
$$ = "blob" //TODO 219
}
| _BOOL
{
$$ = "bool" //TODO 218
$$ = "bool" //TODO 220
}
| _BYTE
{
$$ = "byte" //TODO 219
$$ = "byte" //TODO 221
}
| _COMPLEX128
{
$$ = "complex128" //TODO 220
$$ = "complex128" //TODO 222
}
| _COMPLEX64
{
$$ = "complex64" //TODO 221
$$ = "complex64" //TODO 223
}
| _DURATION
{
$$ = "duration" //TODO 222
$$ = "duration" //TODO 224
}
| _FLOAT
{
$$ = "float" //TODO 223
$$ = "float" //TODO 225
}
| _FLOAT32
{
$$ = "float32" //TODO 224
$$ = "float32" //TODO 226
}
| _FLOAT64
{
$$ = "float64" //TODO 225
$$ = "float64" //TODO 227
}
| _INT
{
$$ = "int" //TODO 226
$$ = "int" //TODO 228
}
| _INT16
{
$$ = "int16" //TODO 227
$$ = "int16" //TODO 229
}
| _INT32
{
$$ = "int32" //TODO 228
$$ = "int32" //TODO 230
}
| _INT64
{
$$ = "int64" //TODO 229
$$ = "int64" //TODO 231
}
| _INT8
{
$$ = "int8" //TODO 230
$$ = "int8" //TODO 232
}
| _RUNE
{
$$ = "rune" //TODO 231
$$ = "rune" //TODO 233
}
| _STRING
{
$$ = "string" //TODO 232
$$ = "string" //TODO 234
}
| _TIME
{
$$ = "time" //TODO 233
$$ = "time" //TODO 235
}
| _UINT
{
$$ = "uint" //TODO 234
$$ = "uint" //TODO 236
}
| _UINT16
{
$$ = "uint16" //TODO 235
$$ = "uint16" //TODO 237
}
| _UINT32
{
$$ = "uint32" //TODO 236
$$ = "uint32" //TODO 238
}
| _UINT64
{
$$ = "uint64" //TODO 237
$$ = "uint64" //TODO 239
}
| _UINT8
{
$$ = "uint8" //TODO 238
$$ = "uint8" //TODO 240
}
UnaryExpr:
UnaryExpr1 PrimaryExpression
{
$$ = []UnaryExpr{$1, $2} //TODO 239
$$ = []UnaryExpr{$1, $2} //TODO 241
}
UnaryExpr1:
/* EMPTY */
{
$$ = nil //TODO 240
$$ = nil //TODO 242
}
| UnaryExpr11
{
$$ = $1 //TODO 241
$$ = $1 //TODO 243
}
UnaryExpr11:
'^'
{
$$ = "^" //TODO 242
$$ = "^" //TODO 244
}
| '!'
{
$$ = "!" //TODO 243
$$ = "!" //TODO 245
}
| '-'
{
$$ = "-" //TODO 244
$$ = "-" //TODO 246
}
| '+'
{
$$ = "+" //TODO 245
$$ = "+" //TODO 247
}
UpdateStmt:
_UPDATE TableName UpdateStmt1 AssignmentList UpdateStmt2
{
$$ = []UpdateStmt{"UPDATE", $2, $3, $4, $5} //TODO 246
$$ = []UpdateStmt{"UPDATE", $2, $3, $4, $5} //TODO 248
}
UpdateStmt1:
/* EMPTY */
{
$$ = nil //TODO 247
$$ = nil //TODO 249
}
| _SET
{
$$ = "SET" //TODO 248
$$ = "SET" //TODO 250
}
UpdateStmt2:
/* EMPTY */
{
$$ = nil //TODO 249
$$ = nil //TODO 251
}
| WhereClause
{
$$ = $1 //TODO 250
$$ = $1 //TODO 252
}
Values:
_VALUES '(' ExpressionList ')' Values1 Values2
{
$$ = []Values{"VALUES", "(", $3, ")", $5, $6} //TODO 251
$$ = []Values{"VALUES", "(", $3, ")", $5, $6} //TODO 253
}
Values1:
/* EMPTY */
{
$$ = []Values1(nil) //TODO 252
$$ = []Values1(nil) //TODO 254
}
| Values1 ',' '(' ExpressionList ')'
{
$$ = append($1.([]Values1), ",", "(", $4, ")") //TODO 253
$$ = append($1.([]Values1), ",", "(", $4, ")") //TODO 255
}
Values2:
/* EMPTY */
{
$$ = nil //TODO 254
$$ = nil //TODO 256
}
| ','
{
$$ = "," //TODO 255
$$ = "," //TODO 257
}
WhereClause:
_WHERE Expression
{
$$ = []WhereClause{"WHERE", $2} //TODO 256
$$ = []WhereClause{"WHERE", $2} //TODO 258
}
%%
......@@ -1640,6 +1651,7 @@ type (
SelectStmt6 interface{}
SelectStmt7 interface{}
SelectStmt8 interface{}
SelectStmt9 interface{}
Slice interface{}
Slice1 interface{}
Slice2 interface{}
......
......@@ -15670,3 +15670,27 @@ COMMIT;
SELECT * FROM t WHERE c1 = 1;
|"c1", "c2"
[1 a]
-- 1347 // https://github.com/cznic/ql/issues/155
SELECT 42;
|""
[42]
-- 1348 // https://github.com/cznic/ql/issues/155
BEGIN TRANSACTION;
CREATE TABLE t (i int);
INSERT INTO t VALUES (1);
INSERT INTO t VALUES (2);
INSERT INTO t VALUES (3);
COMMIT;
SELECT * FROM t WHERE EXISTS (SELECT * FROM t WHERE i == 2);
|"i"
[2]
-- 1349 // https://github.com/cznic/ql/issues/155
BEGIN TRANSACTION;
CREATE TABLE t (i int);
COMMIT;
SELECT * FROM t WHERE EXISTS (SELECT * FROM t WHERE i == 2);
|"i"
[]
Markdown is supported
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