Skip to content

Commit

Permalink
New parsers (matrixorigin#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamlinjunhong authored Nov 9, 2021
1 parent 34fcff7 commit 804b172
Show file tree
Hide file tree
Showing 78 changed files with 31,085 additions and 35 deletions.
39 changes: 39 additions & 0 deletions LICENSES/Goyacc-license
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Derived from Inferno's utils/iyacc/yacc.c
http://code.google.com/p/inferno-os/source/browse/utils/iyacc/yacc.c

This copyright NOTICE applies to all files in this directory and
subdirectories, unless another copyright notice appears in a given
file or subdirectory. If you take substantial code from this software to use in
other programs, you must somehow include with it an appropriate
copyright notice that includes the copyright notice and the other
notices below. It is fine (and often tidier) to do that in a separate
file such as NOTICE, LICENCE or COPYING.

Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
Portions Copyright © 1995-1997 C H Forsyth ([email protected])
Portions Copyright © 1997-1999 Vita Nuova Limited
Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
Portions Copyright © 2004,2006 Bruce Ellis
Portions Copyright © 2005-2007 C H Forsyth ([email protected])
Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
Portions Copyright © 2009 The Go Authors. All rights reserved.
Portions Copyright © 2021 The Vitess Authors.
Portions Copyright © 2021 Matrix Origin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 1 addition & 1 deletion pkg/frontend/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/logutil"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/vm/engine"
"github.com/matrixorigin/matrixone/pkg/vm/metadata"
"os"
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"github.com/stretchr/testify/require"
"github.com/matrixorigin/matrixone/pkg/logutil"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"os"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/vm/process"
)

Expand Down
8 changes: 6 additions & 2 deletions pkg/sql/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ package build

import (
"fmt"

"github.com/matrixorigin/matrixone/pkg/errno"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/parsers"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sql/rewrite"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
"github.com/matrixorigin/matrixone/pkg/vm/engine"
"github.com/matrixorigin/matrixone/pkg/vm/process"
Expand All @@ -35,7 +38,8 @@ func New(db string, sql string, e engine.Engine, proc *process.Process) *build {
}

func (b *build) Build() ([]op.OP, error) {
stmts, err := tree.NewParser().Parse(b.sql)
// stmts, err := tree.NewParser().Parse(b.sql)
stmts, err := parsers.Parse(dialect.MYSQL, b.sql)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/errno"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/createDatabase"
"github.com/matrixorigin/matrixone/pkg/sql/op/createTable"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
"github.com/matrixorigin/matrixone/pkg/vm/engine"
"github.com/matrixorigin/matrixone/pkg/vm/metadata"
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/dropDatabase"
"github.com/matrixorigin/matrixone/pkg/sql/op/dropTable"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
)

func (b *build) buildDropTable(stmt *tree.DropTable) (op.OP, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/errno"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/explain"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/colexec/extend"
"github.com/matrixorigin/matrixone/pkg/sql/colexec/extend/overload"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
"go/constant"
"math"
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/errno"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/product"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/group"
"github.com/matrixorigin/matrixone/pkg/sql/op/projection"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
)

Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/build/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/errno"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/insert"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
"github.com/matrixorigin/matrixone/pkg/vm/engine"
"go/constant"
Expand Down Expand Up @@ -512,13 +512,13 @@ func rewriteInsertRows(rel engine.Relation, insertTargets tree.IdentifierList, f
if targetsNil && allRowsNil {
rows[i] = make(tree.Exprs, targetLen)
for j := 0; j < targetLen; j++{
rows[i][j] = tree.NewDefaultVal()
rows[i][j] = tree.NewDefaultVal(nil)
}
}
} else {
// some cases need to fill the missing columns with default values
for len(rows[i]) < targetLen {
rows[i] = append(rows[i], tree.NewDefaultVal())
rows[i] = append(rows[i], tree.NewDefaultVal(nil))
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/op/innerJoin"
"github.com/matrixorigin/matrixone/pkg/sql/op/naturalJoin"
"github.com/matrixorigin/matrixone/pkg/sql/op/product"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/op/order"
"github.com/matrixorigin/matrixone/pkg/sql/op/projection"
"github.com/matrixorigin/matrixone/pkg/sql/op/top"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
)

func (b *build) buildTop(o op.OP, ns tree.OrderBy, limit int64) (op.OP, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/colexec/extend"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/projection"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
"strings"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/op/limit"
"github.com/matrixorigin/matrixone/pkg/sql/op/offset"
"github.com/matrixorigin/matrixone/pkg/sql/op/projection"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/showDatabases"
"github.com/matrixorigin/matrixone/pkg/sql/op/showTables"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/summarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/projection"
"github.com/matrixorigin/matrixone/pkg/sql/op/summarize"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/errno"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/relation"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/build/where.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/colexec/extend"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/restrict"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
)

func (b *build) buildWhere(o op.OP, stmt *tree.Where) (op.OP, error) {
Expand Down
14 changes: 9 additions & 5 deletions pkg/sql/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package compile

import (
"fmt"
"sync"

"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/errno"
Expand Down Expand Up @@ -44,12 +46,13 @@ import (
"github.com/matrixorigin/matrixone/pkg/sql/op/summarize"
"github.com/matrixorigin/matrixone/pkg/sql/op/top"
"github.com/matrixorigin/matrixone/pkg/sql/opt"
"github.com/matrixorigin/matrixone/pkg/sql/parsers"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
rw "github.com/matrixorigin/matrixone/pkg/sql/rewrite"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sqlerror"
"github.com/matrixorigin/matrixone/pkg/vm/engine"
"github.com/matrixorigin/matrixone/pkg/vm/process"
"sync"
)

func New(db string, sql string, uid string,
Expand All @@ -65,15 +68,16 @@ func New(db string, sql string, uid string,

// Build generates query execution list based on the result of sql parser.
func (c *compile) Build() ([]*Exec, error) {
stmts, err := tree.NewParser().Parse(c.sql)
// stmts, err := tree.NewParser().Parse(c.sql)
stmts, err := parsers.Parse(dialect.MYSQL, c.sql)
if err != nil {
return nil, err
}
es := make([]*Exec, len(stmts))
for i, stmt := range stmts {
es[i] = &Exec{
c: c,
stmt: stmt,
c: c,
stmt: stmt,
affectRows: 0,
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/compile/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/sql/op"
"github.com/matrixorigin/matrixone/pkg/sql/op/relation"
"github.com/matrixorigin/matrixone/pkg/sql/tree"
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
"github.com/matrixorigin/matrixone/pkg/vm"
"github.com/matrixorigin/matrixone/pkg/vm/engine"
"github.com/matrixorigin/matrixone/pkg/vm/metadata"
Expand Down
15 changes: 15 additions & 0 deletions pkg/sql/parsers/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: all
all: mysql postgresql

.PHONY: mysql
mysql:
@cd dialect/mysql && make

.PHONY: postgresql
postgresql:
@cd dialect/postgresql && make

.PHONY: clean
clean:
@cd dialect/mysql && make clean
@cd dialect/postgresql && make clean
Loading

0 comments on commit 804b172

Please sign in to comment.