diff --git a/go.mod b/go.mod index 5847245225..ebc4b7e651 100644 --- a/go.mod +++ b/go.mod @@ -181,6 +181,6 @@ replace ( cloud.google.com/go/compute/metadata => cloud.google.com/go/compute/metadata v0.1.0 github.com/labstack/echo/v4 => github.com/labstack/echo/v4 v4.6.1 github.com/pingcap/log => github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 - github.com/pingcap/parser => github.com/sjjian/parser v0.0.0-20240119100847-3235e2338d0e + github.com/pingcap/parser => github.com/sjjian/parser v0.0.0-20240126074205-9d5d5dbe3c88 google.golang.org/grpc => google.golang.org/grpc v1.29.0 ) diff --git a/go.sum b/go.sum index 69af3427c2..6e43b0a635 100644 --- a/go.sum +++ b/go.sum @@ -839,8 +839,8 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/sjjian/parser v0.0.0-20240119100847-3235e2338d0e h1:f17wdoGuuBUt0U/YCidu9NIzZeLkkhooIBpODzIKuGs= -github.com/sjjian/parser v0.0.0-20240119100847-3235e2338d0e/go.mod h1:Qq2tnreUXwVo7NAKAHmbWFsgqpDUkxwhJCClY+ZCudA= +github.com/sjjian/parser v0.0.0-20240126074205-9d5d5dbe3c88 h1:ezs0SOvT/fo5qGnLCir2ffIHRkjdAY/zXi4luuylEdM= +github.com/sjjian/parser v0.0.0-20240126074205-9d5d5dbe3c88/go.mod h1:Qq2tnreUXwVo7NAKAHmbWFsgqpDUkxwhJCClY+ZCudA= github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM= github.com/skeema/knownhosts v1.2.0/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= diff --git a/vendor/github.com/pingcap/parser/lexer.go b/vendor/github.com/pingcap/parser/lexer.go index cdb6b68c1d..06659a8a15 100644 --- a/vendor/github.com/pingcap/parser/lexer.go +++ b/vendor/github.com/pingcap/parser/lexer.go @@ -57,7 +57,7 @@ type Scanner struct { // It's used to substring sql in syntax error message. lastScanOffset int - lastScanStartLine int + textStartLine int // lastKeyword records the previous keyword returned by scan(). // determine whether an optimizer hint should be parsed or ignored. @@ -98,12 +98,12 @@ func (s *Scanner) stmtText() string { trimedText := strings.TrimLeftFunc(text, unicode.IsSpace) LFs := strings.Count(trimedText, "\n") - s.lastScanStartLine = s.r.pos().Line - LFs + s.textStartLine = s.r.pos().Line - LFs return text } func (s *Scanner) startLine() int { - return s.lastScanStartLine + return s.textStartLine } // Errorf tells scanner something is wrong. diff --git a/vendor/github.com/pingcap/parser/perfect_parser.go b/vendor/github.com/pingcap/parser/perfect_parser.go index a2ff6717ad..e49d98acaa 100644 --- a/vendor/github.com/pingcap/parser/perfect_parser.go +++ b/vendor/github.com/pingcap/parser/perfect_parser.go @@ -10,18 +10,20 @@ import ( // who contains unparsed SQL, the unparsed SQL will be parses to ast.UnparsedStmt. func (parser *Parser) PerfectParse(sql, charset, collation string) (stmt []ast.StmtNode, warns []error, err error) { _, warns, err = parser.Parse(sql, charset, collation) + stmts := parser.result + parser.updateStartLineWithOffset(stmts) if err == nil { - return parser.result, warns, nil + return stmts, warns, nil } // if err is not nil, the query string must be contains unparsed sql. - if len(parser.result) > 0 { - for _, stmt := range parser.result { + if len(stmts) > 0 { + for _, stmt := range stmts { ast.SetFlag(stmt) } - stmt = append(stmt, parser.result...) + stmt = append(stmt, stmts...) } - + parser.startLineOffset = parser.lexer.r.pos().Line - 1 // The origin SQL text(input args `sql`) consists of many SQL segments, // each SQL segments is a complete SQL and be parsed into `ast.StmtNode`. // @@ -86,6 +88,7 @@ ScanLoop: unparsedSql := unparsedStmtBuf.String() if len(unparsedSql) > 0 { un := &ast.UnparsedStmt{} + un.SetStartLine(parser.startLineOffset + 1) un.SetText(unparsedSql) stmt = append(stmt, un) } @@ -102,3 +105,9 @@ ScanLoop: } return stmt, warns, nil } + +func (parser *Parser) updateStartLineWithOffset(stmts []ast.StmtNode) { + for i := range stmts { + stmts[i].SetStartLine(stmts[i].StartLine() + parser.startLineOffset) + } +} diff --git a/vendor/github.com/pingcap/parser/yy_parser.go b/vendor/github.com/pingcap/parser/yy_parser.go index 35c7a8e7a9..6509c93930 100644 --- a/vendor/github.com/pingcap/parser/yy_parser.go +++ b/vendor/github.com/pingcap/parser/yy_parser.go @@ -74,6 +74,8 @@ type Parser struct { cache []yySymType yylval yySymType yyVAL *yySymType + + startLineOffset int } type stmtTexter interface { diff --git a/vendor/modules.txt b/vendor/modules.txt index 67c5049511..a830bf600e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -554,7 +554,7 @@ github.com/pingcap/errors # github.com/pingcap/log v0.0.0-20210317133921-96f4fcab92a4 => github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 ## explicit; go 1.13 github.com/pingcap/log -# github.com/pingcap/parser v3.0.12+incompatible => github.com/sjjian/parser v0.0.0-20240119100847-3235e2338d0e +# github.com/pingcap/parser v3.0.12+incompatible => github.com/sjjian/parser v0.0.0-20240126074205-9d5d5dbe3c88 ## explicit; go 1.13 github.com/pingcap/parser github.com/pingcap/parser/ast @@ -920,5 +920,5 @@ vitess.io/vitess/go/vt/vtgate/evalengine # cloud.google.com/go/compute/metadata => cloud.google.com/go/compute/metadata v0.1.0 # github.com/labstack/echo/v4 => github.com/labstack/echo/v4 v4.6.1 # github.com/pingcap/log => github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 -# github.com/pingcap/parser => github.com/sjjian/parser v0.0.0-20240119100847-3235e2338d0e +# github.com/pingcap/parser => github.com/sjjian/parser v0.0.0-20240126074205-9d5d5dbe3c88 # google.golang.org/grpc => google.golang.org/grpc v1.29.0