Implement async document processing in queries

This commit is contained in:
Tobie Morgan Hitchcock 2019-06-14 18:33:41 +01:00
parent bcb1d3174c
commit db1864224b
12 changed files with 565 additions and 393 deletions

View file

@ -60,6 +60,7 @@ type iterator struct {
limit int
start int
versn int64
async bool
}
type workable struct {
@ -135,6 +136,7 @@ func (i *iterator) Close() {
i.limit = -1
i.start = -1
i.versn = 0
i.async = false
iteratorPool.Put(i)
@ -161,18 +163,24 @@ func (i *iterator) setupState(ctx context.Context) {
i.split = stm.Split
i.group = stm.Group
i.order = stm.Order
i.async = stm.Parallel
case *sql.CreateStatement:
i.what = stm.What
i.async = stm.Parallel
case *sql.UpdateStatement:
i.what = stm.What
i.cond = stm.Cond
i.async = stm.Parallel
case *sql.DeleteStatement:
i.what = stm.What
i.cond = stm.Cond
i.async = stm.Parallel
case *sql.InsertStatement:
i.what = sql.Exprs{stm.Data}
i.async = stm.Parallel
case *sql.UpsertStatement:
i.what = sql.Exprs{stm.Data}
i.async = stm.Parallel
}
if stm, ok := i.stm.(*sql.SelectStatement); ok {
@ -233,7 +241,13 @@ func (i *iterator) setupWorkers(ctx context.Context) {
}
}(i.vals)
for w := 1; w <= workerCount; w++ {
workers := 1
if i.async {
workers = workerCount
}
for w := 1; w <= workers; w++ {
go func(jobs <-chan *workable, vals chan<- *doneable) {
for j := range jobs {
res, err := newDocument(i, j.key, j.val, j.doc).query(ctx, i.stm)

View file

@ -16,6 +16,7 @@ package db
import (
"errors"
"runtime"
)
type method int8
@ -85,7 +86,7 @@ const (
var (
// workerCount specifies how many workers should be used
// to process each query statement concurrently.
workerCount = 1
workerCount = runtime.NumCPU()
// maxRecursiveQueries specifies how many queries will be
// processed recursively before the query is cancelled.

View file

@ -172,6 +172,7 @@ type SelectStatement struct {
Fetch Fetchs
Version Expr
Timeout time.Duration
Parallel bool
}
// CreateStatement represents a SQL CREATE statement.
@ -180,6 +181,7 @@ type CreateStatement struct {
Data Expr
Echo Token
Timeout time.Duration
Parallel bool
}
// UpdateStatement represents a SQL UPDATE statement.
@ -189,6 +191,7 @@ type UpdateStatement struct {
Cond Expr
Echo Token
Timeout time.Duration
Parallel bool
}
// DeleteStatement represents a SQL DELETE statement.
@ -197,6 +200,7 @@ type DeleteStatement struct {
Cond Expr
Echo Token
Timeout time.Duration
Parallel bool
}
// RelateStatement represents a SQL RELATE statement.
@ -208,6 +212,7 @@ type RelateStatement struct {
Uniq bool
Echo Token
Timeout time.Duration
Parallel bool
}
// InsertStatement represents a SQL INSERT statement.
@ -216,6 +221,7 @@ type InsertStatement struct {
Into *Table
Echo Token
Timeout time.Duration
Parallel bool
}
// UpsertStatement represents a SQL UPSERT statement.
@ -224,6 +230,7 @@ type UpsertStatement struct {
Into *Table
Echo Token
Timeout time.Duration
Parallel bool
}
// --------------------------------------------------

View file

@ -34,6 +34,10 @@ func (p *parser) parseCreateStatement() (stmt *CreateStatement, err error) {
return nil, err
}
if stmt.Parallel, err = p.parseParallel(); err != nil {
return nil, err
}
return
}

View file

@ -36,6 +36,10 @@ func (p *parser) parseDeleteStatement() (stmt *DeleteStatement, err error) {
return nil, err
}
if stmt.Parallel, err = p.parseParallel(); err != nil {
return nil, err
}
return
}

View file

@ -244,20 +244,20 @@ func (p *parser) parsePriority() (float64, error) {
}
func (p *parser) parseParallel() (int, error) {
func (p *parser) parseParallel() (bool, error) {
if _, _, exi := p.mightBe(PARALLEL); !exi {
return 0, nil
return true, nil
}
tok, lit, err := p.shouldBe(NUMBER)
tok, lit, err := p.shouldBe(TRUE, FALSE)
if err != nil {
return 0, &ParseError{Found: lit, Expected: []string{"number"}}
return true, &ParseError{Found: lit, Expected: []string{"true", "false"}}
}
val, err := p.declare(tok, lit)
return int(val.(float64)), err
return val.(bool), err
}

View file

@ -40,6 +40,10 @@ func (p *parser) parseInsertStatement() (stmt *InsertStatement, err error) {
return nil, err
}
if stmt.Parallel, err = p.parseParallel(); err != nil {
return nil, err
}
return
}

View file

@ -52,6 +52,10 @@ func (p *parser) parseRelateStatement() (stmt *RelateStatement, err error) {
return nil, err
}
if stmt.Parallel, err = p.parseParallel(); err != nil {
return nil, err
}
return
}

View file

@ -67,6 +67,10 @@ func (p *parser) parseSelectStatement() (stmt *SelectStatement, err error) {
return nil, err
}
if stmt.Parallel, err = p.parseParallel(); err != nil {
return nil, err
}
if err = checkExpression(aggrs, stmt.Expr, stmt.Group); err != nil {
return nil, err
}

View file

@ -457,6 +457,7 @@ func Test_Parse_Queries_Let(t *testing.T) {
What: &SubExpression{Expr: &CreateStatement{
What: Exprs{&Ident{"person"}},
Echo: AFTER,
Parallel: true,
}},
}}},
},
@ -567,6 +568,7 @@ func Test_Parse_Queries_Return(t *testing.T) {
What: Exprs{&SubExpression{Expr: &CreateStatement{
What: Exprs{&Ident{"person"}},
Echo: AFTER,
Parallel: true,
}}},
}}},
},
@ -614,6 +616,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Parallel: true,
}}},
},
{
@ -638,6 +641,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{float64(111)},
Parallel: true,
}}},
},
{
@ -647,6 +651,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"111"}},
Parallel: true,
}}},
},
{
@ -655,6 +660,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"2006-01-02"}},
Parallel: true,
}}},
},
{
@ -663,6 +669,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"2006-01-02T15:04:05+07:00"}},
Parallel: true,
}}},
},
{
@ -671,6 +678,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"2006-01-02T15:04:05.999999999+07:00"}},
Parallel: true,
}}},
},
{
@ -679,6 +687,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Parallel: true,
}}},
},
{
@ -687,6 +696,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}, &Ident{"tweet"}},
Parallel: true,
}}},
},
{
@ -695,6 +705,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: "1a"}},
Parallel: true,
}}},
},
{
@ -704,6 +715,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: "1a"}},
Parallel: true,
}}},
},
{
@ -712,6 +724,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: float64(123456)}},
Parallel: true,
}}},
},
{
@ -721,6 +734,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: float64(123456)}},
Parallel: true,
}}},
},
{
@ -729,6 +743,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: float64(123.456)}},
Parallel: true,
}}},
},
{
@ -738,6 +753,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: float64(123.456)}},
Parallel: true,
}}},
},
{
@ -746,6 +762,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: "123.456.789.012"}},
Parallel: true,
}}},
},
{
@ -755,6 +772,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: "123.456.789.012"}},
Parallel: true,
}}},
},
{
@ -764,6 +782,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: date}},
Parallel: true,
}}},
},
{
@ -772,6 +791,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: nano}},
Parallel: true,
}}},
},
{
@ -780,6 +800,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: "A250C5A3-948F-4657-88AD-FF5F27B5B24E"}},
Parallel: true,
}}},
},
{
@ -788,6 +809,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: "8250C5A3-948F-4657-88AD-FF5F27B5B24E"}},
Parallel: true,
}}},
},
{
@ -796,6 +818,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "person", ID: "Tobie Morgan Hitchcock"}},
Parallel: true,
}}},
},
{
@ -804,6 +827,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "email addresses", ID: "tobie@abcum.com"}},
Parallel: true,
}}},
},
{
@ -812,6 +836,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
RW: false,
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Thing{TB: "email addresses", ID: "tobie+spam@abcum.com"}},
Parallel: true,
}}},
},
{
@ -823,6 +848,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
{Expr: &Ident{"temp"}, Field: "test", Alias: "test"},
},
What: []Expr{&Ident{"person"}},
Parallel: true,
}}},
},
{
@ -833,6 +859,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
{Expr: &Ident{"email addresses"}, Field: "emails", Alias: "emails"},
},
What: []Expr{&Ident{"person"}},
Parallel: true,
}}},
},
{
@ -843,6 +870,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
{Expr: &Ident{"emails"}, Field: "email addresses", Alias: "email addresses"},
},
What: []Expr{&Ident{"person"}},
Parallel: true,
}}},
},
{
@ -855,7 +883,9 @@ func Test_Parse_Queries_Select(t *testing.T) {
What: Exprs{&SubExpression{Expr: &CreateStatement{
What: Exprs{&Ident{"person"}},
Echo: AFTER,
Parallel: true,
}}},
Parallel: true,
}}},
},
{
@ -865,6 +895,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: &Value{"\n"}},
Parallel: true,
}}},
},
{
@ -874,6 +905,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: &Value{"\r"}},
Parallel: true,
}}},
},
{
@ -883,6 +915,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: &Value{"\b\n\r\t"}},
Parallel: true,
}}},
},
{
@ -896,6 +929,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &Ident{"id"},
Parallel: true,
}}},
},
{
@ -909,6 +943,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: float64(1)},
Parallel: true,
}}},
},
{
@ -918,6 +953,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Empty{}},
Parallel: true,
}}},
},
{
@ -927,6 +963,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Empty{}},
Parallel: true,
}}},
},
{
@ -937,6 +974,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Void{}},
Parallel: true,
}}},
},
{
@ -947,6 +985,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Void{}},
Parallel: true,
}}},
},
{
@ -957,6 +996,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Empty{}},
Parallel: true,
}}},
},
{
@ -967,6 +1007,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Empty{}},
Parallel: true,
}}},
},
{
@ -977,6 +1018,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Void{}},
Parallel: true,
}}},
},
{
@ -987,6 +1029,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Void{}},
Parallel: true,
}}},
},
{
@ -996,6 +1039,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: true},
Parallel: true,
}}},
},
{
@ -1005,6 +1049,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: false},
Parallel: true,
}}},
},
{
@ -1050,6 +1095,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
},
},
},
Parallel: true,
}}},
},
{
@ -1071,6 +1117,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Op: EQ,
RHS: float64(10),
},
Parallel: true,
}}},
},
{
@ -1092,6 +1139,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Op: EQ,
RHS: float64(14),
},
Parallel: true,
}}},
},
{
@ -1117,6 +1165,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Op: EQ,
RHS: float64(18),
},
Parallel: true,
}}},
},
{
@ -1142,6 +1191,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Op: EQ,
RHS: float64(17),
},
Parallel: true,
}}},
},
{
@ -1169,6 +1219,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Op: EQ,
RHS: float64(32),
},
Parallel: true,
}}},
},
{
@ -1179,6 +1230,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: INS, RHS: []interface{}{"London", "Paris"}},
Parallel: true,
}}},
},
{
@ -1189,6 +1241,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: INS, RHS: []interface{}{"London", "Paris"}},
Parallel: true,
}}},
},
{
@ -1199,6 +1252,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: NIS, RHS: []interface{}{"London", "Paris"}},
Parallel: true,
}}},
},
{
@ -1209,6 +1263,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: []interface{}{"London", "Paris"}, Op: SIN, RHS: &Ident{"test"}},
Parallel: true,
}}},
},
{
@ -1219,6 +1274,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: []interface{}{"London", "Paris"}, Op: SNI, RHS: &Ident{"test"}},
Parallel: true,
}}},
},
{
@ -1232,6 +1288,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: EQ, RHS: map[string]interface{}{"name": "London"}},
Parallel: true,
}}},
},
{
@ -1241,6 +1298,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: EQ, RHS: map[string]interface{}{"name": map[string]interface{}{"f": "first", "l": "last"}}},
Parallel: true,
}}},
},
{
@ -1250,6 +1308,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Timeout: 1 * time.Second,
Parallel: true,
}}},
},
{
@ -1319,6 +1378,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
res: &Query{Statements: []Statement{&CreateStatement{
What: []Expr{&Ident{"person"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1335,6 +1395,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Void{}}}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1343,6 +1404,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Empty{}}}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1355,6 +1417,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Value{"Tobie"}}}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1375,6 +1438,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &MergeExpression{Data: map[string]interface{}{"firstname": "Tobie"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1395,6 +1459,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &ContentExpression{Data: map[string]interface{}{"firstname": "Tobie"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1406,6 +1471,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
res: &Query{Statements: []Statement{&CreateStatement{
What: []Expr{&Ident{"person"}},
Echo: NONE,
Parallel: true,
}}},
},
{
@ -1413,6 +1479,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
res: &Query{Statements: []Statement{&CreateStatement{
What: []Expr{&Ident{"person"}},
Echo: BOTH,
Parallel: true,
}}},
},
{
@ -1420,6 +1487,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
res: &Query{Statements: []Statement{&CreateStatement{
What: []Expr{&Ident{"person"}},
Echo: DIFF,
Parallel: true,
}}},
},
{
@ -1427,6 +1495,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
res: &Query{Statements: []Statement{&CreateStatement{
What: []Expr{&Ident{"person"}},
Echo: BEFORE,
Parallel: true,
}}},
},
{
@ -1435,6 +1504,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
res: &Query{Statements: []Statement{&CreateStatement{
What: []Expr{&Ident{"person"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1443,6 +1513,7 @@ func Test_Parse_Queries_Create(t *testing.T) {
What: []Expr{&Ident{"person"}},
Echo: AFTER,
Timeout: 1 * time.Second,
Parallel: true,
}}},
},
{
@ -1473,6 +1544,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
res: &Query{Statements: []Statement{&UpdateStatement{
What: []Expr{&Ident{"person"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1489,6 +1561,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Void{}}}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1497,6 +1570,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Empty{}}}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1509,6 +1583,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Value{"Tobie"}}}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1529,6 +1604,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &DiffExpression{Data: []interface{}{}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1549,6 +1625,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &MergeExpression{Data: map[string]interface{}{"firstname": "Tobie"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1569,6 +1646,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
What: []Expr{&Ident{"person"}},
Data: &ContentExpression{Data: map[string]interface{}{"firstname": "Tobie"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1580,6 +1658,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
res: &Query{Statements: []Statement{&UpdateStatement{
What: []Expr{&Ident{"person"}},
Echo: NONE,
Parallel: true,
}}},
},
{
@ -1587,6 +1666,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
res: &Query{Statements: []Statement{&UpdateStatement{
What: []Expr{&Ident{"person"}},
Echo: BOTH,
Parallel: true,
}}},
},
{
@ -1594,6 +1674,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
res: &Query{Statements: []Statement{&UpdateStatement{
What: []Expr{&Ident{"person"}},
Echo: DIFF,
Parallel: true,
}}},
},
{
@ -1601,6 +1682,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
res: &Query{Statements: []Statement{&UpdateStatement{
What: []Expr{&Ident{"person"}},
Echo: BEFORE,
Parallel: true,
}}},
},
{
@ -1609,6 +1691,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
res: &Query{Statements: []Statement{&UpdateStatement{
What: []Expr{&Ident{"person"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1617,6 +1700,7 @@ func Test_Parse_Queries_Update(t *testing.T) {
What: []Expr{&Ident{"person"}},
Echo: AFTER,
Timeout: 1 * time.Second,
Parallel: true,
}}},
},
{
@ -1651,6 +1735,7 @@ func Test_Parse_Queries_Delete(t *testing.T) {
res: &Query{Statements: []Statement{&DeleteStatement{
What: []Expr{&Ident{"person"}},
Echo: NONE,
Parallel: true,
}}},
},
{
@ -1663,6 +1748,7 @@ func Test_Parse_Queries_Delete(t *testing.T) {
res: &Query{Statements: []Statement{&DeleteStatement{
What: []Expr{&Ident{"person"}},
Echo: NONE,
Parallel: true,
}}},
},
{
@ -1670,6 +1756,7 @@ func Test_Parse_Queries_Delete(t *testing.T) {
res: &Query{Statements: []Statement{&DeleteStatement{
What: []Expr{&Ident{"person"}},
Echo: BOTH,
Parallel: true,
}}},
},
{
@ -1677,6 +1764,7 @@ func Test_Parse_Queries_Delete(t *testing.T) {
res: &Query{Statements: []Statement{&DeleteStatement{
What: []Expr{&Ident{"person"}},
Echo: DIFF,
Parallel: true,
}}},
},
{
@ -1684,6 +1772,7 @@ func Test_Parse_Queries_Delete(t *testing.T) {
res: &Query{Statements: []Statement{&DeleteStatement{
What: []Expr{&Ident{"person"}},
Echo: BEFORE,
Parallel: true,
}}},
},
{
@ -1691,6 +1780,7 @@ func Test_Parse_Queries_Delete(t *testing.T) {
res: &Query{Statements: []Statement{&DeleteStatement{
What: []Expr{&Ident{"person"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1699,6 +1789,7 @@ func Test_Parse_Queries_Delete(t *testing.T) {
What: []Expr{&Ident{"person"}},
Echo: NONE,
Timeout: 1 * time.Second,
Parallel: true,
}}},
},
{
@ -1747,6 +1838,7 @@ func Test_Parse_Queries_Relate(t *testing.T) {
From: []Expr{&Ident{"person"}},
With: []Expr{&Ident{"item"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1757,6 +1849,7 @@ func Test_Parse_Queries_Relate(t *testing.T) {
With: []Expr{&Ident{"item"}},
Uniq: true,
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1775,6 +1868,7 @@ func Test_Parse_Queries_Relate(t *testing.T) {
With: []Expr{&Ident{"item"}},
Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"public"}, Op: EQ, RHS: true}}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1788,6 +1882,7 @@ func Test_Parse_Queries_Relate(t *testing.T) {
From: []Expr{&Ident{"person"}},
With: []Expr{&Ident{"item"}},
Echo: NONE,
Parallel: true,
}}},
},
{
@ -1797,6 +1892,7 @@ func Test_Parse_Queries_Relate(t *testing.T) {
From: []Expr{&Ident{"person"}},
With: []Expr{&Ident{"item"}},
Echo: BOTH,
Parallel: true,
}}},
},
{
@ -1806,6 +1902,7 @@ func Test_Parse_Queries_Relate(t *testing.T) {
From: []Expr{&Ident{"person"}},
With: []Expr{&Ident{"item"}},
Echo: DIFF,
Parallel: true,
}}},
},
{
@ -1815,6 +1912,7 @@ func Test_Parse_Queries_Relate(t *testing.T) {
From: []Expr{&Ident{"person"}},
With: []Expr{&Ident{"item"}},
Echo: BEFORE,
Parallel: true,
}}},
},
{
@ -1825,6 +1923,7 @@ func Test_Parse_Queries_Relate(t *testing.T) {
From: []Expr{&Ident{"person"}},
With: []Expr{&Ident{"item"}},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1835,6 +1934,7 @@ func Test_Parse_Queries_Relate(t *testing.T) {
With: []Expr{&Ident{"item"}},
Echo: AFTER,
Timeout: 1 * time.Second,
Parallel: true,
}}},
},
{
@ -1874,6 +1974,7 @@ func Test_Parse_Queries_Insert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1886,6 +1987,7 @@ func Test_Parse_Queries_Insert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: NONE,
Parallel: true,
}}},
},
{
@ -1894,6 +1996,7 @@ func Test_Parse_Queries_Insert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: INFO,
Parallel: true,
}}},
},
{
@ -1902,6 +2005,7 @@ func Test_Parse_Queries_Insert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: BOTH,
Parallel: true,
}}},
},
{
@ -1910,6 +2014,7 @@ func Test_Parse_Queries_Insert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: DIFF,
Parallel: true,
}}},
},
{
@ -1918,6 +2023,7 @@ func Test_Parse_Queries_Insert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: BEFORE,
Parallel: true,
}}},
},
{
@ -1927,6 +2033,7 @@ func Test_Parse_Queries_Insert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1936,6 +2043,7 @@ func Test_Parse_Queries_Insert(t *testing.T) {
Into: &Table{"person"},
Echo: AFTER,
Timeout: 1 * time.Second,
Parallel: true,
}}},
},
{
@ -1975,6 +2083,7 @@ func Test_Parse_Queries_Upsert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -1987,6 +2096,7 @@ func Test_Parse_Queries_Upsert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: NONE,
Parallel: true,
}}},
},
{
@ -1995,6 +2105,7 @@ func Test_Parse_Queries_Upsert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: INFO,
Parallel: true,
}}},
},
{
@ -2003,6 +2114,7 @@ func Test_Parse_Queries_Upsert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: BOTH,
Parallel: true,
}}},
},
{
@ -2011,6 +2123,7 @@ func Test_Parse_Queries_Upsert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: DIFF,
Parallel: true,
}}},
},
{
@ -2019,6 +2132,7 @@ func Test_Parse_Queries_Upsert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: BEFORE,
Parallel: true,
}}},
},
{
@ -2028,6 +2142,7 @@ func Test_Parse_Queries_Upsert(t *testing.T) {
Data: []interface{}{"one", "two", "tre"},
Into: &Table{"person"},
Echo: AFTER,
Parallel: true,
}}},
},
{
@ -2037,6 +2152,7 @@ func Test_Parse_Queries_Upsert(t *testing.T) {
Into: &Table{"person"},
Echo: AFTER,
Timeout: 1 * time.Second,
Parallel: true,
}}},
},
{
@ -2393,6 +2509,7 @@ func Test_Parse_Queries_Define(t *testing.T) {
Expr: &CreateStatement{
What: Exprs{&Ident{"person"}},
Echo: AFTER,
Parallel: true,
},
},
}}},
@ -2409,6 +2526,7 @@ func Test_Parse_Queries_Define(t *testing.T) {
Expr: &SelectStatement{
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Ident{"person"}},
Parallel: true,
},
},
}}},
@ -2425,6 +2543,7 @@ func Test_Parse_Queries_Define(t *testing.T) {
Expr: &SelectStatement{
Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Param{"id"}},
Parallel: true,
},
},
}}},
@ -2649,6 +2768,7 @@ func Test_Parse_Queries_Define(t *testing.T) {
},
}},
Echo: AFTER,
Parallel: true,
},
},
},
@ -2676,6 +2796,7 @@ func Test_Parse_Queries_Define(t *testing.T) {
},
}},
Echo: AFTER,
Parallel: true,
},
&UpdateStatement{
What: Exprs{&Param{"this"}},
@ -2687,6 +2808,7 @@ func Test_Parse_Queries_Define(t *testing.T) {
},
}},
Echo: AFTER,
Parallel: true,
},
},
},

View file

@ -38,6 +38,10 @@ func (p *parser) parseUpdateStatement() (stmt *UpdateStatement, err error) {
return nil, err
}
if stmt.Parallel, err = p.parseParallel(); err != nil {
return nil, err
}
return
}

View file

@ -40,6 +40,10 @@ func (p *parser) parseUpsertStatement() (stmt *UpsertStatement, err error) {
return nil, err
}
if stmt.Parallel, err = p.parseParallel(); err != nil {
return nil, err
}
return
}