Skip to content

Commit

Permalink
feat(hint): bump parser to v0.2.4 and support multiple stmts hints (#402
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jjeffcaii committed Sep 10, 2022
1 parent 2c89224 commit 4052423
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/arana-db/arana
go 1.18

require (
github.com/arana-db/parser v0.2.3
github.com/arana-db/parser v0.2.4
github.com/bwmarrin/snowflake v0.3.0
github.com/cespare/xxhash/v2 v2.1.2
github.com/dop251/goja v0.0.0-20220422102209-3faab1d8f20e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDH
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/arana-db/parser v0.2.3 h1:zLZcx0/oidlHnw/GZYE78NuvwQkHUv2Xtrm2IwyZasA=
github.com/arana-db/parser v0.2.3/go.mod h1:/XA29bplweWSEAjgoM557ZCzhBilSawUlHcZFjOeDAc=
github.com/arana-db/parser v0.2.4 h1:V08PFVL8G4e6cjFPYLXwSiGCoKZbwRc7+lryidkWCN0=
github.com/arana-db/parser v0.2.4/go.mod h1:/XA29bplweWSEAjgoM557ZCzhBilSawUlHcZFjOeDAc=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
Expand Down
5 changes: 4 additions & 1 deletion pkg/constants/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
package constants

import (
"github.com/stretchr/testify/assert"
"strings"
"testing"
)

import (
"github.com/stretchr/testify/assert"
)

func TestGetConfigSearchPathList(t *testing.T) {
tests := []struct {
name string
Expand Down
5 changes: 4 additions & 1 deletion pkg/constants/mysql/constants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
package mysql

import (
"github.com/stretchr/testify/assert"
"testing"
)

import (
"github.com/stretchr/testify/assert"
)

func TestIsNum(t *testing.T) {
type args struct {
typ uint8
Expand Down
4 changes: 2 additions & 2 deletions pkg/executor/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ func (executor *RedirectExecutor) ExecutorComQuery(ctx *proto.Context) (proto.Re
p := parser.New()
query := ctx.GetQuery()
start := time.Now()
act, hts, err := p.ParseOneStmtHints(query, "", "")
act, err := p.ParseOneStmt(query, "", "")
if err != nil {
return nil, 0, errors.WithStack(err)
}

var hints []*hint.Hint
for _, next := range hts {
for _, next := range act.Hints() {
var h *hint.Hint
if h, err = hint.Parse(next); err != nil {
return nil, 0, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/mysql/execute_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (l *Listener) handlePrepare(c *Conn, ctx *proto.Context) error {
PrepareStmt: query,
}
p := parser.New()
act, hts, err := p.ParseOneStmtHints(stmt.PrepareStmt, "", "")
act, err := p.ParseOneStmt(stmt.PrepareStmt, "", "")
if err != nil {
log.Errorf("Conn %v: Error parsing prepared statement: %v", c, err)
if wErr := c.writeErrorPacketFromError(err); wErr != nil {
Expand All @@ -282,7 +282,7 @@ func (l *Listener) handlePrepare(c *Conn, ctx *proto.Context) error {
}
}

for _, it := range hts {
for _, it := range act.Hints() {
var h *hint.Hint
if h, err = hint.Parse(it); err != nil {
if wErr := c.writeErrorPacketFromError(err); wErr != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/runtime/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ func Parse(sql string, options ...ParseOption) ([]*hint.Hint, Statement, error)
}

p := parser.New()
s, hintStrs, err := p.ParseOneStmtHints(sql, o.charset, o.collation)
s, err := p.ParseOneStmt(sql, o.charset, o.collation)
if err != nil {
return nil, nil, err
}
Expand All @@ -741,6 +741,8 @@ func Parse(sql string, options ...ParseOption) ([]*hint.Hint, Statement, error)
return nil, nil, err
}

hintStrs := s.Hints()

if len(hintStrs) < 1 {
return nil, stmt, nil
}
Expand Down

0 comments on commit 4052423

Please sign in to comment.