Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(parser): use exclusive End position for Oracle and CosmosDB (#18687)
h3n4l4e33693295dc
diff --git a/backend/plugin/parser/cosmosdb/split.go b/backend/plugin/parser/cosmosdb/split.goindex 62ce0d23d3..2eb1f1f6ae 100644--- a/backend/plugin/parser/cosmosdb/split.go+++ b/backend/plugin/parser/cosmosdb/split.go@@ -49,7 +49,6 @@ func SplitSQL(statement string) ([]base.Statement, error) {var firstToken, lastToken antlr.Tokenfor _, token := range tokens {if token.GetTokenType() == antlr.TokenEOF {- lastToken = tokenbreak}if firstToken == nil && token.GetChannel() == antlr.TokenDefaultChannel {@@ -79,10 +78,11 @@ func SplitSQL(statement string) ([]base.Statement, error) {Line: int32(firstToken.GetLine()),Column: int32(firstToken.GetColumn()),}, statement),- End: common.ConvertANTLRPositionToPosition(&common.ANTLRPosition{- Line: int32(lastToken.GetLine()),- Column: int32(lastToken.GetColumn()),- }, statement),+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(lastToken.GetLine()),+ int32(lastToken.GetColumn()),+ lastToken.GetText(),+ ),Empty: empty,},}, nildiff --git a/backend/plugin/parser/plsql/split.go b/backend/plugin/parser/plsql/split.goindex edfc1a600c..f021b85b41 100644--- a/backend/plugin/parser/plsql/split.go+++ b/backend/plugin/parser/plsql/split.go@@ -37,8 +37,7 @@ func SplitSQL(statement string) ([]base.Statement, error) {for _, item := range tree.GetChildren() {if stmt, ok := item.(parser.IUnit_statementContext); ok {text := ""- lastLine := 0- lastColumn := 0+ var lastToken antlr.Token// tokens looks likeif startTokenIndex := stmt.GetStart().GetTokenIndex(); startTokenIndex-1 >= 0 && prevStopTokenIndex+1 <= startTokenIndex-1 {byteOffsetStart += len(tokens.GetTextFromTokens(tokens.Get(prevStopTokenIndex+1), tokens.Get(stmt.GetStart().GetTokenIndex()-1)))@@ -48,9 +47,7 @@ func SplitSQL(statement string) ([]base.Statement, error) {// The go-ora driver requires semicolon for anonymous block,// but does not support semicolon for other statements.if needSemicolon(stmt) {- lastToken := tokens.Get(stmt.GetStop().GetTokenIndex())- lastLine = lastToken.GetLine()- lastColumn = lastToken.GetColumn()+ lastToken = tokens.Get(stmt.GetStop().GetTokenIndex())text = tokens.GetTextFromTokens(stmt.GetStart(), lastToken)if lastToken.GetTokenType() != parser.PlSqlParserSEMICOLON {text += ";"@@ -60,9 +57,7 @@ func SplitSQL(statement string) ([]base.Statement, error) {if stmt.GetStop().GetTokenType() == parser.PlSqlParserSEMICOLON {stopIndex--}- lastToken := tokens.Get(stopIndex)- lastLine = lastToken.GetLine()- lastColumn = lastToken.GetColumn()+ lastToken = tokens.Get(stopIndex)text = tokens.GetTextFromTokens(stmt.GetStart(), lastToken)text = strings.TrimRightFunc(text, utils.IsSpaceOrSemicolon)}@@ -78,12 +73,10 @@ func SplitSQL(statement string) ([]base.Statement, error) {},statement,),- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(lastLine),- Column: int32(lastColumn),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(lastToken.GetLine()),+ int32(lastToken.GetColumn()),+ lastToken.GetText(),),Empty: base.IsEmpty(tokens.GetAllTokens()[stmt.GetStart().GetTokenIndex():stmt.GetStop().GetTokenIndex()+1], parser.PlSqlParserSEMICOLON),Range: &storepb.Range{@@ -120,33 +113,25 @@ func SplitSQLForCompletion(statement string) ([]base.Statement, error) {lastToken := tokens.Get(stopIndex)result[len(result)-1] = base.Statement{Text: lastResult.Text + tokens.GetTextFromTokens(stmt.GetStart(), lastToken),- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(lastToken.GetLine()),- Column: int32(lastToken.GetColumn()),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(lastToken.GetLine()),+ int32(lastToken.GetColumn()),+ lastToken.GetText(),),Empty: false,}continue}- lastLine := 0- lastColumn := 0stopIndex := stmt.GetStop().GetTokenIndex()lastToken := tokens.Get(stopIndex)- lastLine = lastToken.GetLine()- lastColumn = lastToken.GetColumn()result = append(result, base.Statement{Text: tokens.GetTextFromTokens(stmt.GetStart(), lastToken),- End: common.ConvertANTLRPositionToPosition(- &common.ANTLRPosition{- Line: int32(lastLine),- Column: int32(lastColumn),- },- statement,+ End: common.ConvertANTLRTokenToExclusiveEndPosition(+ int32(lastToken.GetLine()),+ int32(lastToken.GetColumn()),+ lastToken.GetText(),),Empty: base.IsEmpty(tokens.GetAllTokens()[stmt.GetStart().GetTokenIndex():stmt.GetStop().GetTokenIndex()+1], parser.PlSqlParserSEMICOLON),})diff --git a/backend/plugin/parser/plsql/test-data/test_split.yaml b/backend/plugin/parser/plsql/test-data/test_split.yamlindex 27300d3f40..5131fb9e2d 100644--- a/backend/plugin/parser/plsql/test-data/test_split.yaml+++ b/backend/plugin/parser/plsql/test-data/test_split.yaml@@ -4,13 +4,13 @@- text: "SELECT * FROM t1"baseline: 0start: {line: 1, column: 1}- end: {line: 1, column: 15}+ end: {line: 1, column: 17}range: {start: 0, end: 16}empty: false- text: "SELECT * FROM t2"baseline: 0start: {line: 1, column: 19}- end: {line: 1, column: 33}+ end: {line: 1, column: 35}range: {start: 18, end: 34}empty: false@@ -20,13 +20,13 @@- text: "select * from t"baseline: 1start: {line: 2, column: 5}- end: {line: 2, column: 19}+ end: {line: 2, column: 20}range: {start: 5, end: 20}empty: false- text: "create table table$1 (id int)"baseline: 2start: {line: 3, column: 5}- end: {line: 3, column: 33}+ end: {line: 3, column: 34}range: {start: 26, end: 56}empty: false@@ -36,7 +36,7 @@- text: "CREATE OR REPLACE PROCEDURE test_proc IS\nBEGIN\n CALL DBMS_OUTPUT.PUT_LINE('Hello');\nEND;"baseline: 0start: {line: 1, column: 1}- end: {line: 4, column: 4}+ end: {line: 4, column: 5}range: {start: 0, end: 91}empty: false@@ -46,13 +46,13 @@- text: "CREATE OR REPLACE PROCEDURE proc1 IS\nBEGIN\n NULL;\nEND;"baseline: 0start: {line: 1, column: 1}- end: {line: 4, column: 4}+ end: {line: 4, column: 5}range: {start: 0, end: 57}empty: false- text: "CREATE OR REPLACE PROCEDURE proc2 IS\nBEGIN\n NULL;\nEND;"baseline: 5start: {line: 6, column: 1}- end: {line: 9, column: 4}+ end: {line: 9, column: 5}range: {start: 60, end: 117}empty: false@@ -62,13 +62,13 @@- text: "SELECT * FROM t1"baseline: 0start: {line: 1, column: 1}- end: {line: 1, column: 15}+ end: {line: 1, column: 17}range: {start: 0, end: 16}empty: false- text: "SELECT * FROM t2"baseline: 2start: {line: 3, column: 1}- end: {line: 3, column: 15}+ end: {line: 3, column: 17}range: {start: 20, end: 36}empty: false@@ -78,7 +78,7 @@- text: "BEGIN\n CALL DBMS_OUTPUT.PUT_LINE('Test');\nEND;"baseline: 0start: {line: 1, column: 1}- end: {line: 3, column: 4}+ end: {line: 3, column: 5}range: {start: 0, end: 49}empty: false@@ -88,7 +88,7 @@- text: "ALTER TABLE DATA.TEST\nMODIFY PARTITION BY RANGE (TXN_DATE)\nINTERVAL (NUMTODSINTERVAL(1, 'DAY'))\n(\n\tPARTITION TEST_PO VALUES LESS THAN (\n\t\tTO_DATE('2000-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')\n\t)\n)\nONLINE"baseline: 0start: {line: 1, column: 1}- end: {line: 9, column: 1}+ end: {line: 9, column: 7}range: {start: 0, end: 233}empty: false@@ -98,7 +98,7 @@- text: "CALL my_procedure()"baseline: 0start: {line: 1, column: 1}- end: {line: 1, column: 19}+ end: {line: 1, column: 20}range: {start: 0, end: 19}empty: false@@ -108,7 +108,7 @@- text: "DROP TABLESPACE xxx INCLUDING CONTENTS CASCADE CONSTRAINTS"baseline: 0start: {line: 1, column: 1}- end: {line: 1, column: 48}+ end: {line: 1, column: 59}range: {start: 0, end: 58}empty: false