From db1864224be58cb4380c1e512211760d27e4dc56 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 14 Jun 2019 18:33:41 +0100 Subject: [PATCH] Implement async document processing in queries --- db/iterator.go | 16 +- db/vars.go | 3 +- sql/ast.go | 87 +++--- sql/create.go | 4 + sql/delete.go | 4 + sql/exprs.go | 10 +- sql/insert.go | 4 + sql/relate.go | 4 + sql/select.go | 4 + sql/sql_test.go | 814 ++++++++++++++++++++++++++++-------------------- sql/update.go | 4 + sql/upsert.go | 4 + 12 files changed, 565 insertions(+), 393 deletions(-) diff --git a/db/iterator.go b/db/iterator.go index 0a6a8589..9f029449 100644 --- a/db/iterator.go +++ b/db/iterator.go @@ -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) diff --git a/db/vars.go b/db/vars.go index 12a91ee2..9de4999c 100644 --- a/db/vars.go +++ b/db/vars.go @@ -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. diff --git a/sql/ast.go b/sql/ast.go index 009ddca1..94f07fae 100644 --- a/sql/ast.go +++ b/sql/ast.go @@ -160,70 +160,77 @@ type IfelseStatement struct { // SelectStatement represents a SQL SELECT statement. type SelectStatement struct { - RW bool - Expr Fields - What Exprs - Cond Expr - Split Idents - Group Groups - Order Orders - Limit Expr - Start Expr - Fetch Fetchs - Version Expr - Timeout time.Duration + RW bool + Expr Fields + What Exprs + Cond Expr + Split Idents + Group Groups + Order Orders + Limit Expr + Start Expr + Fetch Fetchs + Version Expr + Timeout time.Duration + Parallel bool } // CreateStatement represents a SQL CREATE statement. type CreateStatement struct { - What Exprs - Data Expr - Echo Token - Timeout time.Duration + What Exprs + Data Expr + Echo Token + Timeout time.Duration + Parallel bool } // UpdateStatement represents a SQL UPDATE statement. type UpdateStatement struct { - What Exprs - Data Expr - Cond Expr - Echo Token - Timeout time.Duration + What Exprs + Data Expr + Cond Expr + Echo Token + Timeout time.Duration + Parallel bool } // DeleteStatement represents a SQL DELETE statement. type DeleteStatement struct { - What Exprs - Cond Expr - Echo Token - Timeout time.Duration + What Exprs + Cond Expr + Echo Token + Timeout time.Duration + Parallel bool } // RelateStatement represents a SQL RELATE statement. type RelateStatement struct { - Type Expr - From Exprs - With Exprs - Data Expr - Uniq bool - Echo Token - Timeout time.Duration + Type Expr + From Exprs + With Exprs + Data Expr + Uniq bool + Echo Token + Timeout time.Duration + Parallel bool } // InsertStatement represents a SQL INSERT statement. type InsertStatement struct { - Data Expr - Into *Table - Echo Token - Timeout time.Duration + Data Expr + Into *Table + Echo Token + Timeout time.Duration + Parallel bool } // UpsertStatement represents a SQL UPSERT statement. type UpsertStatement struct { - Data Expr - Into *Table - Echo Token - Timeout time.Duration + Data Expr + Into *Table + Echo Token + Timeout time.Duration + Parallel bool } // -------------------------------------------------- diff --git a/sql/create.go b/sql/create.go index 5d1cf848..e9a5a205 100644 --- a/sql/create.go +++ b/sql/create.go @@ -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 } diff --git a/sql/delete.go b/sql/delete.go index 0c2d1afa..10cec11a 100644 --- a/sql/delete.go +++ b/sql/delete.go @@ -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 } diff --git a/sql/exprs.go b/sql/exprs.go index 359e3adc..0ec64faa 100644 --- a/sql/exprs.go +++ b/sql/exprs.go @@ -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 } diff --git a/sql/insert.go b/sql/insert.go index 7d10d2b7..7a186163 100644 --- a/sql/insert.go +++ b/sql/insert.go @@ -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 } diff --git a/sql/relate.go b/sql/relate.go index ab54cbe2..994d8e25 100644 --- a/sql/relate.go +++ b/sql/relate.go @@ -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 } diff --git a/sql/select.go b/sql/select.go index 6cc0d75d..66dd8a74 100644 --- a/sql/select.go +++ b/sql/select.go @@ -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 } diff --git a/sql/sql_test.go b/sql/sql_test.go index 1dd05479..0e657115 100644 --- a/sql/sql_test.go +++ b/sql/sql_test.go @@ -455,8 +455,9 @@ func Test_Parse_Queries_Let(t *testing.T) { RW: true, Name: &Ident{"name"}, What: &SubExpression{Expr: &CreateStatement{ - What: Exprs{&Ident{"person"}}, - Echo: AFTER, + What: Exprs{&Ident{"person"}}, + Echo: AFTER, + Parallel: true, }}, }}}, }, @@ -565,8 +566,9 @@ func Test_Parse_Queries_Return(t *testing.T) { res: &Query{Statements: []Statement{&ReturnStatement{ RW: true, What: Exprs{&SubExpression{Expr: &CreateStatement{ - What: Exprs{&Ident{"person"}}, - Echo: AFTER, + What: Exprs{&Ident{"person"}}, + Echo: AFTER, + Parallel: true, }}}, }}}, }, @@ -611,9 +613,10 @@ func Test_Parse_Queries_Select(t *testing.T) { { sql: `SELECT * FROM person`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Parallel: true, }}}, }, { @@ -635,183 +638,205 @@ func Test_Parse_Queries_Select(t *testing.T) { { sql: "SELECT * FROM 111", res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{float64(111)}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{float64(111)}, + Parallel: true, }}}, }, { sql: "SELECT * FROM `111`", str: "SELECT * FROM 111", res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"111"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"111"}}, + Parallel: true, }}}, }, { sql: "SELECT * FROM `2006-01-02`", res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"2006-01-02"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"2006-01-02"}}, + Parallel: true, }}}, }, { sql: "SELECT * FROM `2006-01-02T15:04:05+07:00`", res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"2006-01-02T15:04:05+07:00"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"2006-01-02T15:04:05+07:00"}}, + Parallel: true, }}}, }, { sql: "SELECT * FROM `2006-01-02T15:04:05.999999999+07:00`", res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"2006-01-02T15:04:05.999999999+07:00"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"2006-01-02T15:04:05.999999999+07:00"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person, tweet`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}, &Ident{"tweet"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}, &Ident{"tweet"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:1a`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: "1a"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: "1a"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:⟨1a⟩`, str: `SELECT * FROM person:1a`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: "1a"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: "1a"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:123456`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: float64(123456)}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: float64(123456)}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:⟨123456⟩`, str: `SELECT * FROM person:123456`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: float64(123456)}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: float64(123456)}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:123.456`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: float64(123.456)}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: float64(123.456)}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:⟨123.456⟩`, str: `SELECT * FROM person:123.456`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: float64(123.456)}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: float64(123.456)}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:123.456.789.012`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: "123.456.789.012"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: "123.456.789.012"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:⟨123.456.789.012⟩`, str: `SELECT * FROM person:123.456.789.012`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: "123.456.789.012"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: "123.456.789.012"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:⟨1987-06-22⟩`, str: `SELECT * FROM person:⟨1987-06-22T00:00:00Z⟩`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: date}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: date}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:⟨1987-06-22T08:30:30.511Z⟩`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: nano}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: nano}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:⟨A250C5A3-948F-4657-88AD-FF5F27B5B24E⟩`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: "A250C5A3-948F-4657-88AD-FF5F27B5B24E"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: "A250C5A3-948F-4657-88AD-FF5F27B5B24E"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:⟨8250C5A3-948F-4657-88AD-FF5F27B5B24E⟩`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: "8250C5A3-948F-4657-88AD-FF5F27B5B24E"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: "8250C5A3-948F-4657-88AD-FF5F27B5B24E"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person:⟨Tobie Morgan Hitchcock⟩`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "person", ID: "Tobie Morgan Hitchcock"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "person", ID: "Tobie Morgan Hitchcock"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM ⟨email addresses⟩:⟨tobie@abcum.com⟩`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "email addresses", ID: "tobie@abcum.com"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "email addresses", ID: "tobie@abcum.com"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM ⟨email addresses⟩:⟨tobie+spam@abcum.com⟩`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Thing{TB: "email addresses", ID: "tobie+spam@abcum.com"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Thing{TB: "email addresses", ID: "tobie+spam@abcum.com"}}, + Parallel: true, }}}, }, { @@ -822,7 +847,8 @@ func Test_Parse_Queries_Select(t *testing.T) { {Expr: &All{}, Field: "*"}, {Expr: &Ident{"temp"}, Field: "test", Alias: "test"}, }, - What: []Expr{&Ident{"person"}}, + What: []Expr{&Ident{"person"}}, + Parallel: true, }}}, }, { @@ -832,7 +858,8 @@ func Test_Parse_Queries_Select(t *testing.T) { Expr: []*Field{ {Expr: &Ident{"email addresses"}, Field: "emails", Alias: "emails"}, }, - What: []Expr{&Ident{"person"}}, + What: []Expr{&Ident{"person"}}, + Parallel: true, }}}, }, { @@ -842,7 +869,8 @@ func Test_Parse_Queries_Select(t *testing.T) { Expr: []*Field{ {Expr: &Ident{"emails"}, Field: "email addresses", Alias: "email addresses"}, }, - What: []Expr{&Ident{"person"}}, + What: []Expr{&Ident{"person"}}, + Parallel: true, }}}, }, { @@ -853,36 +881,41 @@ func Test_Parse_Queries_Select(t *testing.T) { {Expr: &All{}, Field: "*"}, }, What: Exprs{&SubExpression{Expr: &CreateStatement{ - What: Exprs{&Ident{"person"}}, - Echo: AFTER, + What: Exprs{&Ident{"person"}}, + Echo: AFTER, + Parallel: true, }}}, + Parallel: true, }}}, }, { sql: "SELECT * FROM person WHERE id = \"\x0A\"", res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: &Value{"\n"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: &Value{"\n"}}, + Parallel: true, }}}, }, { sql: "SELECT * FROM person WHERE id = \"\x0D\"", res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: &Value{"\r"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: &Value{"\r"}}, + Parallel: true, }}}, }, { sql: "SELECT * FROM person WHERE id = \"\b\n\r\t\"", res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: &Value{"\b\n\r\t"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: &Value{"\b\n\r\t"}}, + Parallel: true, }}}, }, { @@ -892,10 +925,11 @@ func Test_Parse_Queries_Select(t *testing.T) { { sql: `SELECT * FROM person WHERE id`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &Ident{"id"}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &Ident{"id"}, + Parallel: true, }}}, }, { @@ -905,106 +939,117 @@ func Test_Parse_Queries_Select(t *testing.T) { { sql: `SELECT * FROM person WHERE id = 1`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: float64(1)}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"id"}, Op: EQ, RHS: float64(1)}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old = EMPTY`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Empty{}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Empty{}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old != EMPTY`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Empty{}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Empty{}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old = MISSING`, str: `SELECT * FROM person WHERE old = VOID`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Void{}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Void{}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old != MISSING`, str: `SELECT * FROM person WHERE old != VOID`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Void{}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Void{}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old IS EMPTY`, str: `SELECT * FROM person WHERE old = EMPTY`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Empty{}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Empty{}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old IS NOT EMPTY`, str: `SELECT * FROM person WHERE old != EMPTY`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Empty{}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Empty{}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old IS MISSING`, str: `SELECT * FROM person WHERE old = VOID`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Void{}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: &Void{}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old IS NOT MISSING`, str: `SELECT * FROM person WHERE old != VOID`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Void{}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: NEQ, RHS: &Void{}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old = true`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: true}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: true}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE old = false`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"old"}, Op: EQ, RHS: false}, + RW: false, + 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,56 +1219,62 @@ func Test_Parse_Queries_Select(t *testing.T) { Op: EQ, RHS: float64(32), }, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE test IN ["London","Paris"]`, str: `SELECT * FROM person WHERE test ∈ ["London","Paris"]`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: INS, RHS: []interface{}{"London", "Paris"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: INS, RHS: []interface{}{"London", "Paris"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE test IS IN ["London","Paris"]`, str: `SELECT * FROM person WHERE test ∈ ["London","Paris"]`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: INS, RHS: []interface{}{"London", "Paris"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: INS, RHS: []interface{}{"London", "Paris"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE test IS NOT IN ["London","Paris"]`, str: `SELECT * FROM person WHERE test ∉ ["London","Paris"]`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: NIS, RHS: []interface{}{"London", "Paris"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: NIS, RHS: []interface{}{"London", "Paris"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE ["London","Paris"] CONTAINS test`, str: `SELECT * FROM person WHERE ["London","Paris"] ∋ test`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: []interface{}{"London", "Paris"}, Op: SIN, RHS: &Ident{"test"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: []interface{}{"London", "Paris"}, Op: SIN, RHS: &Ident{"test"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE ["London","Paris"] CONTAINS NOT test`, str: `SELECT * FROM person WHERE ["London","Paris"] ∌ test`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: []interface{}{"London", "Paris"}, Op: SNI, RHS: &Ident{"test"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: []interface{}{"London", "Paris"}, Op: SNI, RHS: &Ident{"test"}}, + Parallel: true, }}}, }, { @@ -1228,28 +1284,31 @@ func Test_Parse_Queries_Select(t *testing.T) { { sql: `SELECT * FROM person WHERE test = {"name":"London"}`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: EQ, RHS: map[string]interface{}{"name": "London"}}, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Cond: &BinaryExpression{LHS: &Ident{"test"}, Op: EQ, RHS: map[string]interface{}{"name": "London"}}, + Parallel: true, }}}, }, { sql: `SELECT * FROM person WHERE test = {"name":{"f":"first","l":"last"}}`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - 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"}}}, + RW: false, + 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, }}}, }, { sql: `SELECT * FROM person TIMEOUT 1s`, res: &Query{Statements: []Statement{&SelectStatement{ - RW: false, - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, - Timeout: 1 * time.Second, + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Timeout: 1 * time.Second, + Parallel: true, }}}, }, { @@ -1317,8 +1376,9 @@ func Test_Parse_Queries_Create(t *testing.T) { { sql: `CREATE person`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1332,17 +1392,19 @@ func Test_Parse_Queries_Create(t *testing.T) { { sql: `CREATE person SET firstname = VOID`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Void{}}}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Void{}}}}, + Echo: AFTER, + Parallel: true, }}}, }, { sql: `CREATE person SET firstname = EMPTY`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Empty{}}}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Empty{}}}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1352,9 +1414,10 @@ func Test_Parse_Queries_Create(t *testing.T) { { sql: `CREATE person SET firstname = "Tobie"`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Value{"Tobie"}}}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Value{"Tobie"}}}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1372,9 +1435,10 @@ func Test_Parse_Queries_Create(t *testing.T) { { sql: `CREATE person MERGE {"firstname":"Tobie"}`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &MergeExpression{Data: map[string]interface{}{"firstname": "Tobie"}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &MergeExpression{Data: map[string]interface{}{"firstname": "Tobie"}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1392,9 +1456,10 @@ func Test_Parse_Queries_Create(t *testing.T) { { sql: `CREATE person CONTENT {"firstname":"Tobie"}`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &ContentExpression{Data: map[string]interface{}{"firstname": "Tobie"}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &ContentExpression{Data: map[string]interface{}{"firstname": "Tobie"}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1404,45 +1469,51 @@ func Test_Parse_Queries_Create(t *testing.T) { { sql: `CREATE person RETURN NONE`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: NONE, + What: []Expr{&Ident{"person"}}, + Echo: NONE, + Parallel: true, }}}, }, { sql: `CREATE person RETURN BOTH`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: BOTH, + What: []Expr{&Ident{"person"}}, + Echo: BOTH, + Parallel: true, }}}, }, { sql: `CREATE person RETURN DIFF`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: DIFF, + What: []Expr{&Ident{"person"}}, + Echo: DIFF, + Parallel: true, }}}, }, { sql: `CREATE person RETURN BEFORE`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: BEFORE, + What: []Expr{&Ident{"person"}}, + Echo: BEFORE, + Parallel: true, }}}, }, { sql: `CREATE person RETURN AFTER`, str: `CREATE person`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Echo: AFTER, + Parallel: true, }}}, }, { sql: `CREATE person TIMEOUT 1s`, res: &Query{Statements: []Statement{&CreateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: AFTER, - Timeout: 1 * time.Second, + What: []Expr{&Ident{"person"}}, + Echo: AFTER, + Timeout: 1 * time.Second, + Parallel: true, }}}, }, { @@ -1471,8 +1542,9 @@ func Test_Parse_Queries_Update(t *testing.T) { { sql: `UPDATE person`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1486,17 +1558,19 @@ func Test_Parse_Queries_Update(t *testing.T) { { sql: `UPDATE person SET firstname = VOID`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Void{}}}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Void{}}}}, + Echo: AFTER, + Parallel: true, }}}, }, { sql: `UPDATE person SET firstname = EMPTY`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Empty{}}}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Empty{}}}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1506,9 +1580,10 @@ func Test_Parse_Queries_Update(t *testing.T) { { sql: `UPDATE person SET firstname = "Tobie"`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Value{"Tobie"}}}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"firstname"}, Op: EQ, RHS: &Value{"Tobie"}}}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1526,9 +1601,10 @@ func Test_Parse_Queries_Update(t *testing.T) { { sql: `UPDATE person DIFF []`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &DiffExpression{Data: []interface{}{}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &DiffExpression{Data: []interface{}{}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1546,9 +1622,10 @@ func Test_Parse_Queries_Update(t *testing.T) { { sql: `UPDATE person MERGE {"firstname":"Tobie"}`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &MergeExpression{Data: map[string]interface{}{"firstname": "Tobie"}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &MergeExpression{Data: map[string]interface{}{"firstname": "Tobie"}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1566,9 +1643,10 @@ func Test_Parse_Queries_Update(t *testing.T) { { sql: `UPDATE person CONTENT {"firstname":"Tobie"}`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Data: &ContentExpression{Data: map[string]interface{}{"firstname": "Tobie"}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Data: &ContentExpression{Data: map[string]interface{}{"firstname": "Tobie"}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1578,45 +1656,51 @@ func Test_Parse_Queries_Update(t *testing.T) { { sql: `UPDATE person RETURN NONE`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: NONE, + What: []Expr{&Ident{"person"}}, + Echo: NONE, + Parallel: true, }}}, }, { sql: `UPDATE person RETURN BOTH`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: BOTH, + What: []Expr{&Ident{"person"}}, + Echo: BOTH, + Parallel: true, }}}, }, { sql: `UPDATE person RETURN DIFF`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: DIFF, + What: []Expr{&Ident{"person"}}, + Echo: DIFF, + Parallel: true, }}}, }, { sql: `UPDATE person RETURN BEFORE`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: BEFORE, + What: []Expr{&Ident{"person"}}, + Echo: BEFORE, + Parallel: true, }}}, }, { sql: `UPDATE person RETURN AFTER`, str: `UPDATE person`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Echo: AFTER, + Parallel: true, }}}, }, { sql: `UPDATE person TIMEOUT 1s`, res: &Query{Statements: []Statement{&UpdateStatement{ - What: []Expr{&Ident{"person"}}, - Echo: AFTER, - Timeout: 1 * time.Second, + What: []Expr{&Ident{"person"}}, + Echo: AFTER, + Timeout: 1 * time.Second, + Parallel: true, }}}, }, { @@ -1649,8 +1733,9 @@ func Test_Parse_Queries_Delete(t *testing.T) { { sql: `DELETE person`, res: &Query{Statements: []Statement{&DeleteStatement{ - What: []Expr{&Ident{"person"}}, - Echo: NONE, + What: []Expr{&Ident{"person"}}, + Echo: NONE, + Parallel: true, }}}, }, { @@ -1661,44 +1746,50 @@ func Test_Parse_Queries_Delete(t *testing.T) { sql: `DELETE person RETURN NONE`, str: `DELETE person`, res: &Query{Statements: []Statement{&DeleteStatement{ - What: []Expr{&Ident{"person"}}, - Echo: NONE, + What: []Expr{&Ident{"person"}}, + Echo: NONE, + Parallel: true, }}}, }, { sql: `DELETE person RETURN BOTH`, res: &Query{Statements: []Statement{&DeleteStatement{ - What: []Expr{&Ident{"person"}}, - Echo: BOTH, + What: []Expr{&Ident{"person"}}, + Echo: BOTH, + Parallel: true, }}}, }, { sql: `DELETE person RETURN DIFF`, res: &Query{Statements: []Statement{&DeleteStatement{ - What: []Expr{&Ident{"person"}}, - Echo: DIFF, + What: []Expr{&Ident{"person"}}, + Echo: DIFF, + Parallel: true, }}}, }, { sql: `DELETE person RETURN BEFORE`, res: &Query{Statements: []Statement{&DeleteStatement{ - What: []Expr{&Ident{"person"}}, - Echo: BEFORE, + What: []Expr{&Ident{"person"}}, + Echo: BEFORE, + Parallel: true, }}}, }, { sql: `DELETE person RETURN AFTER`, res: &Query{Statements: []Statement{&DeleteStatement{ - What: []Expr{&Ident{"person"}}, - Echo: AFTER, + What: []Expr{&Ident{"person"}}, + Echo: AFTER, + Parallel: true, }}}, }, { sql: `DELETE person TIMEOUT 1s`, res: &Query{Statements: []Statement{&DeleteStatement{ - What: []Expr{&Ident{"person"}}, - Echo: NONE, - Timeout: 1 * time.Second, + What: []Expr{&Ident{"person"}}, + Echo: NONE, + Timeout: 1 * time.Second, + Parallel: true, }}}, }, { @@ -1743,20 +1834,22 @@ func Test_Parse_Queries_Relate(t *testing.T) { { sql: `RELATE purchase FROM person WITH item`, res: &Query{Statements: []Statement{&RelateStatement{ - Type: &Table{"purchase"}, - From: []Expr{&Ident{"person"}}, - With: []Expr{&Ident{"item"}}, - Echo: AFTER, + Type: &Table{"purchase"}, + From: []Expr{&Ident{"person"}}, + With: []Expr{&Ident{"item"}}, + Echo: AFTER, + Parallel: true, }}}, }, { sql: `RELATE purchase FROM person WITH item UNIQUE`, res: &Query{Statements: []Statement{&RelateStatement{ - Type: &Table{"purchase"}, - From: []Expr{&Ident{"person"}}, - With: []Expr{&Ident{"item"}}, - Uniq: true, - Echo: AFTER, + Type: &Table{"purchase"}, + From: []Expr{&Ident{"person"}}, + With: []Expr{&Ident{"item"}}, + Uniq: true, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1770,11 +1863,12 @@ func Test_Parse_Queries_Relate(t *testing.T) { { sql: `RELATE purchase FROM person WITH item SET public = true`, res: &Query{Statements: []Statement{&RelateStatement{ - Type: &Table{"purchase"}, - From: []Expr{&Ident{"person"}}, - With: []Expr{&Ident{"item"}}, - Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"public"}, Op: EQ, RHS: true}}}, - Echo: AFTER, + Type: &Table{"purchase"}, + From: []Expr{&Ident{"person"}}, + With: []Expr{&Ident{"item"}}, + Data: &DataExpression{Data: []*ItemExpression{{LHS: &Ident{"public"}, Op: EQ, RHS: true}}}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1784,57 +1878,63 @@ func Test_Parse_Queries_Relate(t *testing.T) { { sql: `RELATE purchase FROM person WITH item RETURN NONE`, res: &Query{Statements: []Statement{&RelateStatement{ - Type: &Table{"purchase"}, - From: []Expr{&Ident{"person"}}, - With: []Expr{&Ident{"item"}}, - Echo: NONE, + Type: &Table{"purchase"}, + From: []Expr{&Ident{"person"}}, + With: []Expr{&Ident{"item"}}, + Echo: NONE, + Parallel: true, }}}, }, { sql: `RELATE purchase FROM person WITH item RETURN BOTH`, res: &Query{Statements: []Statement{&RelateStatement{ - Type: &Table{"purchase"}, - From: []Expr{&Ident{"person"}}, - With: []Expr{&Ident{"item"}}, - Echo: BOTH, + Type: &Table{"purchase"}, + From: []Expr{&Ident{"person"}}, + With: []Expr{&Ident{"item"}}, + Echo: BOTH, + Parallel: true, }}}, }, { sql: `RELATE purchase FROM person WITH item RETURN DIFF`, res: &Query{Statements: []Statement{&RelateStatement{ - Type: &Table{"purchase"}, - From: []Expr{&Ident{"person"}}, - With: []Expr{&Ident{"item"}}, - Echo: DIFF, + Type: &Table{"purchase"}, + From: []Expr{&Ident{"person"}}, + With: []Expr{&Ident{"item"}}, + Echo: DIFF, + Parallel: true, }}}, }, { sql: `RELATE purchase FROM person WITH item RETURN BEFORE`, res: &Query{Statements: []Statement{&RelateStatement{ - Type: &Table{"purchase"}, - From: []Expr{&Ident{"person"}}, - With: []Expr{&Ident{"item"}}, - Echo: BEFORE, + Type: &Table{"purchase"}, + From: []Expr{&Ident{"person"}}, + With: []Expr{&Ident{"item"}}, + Echo: BEFORE, + Parallel: true, }}}, }, { sql: `RELATE purchase FROM person WITH item RETURN AFTER`, str: `RELATE purchase FROM person WITH item`, res: &Query{Statements: []Statement{&RelateStatement{ - Type: &Table{"purchase"}, - From: []Expr{&Ident{"person"}}, - With: []Expr{&Ident{"item"}}, - Echo: AFTER, + Type: &Table{"purchase"}, + From: []Expr{&Ident{"person"}}, + With: []Expr{&Ident{"item"}}, + Echo: AFTER, + Parallel: true, }}}, }, { sql: `RELATE purchase FROM person WITH item TIMEOUT 1s`, res: &Query{Statements: []Statement{&RelateStatement{ - Type: &Table{"purchase"}, - From: []Expr{&Ident{"person"}}, - With: []Expr{&Ident{"item"}}, - Echo: AFTER, - Timeout: 1 * time.Second, + Type: &Table{"purchase"}, + From: []Expr{&Ident{"person"}}, + With: []Expr{&Ident{"item"}}, + Echo: AFTER, + Timeout: 1 * time.Second, + Parallel: true, }}}, }, { @@ -1871,9 +1971,10 @@ func Test_Parse_Queries_Insert(t *testing.T) { { sql: `INSERT ["one","two","tre"] INTO person`, res: &Query{Statements: []Statement{&InsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: AFTER, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1883,59 +1984,66 @@ func Test_Parse_Queries_Insert(t *testing.T) { { sql: `INSERT ["one","two","tre"] INTO person RETURN NONE`, res: &Query{Statements: []Statement{&InsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: NONE, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: NONE, + Parallel: true, }}}, }, { sql: `INSERT ["one","two","tre"] INTO person RETURN INFO`, res: &Query{Statements: []Statement{&InsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: INFO, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: INFO, + Parallel: true, }}}, }, { sql: `INSERT ["one","two","tre"] INTO person RETURN BOTH`, res: &Query{Statements: []Statement{&InsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: BOTH, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: BOTH, + Parallel: true, }}}, }, { sql: `INSERT ["one","two","tre"] INTO person RETURN DIFF`, res: &Query{Statements: []Statement{&InsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: DIFF, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: DIFF, + Parallel: true, }}}, }, { sql: `INSERT ["one","two","tre"] INTO person RETURN BEFORE`, res: &Query{Statements: []Statement{&InsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: BEFORE, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: BEFORE, + Parallel: true, }}}, }, { sql: `INSERT ["one","two","tre"] INTO person RETURN AFTER`, str: `INSERT ["one","two","tre"] INTO person`, res: &Query{Statements: []Statement{&InsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: AFTER, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: AFTER, + Parallel: true, }}}, }, { sql: `INSERT ["one","two","tre"] INTO person TIMEOUT 1s`, res: &Query{Statements: []Statement{&InsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: AFTER, - Timeout: 1 * time.Second, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: AFTER, + Timeout: 1 * time.Second, + Parallel: true, }}}, }, { @@ -1972,9 +2080,10 @@ func Test_Parse_Queries_Upsert(t *testing.T) { { sql: `UPSERT ["one","two","tre"] INTO person`, res: &Query{Statements: []Statement{&UpsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: AFTER, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: AFTER, + Parallel: true, }}}, }, { @@ -1984,59 +2093,66 @@ func Test_Parse_Queries_Upsert(t *testing.T) { { sql: `UPSERT ["one","two","tre"] INTO person RETURN NONE`, res: &Query{Statements: []Statement{&UpsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: NONE, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: NONE, + Parallel: true, }}}, }, { sql: `UPSERT ["one","two","tre"] INTO person RETURN INFO`, res: &Query{Statements: []Statement{&UpsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: INFO, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: INFO, + Parallel: true, }}}, }, { sql: `UPSERT ["one","two","tre"] INTO person RETURN BOTH`, res: &Query{Statements: []Statement{&UpsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: BOTH, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: BOTH, + Parallel: true, }}}, }, { sql: `UPSERT ["one","two","tre"] INTO person RETURN DIFF`, res: &Query{Statements: []Statement{&UpsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: DIFF, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: DIFF, + Parallel: true, }}}, }, { sql: `UPSERT ["one","two","tre"] INTO person RETURN BEFORE`, res: &Query{Statements: []Statement{&UpsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: BEFORE, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: BEFORE, + Parallel: true, }}}, }, { sql: `UPSERT ["one","two","tre"] INTO person RETURN AFTER`, str: `UPSERT ["one","two","tre"] INTO person`, res: &Query{Statements: []Statement{&UpsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: AFTER, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: AFTER, + Parallel: true, }}}, }, { sql: `UPSERT ["one","two","tre"] INTO person TIMEOUT 1s`, res: &Query{Statements: []Statement{&UpsertStatement{ - Data: []interface{}{"one", "two", "tre"}, - Into: &Table{"person"}, - Echo: AFTER, - Timeout: 1 * time.Second, + Data: []interface{}{"one", "two", "tre"}, + Into: &Table{"person"}, + Echo: AFTER, + Timeout: 1 * time.Second, + Parallel: true, }}}, }, { @@ -2391,8 +2507,9 @@ func Test_Parse_Queries_Define(t *testing.T) { Name: &Ident{"test"}, Signup: &SubExpression{ Expr: &CreateStatement{ - What: Exprs{&Ident{"person"}}, - Echo: AFTER, + What: Exprs{&Ident{"person"}}, + Echo: AFTER, + Parallel: true, }, }, }}}, @@ -2407,8 +2524,9 @@ func Test_Parse_Queries_Define(t *testing.T) { Name: &Ident{"test"}, Signin: &SubExpression{ Expr: &SelectStatement{ - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Ident{"person"}}, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"person"}}, + Parallel: true, }, }, }}}, @@ -2423,8 +2541,9 @@ func Test_Parse_Queries_Define(t *testing.T) { Name: &Ident{"test"}, Connect: &SubExpression{ Expr: &SelectStatement{ - Expr: []*Field{{Expr: &All{}, Field: "*"}}, - What: []Expr{&Param{"id"}}, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Param{"id"}}, + Parallel: true, }, }, }}}, @@ -2648,7 +2767,8 @@ func Test_Parse_Queries_Define(t *testing.T) { RHS: true, }, }}, - Echo: AFTER, + Echo: AFTER, + Parallel: true, }, }, }, @@ -2675,7 +2795,8 @@ func Test_Parse_Queries_Define(t *testing.T) { RHS: true, }, }}, - Echo: AFTER, + Echo: AFTER, + Parallel: true, }, &UpdateStatement{ What: Exprs{&Param{"this"}}, @@ -2686,7 +2807,8 @@ func Test_Parse_Queries_Define(t *testing.T) { RHS: true, }, }}, - Echo: AFTER, + Echo: AFTER, + Parallel: true, }, }, }, diff --git a/sql/update.go b/sql/update.go index ad2e8662..40fdea90 100644 --- a/sql/update.go +++ b/sql/update.go @@ -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 } diff --git a/sql/upsert.go b/sql/upsert.go index a2c62142..542258d0 100644 --- a/sql/upsert.go +++ b/sql/upsert.go @@ -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 }