Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor(parser): use exclusive End.Column for statement positions (#18671)
h3n4lae285a23fb85
diff --git a/backend/common/position.go b/backend/common/position.goindex 917dc7658d..de5f459304 100644--- a/backend/common/position.go+++ b/backend/common/position.go@@ -78,3 +78,18 @@ func ConvertTiDBParserErrorPositionToPosition(line, column int) *storepb.PositioColumn: int32(column),}}++// ConvertANTLRTokenToExclusiveEndPosition converts an ANTLR token position to an exclusive end Position.+// The end token's line and column (0-based) plus its text are used to calculate where the position+// should point to (after the last character of the token).+// This is used for Statement.End which should use exclusive semantics (pointing after the last character).+func ConvertANTLRTokenToExclusiveEndPosition(line int32, column int32, tokenText string) *storepb.Position {+ tokenCharLength := int32(len([]rune(tokenText)))+ // For exclusive end, we simply add the token length to the column.+ // The column is 0-based in ANTLR, so we add 1 to convert to 1-based.+ // The result points to the position AFTER the last character of the token.+ return &storepb.Position{+ Line: line,+ Column: column + tokenCharLength + 1,+ }+}diff --git a/backend/plugin/parser/base/lexer.go b/backend/plugin/parser/base/lexer.goindex a62cb9ce7a..a1553b568f 100644--- a/backend/plugin/parser/base/lexer.go+++ b/backend/plugin/parser/base/lexer.go@@ -104,17 +104,20 @@ func SplitSQLByLexer(stream *antlr.CommonTokenStream, semiTokenType int, stateme// Get the position of the first default channel token for Start positionantlrPosition := FirstDefaultChannelTokenPosition(buf)+ // Use the last token in the buffer for End position (not EOF token when at end of stream)+ lastToken := buf[len(buf)-1]sqls = append(sqls, Statement{Text: bufStr.String(),BaseLine: buf[0].GetLine() - 1, // BaseLine is the offset of the first tokenRange: &storepb.Range{Start: int32(buf[0].GetStart()),- End: int32(buf[len(buf)-1].GetStop() + 1),+ End: int32(lastToken.GetStop() + 1),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(token.GetLine()),- Column: int32(token.GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(lastToken.GetLine()),+ int32(lastToken.GetColumn()),+ lastToken.GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: empty,})diff --git a/backend/plugin/parser/base/statement.go b/backend/plugin/parser/base/statement.goindex a2a6c2fa56..3ef3a982d6 100644--- a/backend/plugin/parser/base/statement.go+++ b/backend/plugin/parser/base/statement.go@@ -17,7 +17,8 @@ type Statement struct {// Start is the inclusive start position of the SQL in the original SQL (1-based).Start *storepb.Position- // End is the inclusive end position of the SQL in the original SQL (1-based).+ // End is the exclusive end position of the SQL in the original SQL (1-based).+ // It points to the position AFTER the last character of the statement.End *storepb.Position// Range is the byte offset range of the SQL in the original SQL.diff --git a/backend/plugin/parser/bigquery/split.go b/backend/plugin/parser/bigquery/split.goindex 71aa0e828d..0a86d05160 100644--- a/backend/plugin/parser/bigquery/split.go+++ b/backend/plugin/parser/bigquery/split.go@@ -50,10 +50,11 @@ func SplitSQL(statement string) ([]base.Statement, error) {Start: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(buf[len(buf)-1].GetLine()),- Column: int32(buf[len(buf)-1].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(buf[len(buf)-1].GetLine()),+ int32(buf[len(buf)-1].GetColumn()),+ buf[len(buf)-1].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: empty,})diff --git a/backend/plugin/parser/bigquery/split_test.go b/backend/plugin/parser/bigquery/split_test.goindex 262486dd72..995499b03e 100644--- a/backend/plugin/parser/bigquery/split_test.go+++ b/backend/plugin/parser/bigquery/split_test.go@@ -28,7 +28,7 @@ func TestBigQuerySplitMultiSQL(t *testing.T) {Text: "SELECT 1",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 8},+ End: &storepb.Position{Line: 1, Column: 9},Empty: false,Range: &storepb.Range{Start: 0, End: 8},},@@ -43,7 +43,7 @@ func TestBigQuerySplitMultiSQL(t *testing.T) {Text: "SELECT 1;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 9},+ End: &storepb.Position{Line: 1, Column: 10},Empty: false,Range: &storepb.Range{Start: 0, End: 9},},@@ -51,7 +51,7 @@ func TestBigQuerySplitMultiSQL(t *testing.T) {Text: "\n SELECT\n 33;",BaseLine: 0,Start: &storepb.Position{Line: 2, Column: 2},- End: &storepb.Position{Line: 3, Column: 4},+ End: &storepb.Position{Line: 3, Column: 5},Empty: false,Range: &storepb.Range{Start: 9, End: 22},},diff --git a/backend/plugin/parser/cassandra/split_test.go b/backend/plugin/parser/cassandra/split_test.goindex e34e64c53a..337d3f7b7e 100644--- a/backend/plugin/parser/cassandra/split_test.go+++ b/backend/plugin/parser/cassandra/split_test.go@@ -19,7 +19,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 0, End: 20},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 20},+ End: &storepb.Position{Line: 1, Column: 21},Empty: false,},{@@ -27,7 +27,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 20, End: 43},Start: &storepb.Position{Line: 2, Column: 2},- End: &storepb.Position{Line: 2, Column: 22},+ End: &storepb.Position{Line: 2, Column: 23},Empty: false,},{@@ -35,7 +35,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 1,Range: &storepb.Range{Start: 43, End: 68},Start: &storepb.Position{Line: 3, Column: 2},- End: &storepb.Position{Line: 3, Column: 24},+ End: &storepb.Position{Line: 3, Column: 25},Empty: false,},}diff --git a/backend/plugin/parser/doris/split_test.go b/backend/plugin/parser/doris/split_test.goindex 0a7750cc9b..bf407444f4 100644--- a/backend/plugin/parser/doris/split_test.go+++ b/backend/plugin/parser/doris/split_test.go@@ -23,7 +23,7 @@ func TestSplitDorisSQLStatements(t *testing.T) {Text: "SELECT 1;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 9},+ End: &storepb.Position{Line: 1, Column: 10},Range: &storepb.Range{Start: 0, End: 9},},},@@ -36,14 +36,14 @@ func TestSplitDorisSQLStatements(t *testing.T) {Text: "SELECT 1;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 9},+ End: &storepb.Position{Line: 1, Column: 10},Range: &storepb.Range{Start: 0, End: 9},},{Text: " SELECT 2;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 11},- End: &storepb.Position{Line: 1, Column: 19},+ End: &storepb.Position{Line: 1, Column: 20},Range: &storepb.Range{Start: 9, End: 19},},},@@ -56,7 +56,7 @@ func TestSplitDorisSQLStatements(t *testing.T) {Text: "SELECT\n 1;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 2, Column: 4},+ End: &storepb.Position{Line: 2, Column: 5},Range: &storepb.Range{Start: 0, End: 11},},},@@ -69,14 +69,14 @@ func TestSplitDorisSQLStatements(t *testing.T) {Text: "SELECT 1;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 9},+ End: &storepb.Position{Line: 1, Column: 10},Range: &storepb.Range{Start: 0, End: 9},},{Text: "\nSELECT 2;",BaseLine: 0,Start: &storepb.Position{Line: 2, Column: 1},- End: &storepb.Position{Line: 2, Column: 9},+ End: &storepb.Position{Line: 2, Column: 10},Range: &storepb.Range{Start: 9, End: 19},},},diff --git a/backend/plugin/parser/mysql/completion.go b/backend/plugin/parser/mysql/completion.goindex f1d3ae9252..d76f3a1fc3 100644--- a/backend/plugin/parser/mysql/completion.go+++ b/backend/plugin/parser/mysql/completion.go@@ -1236,9 +1236,15 @@ func skipHeadingSQLs(statement string, caretLine int, caretOffset int) (string,start := 0for i, sql := range list {// Both caretLine and End.Line are 1-based+ // End.Column is 1-based exclusive (points after the last character)+ // caretOffset is 0-basedsqlEndLine := int(sql.End.GetLine())sqlEndColumn := int(sql.End.GetColumn())- if sqlEndLine > caretLine || (sqlEndLine == caretLine && sqlEndColumn >= caretOffset) {+ // Use > for End.Column comparison because it's exclusive (points after last char)+ // A 0-based offset of N corresponds to 1-based position N+1+ // Exclusive End.Column of N means last char is at 1-based position N-1 (0-based N-2)+ // So caret is in this statement if: sqlEndColumn > caretOffset+1, i.e., sqlEndColumn > caretOffset+ if sqlEndLine > caretLine || (sqlEndLine == caretLine && sqlEndColumn > caretOffset) {start = iif i == 0 {// The caret is in the first SQL statement, so we don't need to skip any SQL statements.@@ -1250,7 +1256,9 @@ func skipHeadingSQLs(statement string, caretLine int, caretOffset int) (string,if caretLine == previousSQLEndLine {// The caret is in the same line as the last line of the previous SQL statement.// We need to adjust the caret offset.- newCaretOffset = caretOffset - previousSQLEndColumn+ // previousSQLEndColumn is 1-based exclusive, caretOffset is 0-based+ // New offset = caretOffset - (previousSQLEndColumn - 1) = caretOffset - previousSQLEndColumn + 1+ newCaretOffset = caretOffset - previousSQLEndColumn + 1}break}diff --git a/backend/plugin/parser/mysql/split.go b/backend/plugin/parser/mysql/split.goindex e8b86781de..84a5e1885d 100644--- a/backend/plugin/parser/mysql/split.go+++ b/backend/plugin/parser/mysql/split.go@@ -76,10 +76,11 @@ func splitDelimiterModeSQL(stream *antlr.CommonTokenStream, statement string) ([Start: int32(stmtStartByte),End: int32(stmtEndByte),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[i].GetLine()),- Column: int32(tokens[i].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[i].GetLine()),+ int32(tokens[i].GetColumn()),+ tokens[i].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:i+1], parser.MySQLLexerSEMICOLON_SYMBOL),})@@ -113,10 +114,11 @@ func splitDelimiterModeSQL(stream *antlr.CommonTokenStream, statement string) ([Start: int32(stmtStartByte),End: int32(stmtEndByte),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[newStart-1].GetLine()),- Column: int32(tokens[newStart-1].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[newStart-1].GetLine()),+ int32(tokens[newStart-1].GetColumn()),+ tokens[newStart-1].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:i], parser.MySQLLexerSEMICOLON_SYMBOL),})@@ -148,10 +150,11 @@ func splitDelimiterModeSQL(stream *antlr.CommonTokenStream, statement string) ([Start: int32(stmtStartByte),End: int32(stmtEndByte),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[endPos-1].GetLine()),- Column: int32(tokens[endPos-1].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[endPos-1].GetLine()),+ int32(tokens[endPos-1].GetColumn()),+ tokens[endPos-1].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:endPos], parser.MySQLLexerSEMICOLON_SYMBOL),})@@ -248,10 +251,11 @@ func splitByParser(statement string, lexer *parser.MySQLLexer, stream *antlr.ComStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:pos+1], parser.MySQLLexerSEMICOLON_SYMBOL),})@@ -274,10 +278,11 @@ func splitByParser(statement string, lexer *parser.MySQLLexer, stream *antlr.ComStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[eofPos-1].GetLine()),- Column: int32(tokens[eofPos-1].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[eofPos-1].GetLine()),+ int32(tokens[eofPos-1].GetColumn()),+ tokens[eofPos-1].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:eofPos], parser.MySQLLexerSEMICOLON_SYMBOL),})@@ -442,10 +447,11 @@ func splitMySQLStatement(stream *antlr.CommonTokenStream, statement string) ([]bStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:pos+1], parser.MySQLLexerSEMICOLON_SYMBOL),})@@ -468,10 +474,11 @@ func splitMySQLStatement(stream *antlr.CommonTokenStream, statement string) ([]bStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[eofPos-1].GetLine()),- Column: int32(tokens[eofPos-1].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[eofPos-1].GetLine()),+ int32(tokens[eofPos-1].GetColumn()),+ tokens[eofPos-1].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:eofPos], parser.MySQLLexerSEMICOLON_SYMBOL),})diff --git a/backend/plugin/parser/mysql/split_test.go b/backend/plugin/parser/mysql/split_test.goindex afc9356988..414774fce3 100644--- a/backend/plugin/parser/mysql/split_test.go+++ b/backend/plugin/parser/mysql/split_test.go@@ -66,14 +66,14 @@ func TestMySQLSplitMultiSQL(t *testing.T) {END;`,BaseLine: 2,Start: &storepb.Position{Line: 3, Column: 4},- End: &storepb.Position{Line: 10, Column: 8},+ End: &storepb.Position{Line: 10, Column: 9},Range: &storepb.Range{Start: 17, End: 175},},{Text: ` CALL dorepeat(1000);`,BaseLine: 11,Start: &storepb.Position{Line: 12, Column: 4},- End: &storepb.Position{Line: 12, Column: 23},+ End: &storepb.Position{Line: 12, Column: 24},Range: &storepb.Range{Start: 191, End: 214},},{@@ -81,7 +81,7 @@ func TestMySQLSplitMultiSQL(t *testing.T) {SELECT x;`,BaseLine: 11,Start: &storepb.Position{Line: 13, Column: 4},- End: &storepb.Position{Line: 13, Column: 12},+ End: &storepb.Position{Line: 13, Column: 13},Range: &storepb.Range{Start: 214, End: 227},},{@@ -89,7 +89,7 @@ func TestMySQLSplitMultiSQL(t *testing.T) {BaseLine: 12,// TODO(zp): Wait, but why the start position is larger than the end position?Start: &storepb.Position{Line: 14, Column: 4},- End: &storepb.Position{Line: 14, Column: 3},+ End: &storepb.Position{Line: 14, Column: 4},Empty: true,Range: &storepb.Range{Start: 227, End: 231},},@@ -308,14 +308,14 @@ func TestMySQLSplitMultiSQL(t *testing.T) {)FROM t;`,Start: &storepb.Position{Line: 2, Column: 4},- End: &storepb.Position{Line: 103, Column: 10},+ End: &storepb.Position{Line: 103, Column: 11},Range: &storepb.Range{Start: 0, End: 1080},},{Text: " SELECT * FROM t;",BaseLine: 102,Start: &storepb.Position{Line: 103, Column: 12},- End: &storepb.Position{Line: 103, Column: 27},+ End: &storepb.Position{Line: 103, Column: 28},Range: &storepb.Range{Start: 1080, End: 1097},},},@@ -328,13 +328,13 @@ func TestMySQLSplitMultiSQL(t *testing.T) {{Text: `select * from t;`,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 16},+ End: &storepb.Position{Line: 1, Column: 17},Range: &storepb.Range{Start: 0, End: 16},},{Text: `select "\"" where true;`,Start: &storepb.Position{Line: 1, Column: 17},- End: &storepb.Position{Line: 1, Column: 39},+ End: &storepb.Position{Line: 1, Column: 40},Range: &storepb.Range{Start: 16, End: 39},},},@@ -349,7 +349,7 @@ func TestMySQLSplitMultiSQL(t *testing.T) {{Text: "-- klsjdfjasldf\n\t\t\t-- klsjdflkjaskldfj\n",Start: &storepb.Position{Line: 3, Column: 1},- End: &storepb.Position{Line: 2, Column: 23},+ End: &storepb.Position{Line: 2, Column: 24},Empty: true,Range: &storepb.Range{Start: 0, End: 39},},@@ -363,15 +363,14 @@ func TestMySQLSplitMultiSQL(t *testing.T) {res: []base.Statement{{Text: `select * from t;`,- End: &storepb.Position{Line: 1, Column: 16},+ End: &storepb.Position{Line: 1, Column: 17},Start: &storepb.Position{Line: 1, Column: 1},Range: &storepb.Range{Start: 0, End: 16},},{- Text: "\n\t\t\t/* sdfasdf */",- // TODO(zp): Wait, but why the start position is larger than the end position?- End: &storepb.Position{Line: 2, Column: 4},+ Text: "\n\t\t\t/* sdfasdf */",Start: &storepb.Position{Line: 2, Column: 17},+ End: &storepb.Position{Line: 2, Column: 17},Empty: true,Range: &storepb.Range{Start: 16, End: 33},},@@ -387,12 +386,12 @@ func TestMySQLSplitMultiSQL(t *testing.T) {{Text: `select * from t;`,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 16},+ End: &storepb.Position{Line: 1, Column: 17},Range: &storepb.Range{Start: 0, End: 16},},{Text: "\n\t\t\t/* sdfasdf */;",- End: &storepb.Position{Line: 2, Column: 17},+ End: &storepb.Position{Line: 2, Column: 18},Start: &storepb.Position{Line: 2, Column: 17},Empty: true,Range: &storepb.Range{Start: 16, End: 34},@@ -400,7 +399,7 @@ func TestMySQLSplitMultiSQL(t *testing.T) {{Text: "\n\t\t\tselect * from t;",BaseLine: 1,- End: &storepb.Position{Line: 3, Column: 19},+ End: &storepb.Position{Line: 3, Column: 20},Start: &storepb.Position{Line: 3, Column: 4},Range: &storepb.Range{Start: 34, End: 54},},@@ -440,7 +439,7 @@ func TestMySQLSplitMultiSQL(t *testing.T) {END ;`,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 14, Column: 7},+ End: &storepb.Position{Line: 14, Column: 8},Range: &storepb.Range{Start: 0, End: 268},},},@@ -453,7 +452,7 @@ func TestMySQLSplitMultiSQL(t *testing.T) {{Text: bigSQL,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: int32(len(bigSQL))},+ End: &storepb.Position{Line: 1, Column: int32(len(bigSQL) + 1)},Range: &storepb.Range{Start: 0, End: int32(len(bigSQL))},},},@@ -466,13 +465,13 @@ func TestMySQLSplitMultiSQL(t *testing.T) {{Text: " CREATE TABLE t(a int);",Start: &storepb.Position{Line: 1, Column: 5},- End: &storepb.Position{Line: 1, Column: 26},+ End: &storepb.Position{Line: 1, Column: 27},Range: &storepb.Range{Start: 0, End: 26},},{Text: " CREATE TABLE t1(a int)",Start: &storepb.Position{Line: 1, Column: 28},- End: &storepb.Position{Line: 1, Column: 49},+ End: &storepb.Position{Line: 1, Column: 50},Range: &storepb.Range{Start: 26, End: 49},},},@@ -486,13 +485,13 @@ func TestMySQLSplitMultiSQL(t *testing.T) {{Text: "CREATE TABLE `tech_Book`(id int, name varchar(255));",Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 52},+ End: &storepb.Position{Line: 1, Column: 53},Range: &storepb.Range{Start: 0, End: 52},},{Text: "\nINSERT INTO `tech_Book` VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafa\\'jdfl;\"ka');",Start: &storepb.Position{Line: 2, Column: 1},- End: &storepb.Position{Line: 2, Column: 78},+ End: &storepb.Position{Line: 2, Column: 79},Range: &storepb.Range{Start: 52, End: 131},},},@@ -511,21 +510,21 @@ func TestMySQLSplitMultiSQL(t *testing.T) {{Text: "\n\t\t\t\t\t\t/* this is the comment. */\n\t\t\t\t\t\tCREATE /* inline comment */TABLE tech_Book(id int, name varchar(255));",Start: &storepb.Position{Line: 3, Column: 7},- End: &storepb.Position{Line: 3, Column: 76},+ End: &storepb.Position{Line: 3, Column: 77},Range: &storepb.Range{Start: 0, End: 110},},{Text: "\n\t\t\t\t\t\t-- this is the comment.\n\t\t\t\t\t\tINSERT INTO tech_Book VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafa\\'jdfl;\"ka');",Start: &storepb.Position{Line: 5, Column: 7},BaseLine: 2,- End: &storepb.Position{Line: 5, Column: 82},+ End: &storepb.Position{Line: 5, Column: 83},Range: &storepb.Range{Start: 110, End: 223},},{Text: "\n\t\t\t\t\t\t# this is the comment.\n\t\t\t\t\t\tINSERT INTO tech_Book VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafa\\'jdfl;\"ka');",BaseLine: 4,Start: &storepb.Position{Line: 7, Column: 7},- End: &storepb.Position{Line: 7, Column: 82},+ End: &storepb.Position{Line: 7, Column: 83},Range: &storepb.Range{Start: 223, End: 335},},},@@ -547,21 +546,21 @@ func TestMySQLSplitMultiSQL(t *testing.T) {{Text: "# test for defining stored programs\n\t\t\t\t\t\tCREATE PROCEDURE dorepeat(p1 INT)\n\t\t\t\t\t\tBEGIN\n\t\t\t\t\t\t\tSET @x = 0;\n\t\t\t\t\t\t\tREPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;\n\t\t\t\t\t\tEND\n\t\t\t\t\t\t;",Start: &storepb.Position{Line: 2, Column: 7},- End: &storepb.Position{Line: 7, Column: 7},+ End: &storepb.Position{Line: 7, Column: 8},Range: &storepb.Range{Start: 0, End: 181},},{Text: "\n\t\t\t\t\t\tCALL dorepeat(1000);",BaseLine: 6,Start: &storepb.Position{Line: 8, Column: 7},- End: &storepb.Position{Line: 8, Column: 26},+ End: &storepb.Position{Line: 8, Column: 27},Range: &storepb.Range{Start: 181, End: 208},},{Text: "\n\t\t\t\t\t\tSELECT @x;",BaseLine: 7,Start: &storepb.Position{Line: 9, Column: 7},- End: &storepb.Position{Line: 9, Column: 16},+ End: &storepb.Position{Line: 9, Column: 17},Range: &storepb.Range{Start: 208, End: 225},},{@@ -569,7 +568,7 @@ func TestMySQLSplitMultiSQL(t *testing.T) {BaseLine: 8,Start: &storepb.Position{Line: 10, Column: 7},// TODO(zp): Wait, but why the start position is larger than the end position?- End: &storepb.Position{Line: 10, Column: 6},+ End: &storepb.Position{Line: 10, Column: 7},Empty: true,Range: &storepb.Range{Start: 225, End: 232},},@@ -592,7 +591,7 @@ func TestMySQLSplitMultiSQL(t *testing.T) {res: []base.Statement{{Text: "# test for defining stored programs\n\t\t\t\t\t\tCREATE PROCEDURE dorepeat(p1 INT)\n\t\t\t\t\t\t/* This is a comment */\n\t\t\t\t\t\tBEGIN\n\t\t\t\t\t\t\tSET @x = 0;\n\t\t\t\t\t\t\tREPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;\n\t\t\t\t\t\tEND\n\t\t\t\t\t\t;",- End: &storepb.Position{Line: 8, Column: 7},+ End: &storepb.Position{Line: 8, Column: 8},Start: &storepb.Position{Line: 2, Column: 7},Range: &storepb.Range{Start: 0, End: 211},},@@ -600,21 +599,21 @@ func TestMySQLSplitMultiSQL(t *testing.T) {Text: "\n\t\t\t\t\t\tCALL dorepeat(1000);",BaseLine: 7,Start: &storepb.Position{Line: 9, Column: 7},- End: &storepb.Position{Line: 9, Column: 26},+ End: &storepb.Position{Line: 9, Column: 27},Range: &storepb.Range{Start: 211, End: 238},},{Text: "\n\t\t\t\t\t\tSELECT @x;",BaseLine: 8,Start: &storepb.Position{Line: 10, Column: 7},- End: &storepb.Position{Line: 10, Column: 16},+ End: &storepb.Position{Line: 10, Column: 17},Range: &storepb.Range{Start: 238, End: 255},},{Text: "\n\t\t\t\t\t\t",BaseLine: 9,Start: &storepb.Position{Line: 11, Column: 7},- End: &storepb.Position{Line: 11, Column: 6},+ End: &storepb.Position{Line: 11, Column: 7},Empty: true,Range: &storepb.Range{Start: 255, End: 262},},@@ -630,14 +629,14 @@ func TestMySQLSplitMultiSQL(t *testing.T) {Text: "CREATE TABLE t\r\n(a int);",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 2, Column: 8},+ End: &storepb.Position{Line: 2, Column: 9},Range: &storepb.Range{Start: 0, End: 24},},{Text: "\r\nCREATE TABLE t1(b int);",BaseLine: 1,Start: &storepb.Position{Line: 3, Column: 1},- End: &storepb.Position{Line: 3, Column: 23},+ End: &storepb.Position{Line: 3, Column: 24},Range: &storepb.Range{Start: 24, End: 49},},},@@ -651,13 +650,13 @@ func TestMySQLSplitMultiSQL(t *testing.T) {Text: "SELECT * FROM 表名;",Range: &storepb.Range{Start: 0, End: 21}, // Byte offset 0-21 (not 0-17)Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 17},+ End: &storepb.Position{Line: 1, Column: 18},},{Text: " INSERT INTO 表 VALUES (1);",Range: &storepb.Range{Start: 21, End: 49}, // Byte offset 21-49 (not 17-43)Start: &storepb.Position{Line: 1, Column: 19},- End: &storepb.Position{Line: 1, Column: 43},+ End: &storepb.Position{Line: 1, Column: 44},},},},diff --git a/backend/plugin/parser/mysql/test-data/test_backup.yaml b/backend/plugin/parser/mysql/test-data/test_backup.yamlindex cb3f4594ea..08ba863637 100644--- a/backend/plugin/parser/mysql/test-data/test_backup.yaml+++ b/backend/plugin/parser/mysql/test-data/test_backup.yaml@@ -51,7 +51,7 @@column: 1endposition:line: 18- column: 78+ column: 79- input: |-WITH t_cte AS (SELECT * FROM test WHERE test.b1 > 10@@ -70,7 +70,7 @@column: 1endposition:line: 3- column: 66+ column: 67- input: |-WITH t_cte AS (SELECT * FROM test WHERE test.b1 > 10@@ -89,7 +89,7 @@column: 1endposition:line: 3- column: 62+ column: 63- input: |-UPDATE test SET test.c1 = 1 WHERE test.b1 = 1;UPDATE test SET test.c1 = 2 WHERE test.b1 = 2;@@ -122,7 +122,7 @@column: 1endposition:line: 7- column: 46+ column: 47- input: UPDATE t_generated SET a = 1 WHERE a = 2;result:- statement: |-@@ -136,7 +136,7 @@column: 1endposition:line: 1- column: 41+ column: 42- input: |-UPDATE db1.t1 SET c1 = 1 WHERE c1 = 2;UPDATE db2.t2 SET c1 = 1 WHERE c1 = 2;@@ -152,7 +152,7 @@column: 1endposition:line: 1- column: 38+ column: 39- statement: |-CREATE TABLE `backupDB`.`_rollback_t2_db2` LIKE `db2`.`t2`;INSERT INTO `backupDB`.`_rollback_t2_db2` SELECT `t2`.* FROM db2.t2 WHERE c1 = 2;@@ -164,7 +164,7 @@column: 1endposition:line: 2- column: 38+ column: 39- input: DELETE test FROM test, test2 as t2 where test.id = t2.id;result:- statement: |-@@ -178,7 +178,7 @@column: 1endposition:line: 1- column: 57+ column: 58- input: DELETE t1, t2 FROM test as t1, test2 as t2 WHERE t1.id = t2.id;result:- statement: |-@@ -192,7 +192,7 @@column: 1endposition:line: 1- column: 63+ column: 64- statement: |-CREATE TABLE `backupDB`.`_rollback_test_db` LIKE `db`.`test`;INSERT INTO `backupDB`.`_rollback_test_db` SELECT `t1`.* FROM test as t1, test2 as t2 WHERE t1.id = t2.id;@@ -204,7 +204,7 @@column: 1endposition:line: 1- column: 63+ column: 64- input: DELETE FROM t1, t2 USING test as t1, test2 as t2 WHERE t1.id = t2.id;result:- statement: |-@@ -218,7 +218,7 @@column: 1endposition:line: 1- column: 69+ column: 70- statement: |-CREATE TABLE `backupDB`.`_rollback_test_db` LIKE `db`.`test`;INSERT INTO `backupDB`.`_rollback_test_db` SELECT `t1`.* FROM test as t1, test2 as t2 WHERE t1.id = t2.id;@@ -230,7 +230,7 @@column: 1endposition:line: 1- column: 69+ column: 70- input: DELETE FROM test as t1 WHERE t1.c1 = 1;result:- statement: |-@@ -244,7 +244,7 @@column: 1endposition:line: 1- column: 39+ column: 40- input: DELETE FROM test WHERE c1 = 1;result:- statement: |-@@ -258,7 +258,7 @@column: 1endposition:line: 1- column: 30+ column: 31- input: UPDATE test x SET x.c1 = 1 WHERE x.c1 = 1result:- statement: |-@@ -272,7 +272,7 @@column: 1endposition:line: 1- column: 41+ column: 42- input: UPDATE test SET c1 = 1 WHERE c1=2;result:- statement: |-@@ -286,7 +286,7 @@column: 1endposition:line: 1- column: 34+ column: 35- input: UPDATE test t1, test2 t2 SET t1.c1 = 1 WHERE t1.c1 = t2.c1;result:- statement: |-@@ -300,7 +300,7 @@column: 1endposition:line: 1- column: 59+ column: 60- input: UPDATE test t1, test2 t2 SET t1.c1 = 1, t2.c2 = 2 WHERE t1.c1 = t2.c1;result:- statement: |-@@ -314,7 +314,7 @@column: 1endposition:line: 1- column: 70+ column: 71- statement: |-CREATE TABLE `backupDB`.`_rollback_test_db` LIKE `db`.`test`;INSERT INTO `backupDB`.`_rollback_test_db` SELECT `t1`.* FROM test t1, test2 t2 WHERE t1.c1 = t2.c1;@@ -326,7 +326,7 @@column: 1endposition:line: 1- column: 70+ column: 71- input: |-UPDATE test t1 SET t1.c1 = 2 WHERE t1.c1 = 1 ;UPDATE test t2 SET t2.c1 = 3 WHERE t2.c1 = 5 ;@@ -344,4 +344,4 @@column: 1endposition:line: 2- column: 46+ column: 47diff --git a/backend/plugin/parser/partiql/split_test.go b/backend/plugin/parser/partiql/split_test.goindex 65bce56ce2..47868d90fe 100644--- a/backend/plugin/parser/partiql/split_test.go+++ b/backend/plugin/parser/partiql/split_test.go@@ -21,7 +21,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 0, End: 70},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 70},+ End: &storepb.Position{Line: 1, Column: 71},Empty: false,},{@@ -29,7 +29,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 70, End: 201},Start: &storepb.Position{Line: 2, Column: 2},- End: &storepb.Position{Line: 2, Column: 130},+ End: &storepb.Position{Line: 2, Column: 131},Empty: false,},{@@ -37,7 +37,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 1,Range: &storepb.Range{Start: 201, End: 334},Start: &storepb.Position{Line: 3, Column: 2},- End: &storepb.Position{Line: 3, Column: 132},+ End: &storepb.Position{Line: 3, Column: 133},Empty: false,},{@@ -45,7 +45,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 2,Range: &storepb.Range{Start: 334, End: 467},Start: &storepb.Position{Line: 4, Column: 2},- End: &storepb.Position{Line: 4, Column: 132},+ End: &storepb.Position{Line: 4, Column: 133},Empty: false,},{diff --git a/backend/plugin/parser/pg/backup.go b/backend/plugin/parser/pg/backup.goindex 9ab48abbcf..19b152cc84 100644--- a/backend/plugin/parser/pg/backup.go+++ b/backend/plugin/parser/pg/backup.go@@ -169,10 +169,11 @@ func generateSQLForTable(statementInfoList []statementInfo, targetSchema string,Line: int32(statementInfoList[0].tree.GetStart().GetLine() + statementInfoList[0].baseLine),Column: int32(statementInfoList[0].tree.GetStart().GetColumn()),},- EndPosition: &storepb.Position{- Line: int32(statementInfoList[len(statementInfoList)-1].tree.GetStop().GetLine() + statementInfoList[len(statementInfoList)-1].baseLine),- Column: int32(statementInfoList[len(statementInfoList)-1].tree.GetStop().GetColumn()),- },+ EndPosition: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(statementInfoList[len(statementInfoList)-1].tree.GetStop().GetLine()+statementInfoList[len(statementInfoList)-1].baseLine),+ int32(statementInfoList[len(statementInfoList)-1].tree.GetStop().GetColumn()),+ statementInfoList[len(statementInfoList)-1].tree.GetStop().GetText(),+ ),}, nil}diff --git a/backend/plugin/parser/pg/completion.go b/backend/plugin/parser/pg/completion.goindex 838097a3ae..c57a7296ce 100644--- a/backend/plugin/parser/pg/completion.go+++ b/backend/plugin/parser/pg/completion.go@@ -1279,9 +1279,12 @@ func skipHeadingSQLs(statement string, caretLine int, caretOffset int) (string,start := 0for i, sql := range list {// Both caretLine and End.Line are 1-based+ // End.Column is 1-based exclusive (points after the last character)+ // caretOffset is 0-basedsqlEndLine := int(sql.End.GetLine())sqlEndColumn := int(sql.End.GetColumn())- if sqlEndLine > caretLine || (sqlEndLine == caretLine && sqlEndColumn >= caretOffset) {+ // Use > for End.Column comparison because it's exclusive (points after last char)+ if sqlEndLine > caretLine || (sqlEndLine == caretLine && sqlEndColumn > caretOffset) {start = iif i == 0 {// The caret is in the first SQL statement, so we don't need to skip any SQL statements.@@ -1293,7 +1296,8 @@ func skipHeadingSQLs(statement string, caretLine int, caretOffset int) (string,if caretLine == previousSQLEndLine {// The caret is in the same line as the last line of the previous SQL statement.// We need to adjust the caret offset.- newCaretOffset = caretOffset - previousSQLEndColumn+ // previousSQLEndColumn is 1-based exclusive, caretOffset is 0-based+ newCaretOffset = caretOffset - previousSQLEndColumn + 1}break}diff --git a/backend/plugin/parser/pg/split.go b/backend/plugin/parser/pg/split.goindex 23ac44ca5a..512c350b6f 100644--- a/backend/plugin/parser/pg/split.go+++ b/backend/plugin/parser/pg/split.go@@ -80,10 +80,11 @@ func splitByParser(statement string, lexer *parser.PostgreSQLLexer, stream *antlStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:pos+1], parser.PostgreSQLParserSEMI),})@@ -106,10 +107,11 @@ func splitByParser(statement string, lexer *parser.PostgreSQLLexer, stream *antlStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[eofPos-1].GetLine()),- Column: int32(tokens[eofPos-1].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[eofPos-1].GetLine()),+ int32(tokens[eofPos-1].GetColumn()),+ tokens[eofPos-1].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:eofPos], parser.PostgreSQLParserSEMI),})@@ -215,10 +217,11 @@ func splitSQLImpl(stream *antlr.CommonTokenStream, statement string) ([]base.StaStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:pos+1], parser.PostgreSQLParserSEMI),})@@ -241,10 +244,11 @@ func splitSQLImpl(stream *antlr.CommonTokenStream, statement string) ([]base.StaStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[eofPos-1].GetLine()),- Column: int32(tokens[eofPos-1].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[eofPos-1].GetLine()),+ int32(tokens[eofPos-1].GetColumn()),+ tokens[eofPos-1].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:eofPos], parser.PostgreSQLParserSEMI),})diff --git a/backend/plugin/parser/pg/split_test.go b/backend/plugin/parser/pg/split_test.goindex a9a1480cf6..3f79905cc9 100644--- a/backend/plugin/parser/pg/split_test.go+++ b/backend/plugin/parser/pg/split_test.go@@ -46,7 +46,7 @@ func TestPGSplitMultiSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 0, End: 42},Start: &storepb.Position{Line: 3, Column: 4},- End: &storepb.Position{Line: 3, Column: 3},+ End: &storepb.Position{Line: 3, Column: 4},Empty: true,},},@@ -61,13 +61,13 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: `select * from t;`,Range: &storepb.Range{Start: 0, End: 16},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 16},+ End: &storepb.Position{Line: 1, Column: 17},},{Text: "\n\t\t\t/* sdfasdf */",Range: &storepb.Range{Start: 16, End: 33},- End: &storepb.Position{Line: 2, Column: 4},Start: &storepb.Position{Line: 2, Column: 17},+ End: &storepb.Position{Line: 2, Column: 17},Empty: true,},},@@ -83,13 +83,13 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: `select * from t;`,Range: &storepb.Range{Start: 0, End: 16},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 16},+ End: &storepb.Position{Line: 1, Column: 17},},{Text: "\n\t\t\t/* sdfasdf */;",Range: &storepb.Range{Start: 16, End: 34},Start: &storepb.Position{Line: 2, Column: 17},- End: &storepb.Position{Line: 2, Column: 17},+ End: &storepb.Position{Line: 2, Column: 18},Empty: true,},{@@ -97,7 +97,7 @@ func TestPGSplitMultiSQL(t *testing.T) {BaseLine: 1,Range: &storepb.Range{Start: 34, End: 54},Start: &storepb.Position{Line: 3, Column: 4},- End: &storepb.Position{Line: 3, Column: 19},+ End: &storepb.Position{Line: 3, Column: 20},},},},@@ -110,7 +110,7 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: bigSQL,Range: &storepb.Range{Start: 0, End: 1048600},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: int32(len(bigSQL))},+ End: &storepb.Position{Line: 1, Column: int32(len(bigSQL) + 1)},},},},@@ -123,13 +123,13 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: " CREATE TABLE t(a int);",Range: &storepb.Range{Start: 0, End: 26},Start: &storepb.Position{Line: 1, Column: 5},- End: &storepb.Position{Line: 1, Column: 26},+ End: &storepb.Position{Line: 1, Column: 27},},{Text: " CREATE TABLE t1(a int)",Range: &storepb.Range{Start: 26, End: 49},Start: &storepb.Position{Line: 1, Column: 28},- End: &storepb.Position{Line: 1, Column: 49},+ End: &storepb.Position{Line: 1, Column: 50},},},},@@ -143,13 +143,13 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: `CREATE TABLE "tech_Book"(id int, name varchar(255));`,Range: &storepb.Range{Start: 0, End: 52},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 52},+ End: &storepb.Position{Line: 1, Column: 53},},{Text: "\n\t\t\t\t\t\tINSERT INTO \"tech_Book\" VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafajdfl;\"ka');",Range: &storepb.Range{Start: 52, End: 135},Start: &storepb.Position{Line: 2, Column: 7},- End: &storepb.Position{Line: 2, Column: 82},+ End: &storepb.Position{Line: 2, Column: 83},},},},@@ -166,14 +166,14 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: "\n\t\t\t\t\t\t/* this is the comment. */\n\t\t\t\t\t\tCREATE /* inline comment */TABLE \"tech_Book\"(id int, name varchar(255));",Range: &storepb.Range{Start: 0, End: 112},Start: &storepb.Position{Line: 3, Column: 7},- End: &storepb.Position{Line: 3, Column: 78},+ End: &storepb.Position{Line: 3, Column: 79},},{Text: "\n\t\t\t\t\t\t-- this is the comment.\n\t\t\t\t\t\tINSERT INTO \"tech_Book\" VALUES (0, 'abce_ksdf'), (1, 'lks''kjsafajdfl;\"ka');",BaseLine: 2,Range: &storepb.Range{Start: 112, End: 225},Start: &storepb.Position{Line: 5, Column: 7},- End: &storepb.Position{Line: 5, Column: 82},+ End: &storepb.Position{Line: 5, Column: 83},},},},@@ -201,14 +201,14 @@ func TestPGSplitMultiSQL(t *testing.T) {$$;`,Range: &storepb.Range{Start: 0, End: 303},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 8, Column: 9},+ End: &storepb.Position{Line: 8, Column: 10},},{Text: "\n\t\t\t\t\t\tCREATE TABLE t(a int);",BaseLine: 7,Range: &storepb.Range{Start: 303, End: 332},Start: &storepb.Position{Line: 9, Column: 7},- End: &storepb.Position{Line: 9, Column: 28},+ End: &storepb.Position{Line: 9, Column: 29},},},},@@ -236,14 +236,14 @@ func TestPGSplitMultiSQL(t *testing.T) {$tag_name$;`,Range: &storepb.Range{Start: 0, End: 315},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 8, Column: 17},+ End: &storepb.Position{Line: 8, Column: 18},},{Text: "\n\t\t\t\t\t\tCREATE TABLE t(a int);",BaseLine: 7,Range: &storepb.Range{Start: 315, End: 344},Start: &storepb.Position{Line: 9, Column: 7},- End: &storepb.Position{Line: 9, Column: 28},+ End: &storepb.Position{Line: 9, Column: 29},},},},@@ -257,14 +257,14 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: "CREATE TABLE t\r\n(a int);",Range: &storepb.Range{Start: 0, End: 24},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 2, Column: 8},+ End: &storepb.Position{Line: 2, Column: 9},},{Text: "\r\nCREATE TABLE t1(b int);",BaseLine: 1,Range: &storepb.Range{Start: 24, End: 49},Start: &storepb.Position{Line: 3, Column: 1},- End: &storepb.Position{Line: 3, Column: 23},+ End: &storepb.Position{Line: 3, Column: 24},},},},@@ -281,7 +281,7 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: "INSERT INTO \"public\".\"table\"(\"id\",\"content\")\n\t\t\tVALUES\n\t\t\t(12,'table column name () { :xna,sydfn,,kasdfyn;}; /////test string/// 0'),\n\t\t\t(133,'knuandfan public table id'';create table t(a int, b int);set @text=''\\\\\\\\kdaminxkljasdfiebkla.unkonwn''+''abcdef.xyz\\\\''; local xxxyy.abcddd.mysql @text;------- '),\n\t\t\t(1444,'table t xyz abc a''a\\\\\\\\\\\\\\\\''b\"c>?>xxxxxx%}}%%>c<[[?${12344556778990{%}}cake\\\\');",Range: &storepb.Range{Start: 0, End: 400},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 5, Column: 92},+ End: &storepb.Position{Line: 5, Column: 93},},},},@@ -294,7 +294,7 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: "INSERT INTO t VALUES ('klajfas)",Range: &storepb.Range{Start: 0, End: 31},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 23},+ End: &storepb.Position{Line: 1, Column: 32},Empty: false,},},@@ -308,7 +308,7 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: "INSERT INTO \"t VALUES ('klajfas)",Range: &storepb.Range{Start: 0, End: 32},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 13},+ End: &storepb.Position{Line: 1, Column: 33},},},},@@ -322,7 +322,7 @@ func TestPGSplitMultiSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 0, End: 34},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 1},+ End: &storepb.Position{Line: 1, Column: 35},Empty: false,},},@@ -336,7 +336,7 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: "$$INSERT INTO \"t VALUES ('klajfas)",Range: &storepb.Range{Start: 0, End: 34},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 3},+ End: &storepb.Position{Line: 1, Column: 35},},},},@@ -349,13 +349,13 @@ func TestPGSplitMultiSQL(t *testing.T) {Text: "SELECT * FROM 表名;",Range: &storepb.Range{Start: 0, End: 21}, // Byte offset 0-21 (not 0-17)Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 17},+ End: &storepb.Position{Line: 1, Column: 18},},{Text: " INSERT INTO 表 VALUES (1);",Range: &storepb.Range{Start: 21, End: 49}, // Byte offset 21-49 (not 17-43)Start: &storepb.Position{Line: 1, Column: 19},- End: &storepb.Position{Line: 1, Column: 43},+ End: &storepb.Position{Line: 1, Column: 44},},},},diff --git a/backend/plugin/parser/pg/test-data/test_backup.yaml b/backend/plugin/parser/pg/test-data/test_backup.yamlindex 021c7d94d5..9b8a643812 100644--- a/backend/plugin/parser/pg/test-data/test_backup.yaml+++ b/backend/plugin/parser/pg/test-data/test_backup.yaml@@ -30,7 +30,7 @@column: 0endposition:line: 7- column: 44+ column: 46- input: |-DELETE FROM tUSING test@@ -47,7 +47,7 @@column: 0endposition:line: 3- column: 31+ column: 34- input: |-DELETE FROM testUSING test2@@ -64,7 +64,7 @@column: 0endposition:line: 3- column: 38+ column: 41- input: |-UPDATE testSET test.c1 = 2@@ -82,7 +82,7 @@column: 0endposition:line: 4- column: 38+ column: 41- input: |-DELETE FROM test1 WHERE c1 = 1;UPDATE test SET test.c1 = 2 WHERE test.c1 = 1;@@ -98,7 +98,7 @@column: 0endposition:line: 1- column: 29+ column: 31- statement: |-CREATE TABLE "backupSchema"."rollback_test_public" ASSELECT "public"."test".* FROM test WHERE test.c1 = 1;@@ -110,7 +110,7 @@column: 0endposition:line: 2- column: 44+ column: 46- input: DELETE FROM test WHERE c1 = 1;result:- statement: |-@@ -124,7 +124,7 @@column: 0endposition:line: 1- column: 28+ column: 30- input: UPDATE test SET c1 = 1 WHERE c1=2;result:- statement: |-@@ -138,7 +138,7 @@column: 0endposition:line: 1- column: 32+ column: 34- input: |-UPDATE test SET test.c1 = 2 WHERE test.c1 = 1 ;UPDATE test SET test.c1 = 3 WHERE test.c1 = 5 ;@@ -156,7 +156,7 @@column: 0endposition:line: 2- column: 44+ column: 46- input: |-DELETE FROM test t1USING test2 t2@@ -173,4 +173,4 @@column: 0endposition:line: 3- column: 17+ column: 20diff --git a/backend/plugin/parser/redshift/split.go b/backend/plugin/parser/redshift/split.goindex cb4172db5c..d16d3ecbde 100644--- a/backend/plugin/parser/redshift/split.go+++ b/backend/plugin/parser/redshift/split.go@@ -81,10 +81,11 @@ func splitByParser(statement string, lexer *parser.RedshiftLexer, stream *antlr.Start: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:pos+1], parser.RedshiftParserSEMI),})@@ -107,10 +108,11 @@ func splitByParser(statement string, lexer *parser.RedshiftLexer, stream *antlr.Start: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[eofPos-1].GetLine()),- Column: int32(tokens[eofPos-1].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[eofPos-1].GetLine()),+ int32(tokens[eofPos-1].GetColumn()),+ tokens[eofPos-1].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:eofPos], parser.RedshiftParserSEMI),})@@ -215,10 +217,11 @@ func splitSQLImpl(stream *antlr.CommonTokenStream, statement string) ([]base.StaStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:pos+1], parser.RedshiftParserSEMI),})@@ -241,10 +244,11 @@ func splitSQLImpl(stream *antlr.CommonTokenStream, statement string) ([]base.StaStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[eofPos-1].GetLine()),- Column: int32(tokens[eofPos-1].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[eofPos-1].GetLine()),+ int32(tokens[eofPos-1].GetColumn()),+ tokens[eofPos-1].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:eofPos], parser.RedshiftParserSEMI),})diff --git a/backend/plugin/parser/redshift/split_test.go b/backend/plugin/parser/redshift/split_test.goindex f2c7e68c71..489db23abe 100644--- a/backend/plugin/parser/redshift/split_test.go+++ b/backend/plugin/parser/redshift/split_test.go@@ -23,7 +23,7 @@ func TestSplitSQL(t *testing.T) {Text: "SELECT 1;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 9},+ End: &storepb.Position{Line: 1, Column: 10},Range: &storepb.Range{Start: 0, End: 9},},},@@ -36,14 +36,14 @@ func TestSplitSQL(t *testing.T) {Text: "SELECT 1;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 9},+ End: &storepb.Position{Line: 1, Column: 10},Range: &storepb.Range{Start: 0, End: 9},},{Text: " SELECT 2;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 11},- End: &storepb.Position{Line: 1, Column: 19},+ End: &storepb.Position{Line: 1, Column: 20},Range: &storepb.Range{Start: 9, End: 19},},},@@ -56,7 +56,7 @@ func TestSplitSQL(t *testing.T) {Text: "SELECT\n 1;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 2, Column: 4},+ End: &storepb.Position{Line: 2, Column: 5},Range: &storepb.Range{Start: 0, End: 11},},},@@ -69,14 +69,14 @@ func TestSplitSQL(t *testing.T) {Text: "SELECT 1;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 9},+ End: &storepb.Position{Line: 1, Column: 10},Range: &storepb.Range{Start: 0, End: 9},},{Text: "\nSELECT 2;",BaseLine: 0,Start: &storepb.Position{Line: 2, Column: 1},- End: &storepb.Position{Line: 2, Column: 9},+ End: &storepb.Position{Line: 2, Column: 10},Range: &storepb.Range{Start: 9, End: 19},},},diff --git a/backend/plugin/parser/snowflake/split_test.go b/backend/plugin/parser/snowflake/split_test.goindex 7a87ab2cd6..6caea57c5c 100644--- a/backend/plugin/parser/snowflake/split_test.go+++ b/backend/plugin/parser/snowflake/split_test.go@@ -19,7 +19,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 0, End: 20},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 20},+ End: &storepb.Position{Line: 1, Column: 21},Empty: false,},{@@ -27,7 +27,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 20, End: 43},Start: &storepb.Position{Line: 2, Column: 2},- End: &storepb.Position{Line: 2, Column: 22},+ End: &storepb.Position{Line: 2, Column: 23},Empty: false,},{@@ -35,7 +35,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 1,Range: &storepb.Range{Start: 43, End: 68},Start: &storepb.Position{Line: 3, Column: 2},- End: &storepb.Position{Line: 3, Column: 24},+ End: &storepb.Position{Line: 3, Column: 25},Empty: false,},}diff --git a/backend/plugin/parser/spanner/split.go b/backend/plugin/parser/spanner/split.goindex df592d009b..a01347d955 100644--- a/backend/plugin/parser/spanner/split.go+++ b/backend/plugin/parser/spanner/split.go@@ -100,10 +100,11 @@ func SplitSQL(statement string) ([]base.Statement, error) {Start: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(tokens[endPos].GetLine()),- Column: int32(tokens[endPos].GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[endPos].GetLine()),+ int32(tokens[endPos].GetColumn()),+ tokens[endPos].GetText(),+ ),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: base.IsEmpty(tokens[start:endPos+1], parser.GoogleSQLLexerSEMI_SYMBOL),})diff --git a/backend/plugin/parser/spanner/split_test.go b/backend/plugin/parser/spanner/split_test.goindex 02f738dc1e..34399e8a3d 100644--- a/backend/plugin/parser/spanner/split_test.go+++ b/backend/plugin/parser/spanner/split_test.go@@ -19,7 +19,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 0, End: 20},Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 20},+ End: &storepb.Position{Line: 1, Column: 21},Empty: false,},{@@ -27,7 +27,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 0,Range: &storepb.Range{Start: 20, End: 43},Start: &storepb.Position{Line: 2, Column: 2},- End: &storepb.Position{Line: 2, Column: 22},+ End: &storepb.Position{Line: 2, Column: 23},Empty: false,},{@@ -35,7 +35,7 @@ func TestSplitSQL(t *testing.T) {BaseLine: 1,Range: &storepb.Range{Start: 43, End: 68},Start: &storepb.Position{Line: 3, Column: 2},- End: &storepb.Position{Line: 3, Column: 24},+ End: &storepb.Position{Line: 3, Column: 25},Empty: false,},}diff --git a/backend/plugin/parser/tidb/test-data/test_backup.yaml b/backend/plugin/parser/tidb/test-data/test_backup.yamlindex 592021d275..a0af5507c4 100644--- a/backend/plugin/parser/tidb/test-data/test_backup.yaml+++ b/backend/plugin/parser/tidb/test-data/test_backup.yaml@@ -30,7 +30,7 @@column: 1endposition:line: 7- column: 46+ column: 47- input: |-UPDATE db1.t1 SET c1 = 1 WHERE c1 = 2;UPDATE db2.t2 SET c1 = 1 WHERE c1 = 2;@@ -46,7 +46,7 @@column: 1endposition:line: 1- column: 38+ column: 39- statement: |-CREATE TABLE `backupDB`.`_rollback_1_t2` LIKE `db2`.`t2`;INSERT INTO `backupDB`.`_rollback_1_t2` SELECT `t2`.* FROM db2.t2 WHERE c1 = 2;@@ -58,7 +58,7 @@column: 1endposition:line: 2- column: 38+ column: 39- input: DELETE test FROM test, test2 as t2 where test.id = t2.id;result:- statement: |-@@ -72,7 +72,7 @@column: 1endposition:line: 1- column: 57+ column: 58- input: DELETE t1, t2 FROM test as t1, test2 as t2 WHERE t1.id = t2.id;result:- statement: |-@@ -86,7 +86,7 @@column: 1endposition:line: 1- column: 63+ column: 64- statement: |-CREATE TABLE `backupDB`.`_rollback_0_test2` LIKE `db`.`test2`;INSERT INTO `backupDB`.`_rollback_0_test2` SELECT `t2`.* FROM test as t1, test2 as t2 WHERE t1.id = t2.id;@@ -98,7 +98,7 @@column: 1endposition:line: 1- column: 63+ column: 64- input: DELETE FROM t1, t2 USING test as t1, test2 as t2 WHERE t1.id = t2.id;result:- statement: |-@@ -112,7 +112,7 @@column: 1endposition:line: 1- column: 69+ column: 70- statement: |-CREATE TABLE `backupDB`.`_rollback_0_test2` LIKE `db`.`test2`;INSERT INTO `backupDB`.`_rollback_0_test2` SELECT `t2`.* FROM test as t1, test2 as t2 WHERE t1.id = t2.id;@@ -124,7 +124,7 @@column: 1endposition:line: 1- column: 69+ column: 70- input: DELETE FROM test as t1 WHERE t1.c1 = 1;result:- statement: |-@@ -138,7 +138,7 @@column: 1endposition:line: 1- column: 39+ column: 40- input: DELETE FROM test WHERE c1 = 1;result:- statement: |-@@ -152,7 +152,7 @@column: 1endposition:line: 1- column: 30+ column: 31- input: UPDATE test x SET x.c1 = 1 WHERE x.c1 = 1result:- statement: |-@@ -166,7 +166,7 @@column: 1endposition:line: 1- column: 41+ column: 42- input: UPDATE test SET c1 = 1 WHERE c1=2;result:- statement: |-@@ -180,7 +180,7 @@column: 1endposition:line: 1- column: 34+ column: 35- input: UPDATE test t1, test2 t2 SET t1.c1 = 1 WHERE t1.c1 = t2.c1;result:- statement: |-@@ -194,7 +194,7 @@column: 1endposition:line: 1- column: 59+ column: 60- input: UPDATE test t1, test2 t2 SET t1.c1 = 1, t2.c2 = 2 WHERE t1.c1 = t2.c1;result:- statement: |-@@ -208,7 +208,7 @@column: 1endposition:line: 1- column: 70+ column: 71- statement: |-CREATE TABLE `backupDB`.`_rollback_0_test2` LIKE `db`.`test2`;INSERT INTO `backupDB`.`_rollback_0_test2` SELECT `t2`.* FROM test t1, test2 t2 WHERE t1.c1 = t2.c1;@@ -220,7 +220,7 @@column: 1endposition:line: 1- column: 70+ column: 71- input: |-UPDATE test t1 SET t1.c1 = 2 WHERE t1.c1 = 1 ;UPDATE test t2 SET t2.c1 = 3 WHERE t2.c1 = 5 ;@@ -236,7 +236,7 @@column: 1endposition:line: 1- column: 46+ column: 47- statement: |-CREATE TABLE `backupDB`.`_rollback_1_test` LIKE `db`.`test`;INSERT INTO `backupDB`.`_rollback_1_test` SELECT `t2`.* FROM test t2 WHERE t2.c1 = 5;@@ -248,4 +248,4 @@column: 1endposition:line: 2- column: 46+ column: 47diff --git a/backend/plugin/parser/tsql/split.go b/backend/plugin/parser/tsql/split.goindex 794cc0c178..4432fa11e2 100644--- a/backend/plugin/parser/tsql/split.go+++ b/backend/plugin/parser/tsql/split.go@@ -83,12 +83,10 @@ func splitByParser(statement string) ([]base.Statement, error) {Start: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: false,@@ -132,12 +130,10 @@ func splitByParser(statement string) ([]base.Statement, error) {Start: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: false,@@ -165,12 +161,10 @@ func splitByParser(statement string) ([]base.Statement, error) {Start: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: false,@@ -200,12 +194,10 @@ func splitBatchWithoutGo(b parser.IBatch_without_goContext, tokens []antlr.TokenStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: false,@@ -225,12 +217,10 @@ func splitBatchWithoutGo(b parser.IBatch_without_goContext, tokens []antlr.TokenStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: false,@@ -249,12 +239,10 @@ func splitBatchWithoutGo(b parser.IBatch_without_goContext, tokens []antlr.TokenStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: false,@@ -273,12 +261,10 @@ func splitBatchWithoutGo(b parser.IBatch_without_goContext, tokens []antlr.TokenStart: int32(byteOffset),End: int32(byteOffset + stmtByteLength),},- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(tokens[pos].GetLine()),- Column: int32(tokens[pos].GetColumn()),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(tokens[pos].GetLine()),+ int32(tokens[pos].GetColumn()),+ tokens[pos].GetText(),),Start: common.ConvertANTLRPositionToPosition(antlrPosition, statement),Empty: false,diff --git a/backend/plugin/parser/tsql/split_test.go b/backend/plugin/parser/tsql/split_test.goindex 36ed7ada4b..954b529509 100644--- a/backend/plugin/parser/tsql/split_test.go+++ b/backend/plugin/parser/tsql/split_test.go@@ -41,7 +41,7 @@ goText: "-- first statement\ndeclare @temp table(a int)",BaseLine: 0,Start: &storepb.Position{Line: 2, Column: 1},- End: &storepb.Position{Line: 2, Column: 26},+ End: &storepb.Position{Line: 2, Column: 27},Empty: false,Range: &storepb.Range{Start: 0, End: 45},},@@ -49,7 +49,7 @@ goText: "\n-- second statement\ninsert into @temp values(1)",BaseLine: 1,Start: &storepb.Position{Line: 4, Column: 1},- End: &storepb.Position{Line: 4, Column: 27},+ End: &storepb.Position{Line: 4, Column: 28},Empty: false,Range: &storepb.Range{Start: 45, End: 93},},@@ -57,7 +57,7 @@ goText: "\n-- third statement\nselect * from @temp\n-- go statement\ngo",BaseLine: 3,Start: &storepb.Position{Line: 6, Column: 1},- End: &storepb.Position{Line: 8, Column: 1},+ End: &storepb.Position{Line: 8, Column: 3},Empty: false,Range: &storepb.Range{Start: 93, End: 151},},@@ -65,7 +65,7 @@ goText: "\ngo",BaseLine: 7,Start: &storepb.Position{Line: 9, Column: 1},- End: &storepb.Position{Line: 9, Column: 1},+ End: &storepb.Position{Line: 9, Column: 3},Empty: false,Range: &storepb.Range{Start: 151, End: 154},},@@ -73,7 +73,7 @@ goText: "\ngo\ngo",BaseLine: 8,Start: &storepb.Position{Line: 10, Column: 1},- End: &storepb.Position{Line: 11, Column: 1},+ End: &storepb.Position{Line: 11, Column: 3},Empty: false,Range: &storepb.Range{Start: 154, End: 160},},@@ -106,7 +106,7 @@ UPDATE SalesLT.ProductModelProductDescription SET Culture = "zh-cn";Text: "\n\n\n\n\n\n\n\n\nUPDATE SalesLT.Address SET City = \"Shanghai\";",BaseLine: 0,Start: &storepb.Position{Line: 10, Column: 1},- End: &storepb.Position{Line: 10, Column: 45},+ End: &storepb.Position{Line: 10, Column: 46},Empty: false,Range: &storepb.Range{Start: 0, End: 54},},@@ -114,7 +114,7 @@ UPDATE SalesLT.ProductModelProductDescription SET Culture = "zh-cn";Text: "\n\nUPDATE SalesLT.Address SET PostalCode = 0;",BaseLine: 9,Start: &storepb.Position{Line: 12, Column: 1},- End: &storepb.Position{Line: 12, Column: 42},+ End: &storepb.Position{Line: 12, Column: 43},Empty: false,Range: &storepb.Range{Start: 54, End: 98},},@@ -122,7 +122,7 @@ UPDATE SalesLT.ProductModelProductDescription SET Culture = "zh-cn";Text: "\n\n\nUPDATE SalesLT.ProductModelProductDescription SET Culture = \"zh-cn\";",BaseLine: 11,Start: &storepb.Position{Line: 15, Column: 1},- End: &storepb.Position{Line: 15, Column: 68},+ End: &storepb.Position{Line: 15, Column: 69},Empty: false,Range: &storepb.Range{Start: 98, End: 169},},@@ -137,7 +137,7 @@ UPDATE SalesLT.ProductModelProductDescription SET Culture = "zh-cn";Text: "SELECT * FROM 表名;",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 1},- End: &storepb.Position{Line: 1, Column: 17},+ End: &storepb.Position{Line: 1, Column: 18},Empty: false,Range: &storepb.Range{Start: 0, End: 21}, // Byte offset 0-21 (not 0-17)},@@ -145,7 +145,7 @@ UPDATE SalesLT.ProductModelProductDescription SET Culture = "zh-cn";Text: " INSERT INTO 表 VALUES (1);",BaseLine: 0,Start: &storepb.Position{Line: 1, Column: 19},- End: &storepb.Position{Line: 1, Column: 43},+ End: &storepb.Position{Line: 1, Column: 44},Empty: false,Range: &storepb.Range{Start: 21, End: 49}, // Byte offset 21-49 (not 17-43)},