Skip to content

Commit

Permalink
Merge pull request #2722 from actiontech/fix-fingerprint-panic-ce
Browse files Browse the repository at this point in the history
use util.Fingerprint to fix panic ce
  • Loading branch information
winfredLIN authored Oct 29, 2024
2 parents f2d33a5 + e6bc8a0 commit 3802127
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions sqle/driver/mysql/util/parser_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ func TestFingerprint(t *testing.T) {
input: "select * from tb1 where a='my_db' and b='test1'# this is a comment",
expect: "SELECT * FROM `tb1` WHERE `a`=? AND `b`=?",
},
// not sql
{
input: "SELECT*FROM (SELECT * FROM tb values(1));",
expect: "SELECT*FROM (SELECT * FROM tb values(1));",
},
{
input: "not sql",
expect: "not sql",
},
// https://github.com/actiontech/sqle/issues/2603
{
input: "insert into tb values(1)",
expect: "INSERT INTO `tb` VALUES (?)",
},
}
for _, c := range cases {
testFingerprint(t, c.input, c.expect)
Expand Down
8 changes: 6 additions & 2 deletions sqle/pkg/driver/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"fmt"
"time"

"github.com/actiontech/sqle/sqle/driver/mysql/util"
driverV2 "github.com/actiontech/sqle/sqle/driver/v2"
"github.com/actiontech/sqle/sqle/pkg/params"
"github.com/actiontech/sqle/sqle/utils"
hclog "github.com/hashicorp/go-hclog"

"github.com/percona/go-mysql/query"
"github.com/pkg/errors"
"vitess.io/vitess/go/vt/sqlparser"
)
Expand Down Expand Up @@ -200,10 +200,14 @@ func (p *DriverImpl) Parse(ctx context.Context, sql string) ([]driverV2.Node, er

nodes := make([]driverV2.Node, 0, len(sqls))
for _, sql := range sqls {
fp, err := util.Fingerprint(sql, true)
if err != nil {
return nil, errors.Wrapf(err, "fingerprint of sql: %s", sql)
}
n := driverV2.Node{
Text: sql,
Type: classifySQL(sql),
Fingerprint: query.Fingerprint(sql),
Fingerprint: fp,
}
nodes = append(nodes, n)
}
Expand Down

0 comments on commit 3802127

Please sign in to comment.