Skip to content

Commit 55eba98

Browse files
committed
Fix SYSTEM SYNC REPLICA mode parsing (PULL/LIGHTWEIGHT/STRICT)
Add special case handling in parseSystem() to correctly parse SYNC REPLICA commands with mode suffixes. The mode keywords (PULL, LIGHTWEIGHT, STRICT) were incorrectly being parsed as table names instead of being included in the command string. Now correctly outputs the actual table name (e.g., rmt2) in the Identifier instead of the mode keyword. Fixes 5 statements in 02438_sync_replica_lightweight plus 23+ additional tests across other files (03047_*, 02486_*, 02440_*, 02265_*, etc.).
1 parent 69f8e06 commit 55eba98

17 files changed

Lines changed: 45 additions & 91 deletions

File tree

parser/parser.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5881,6 +5881,35 @@ func (p *Parser) parseSystem() *ast.SystemQuery {
58815881
}
58825882
break
58835883
}
5884+
// Special case: for SYNC REPLICA commands, check if next token is a mode keyword (PULL/LIGHTWEIGHT/STRICT)
5885+
// followed by end-of-statement. If so, current token is the table name.
5886+
if p.peekIs(token.IDENT) {
5887+
nextUpper := strings.ToUpper(p.peek.Value)
5888+
if nextUpper == "PULL" || nextUpper == "LIGHTWEIGHT" || nextUpper == "STRICT" {
5889+
// Look ahead one more token to check if it's followed by end-of-statement
5890+
currentValue := p.current.Value
5891+
p.nextToken() // now at mode keyword
5892+
modeValue := p.current.Value
5893+
if p.peekIs(token.SEMICOLON) || p.peekIs(token.EOF) || p.peekIs(token.FORMAT) {
5894+
// Mode keyword is followed by end-of-statement
5895+
// Include mode in command, but NOT the table name
5896+
parts = append(parts, modeValue)
5897+
p.nextToken() // move past mode keyword
5898+
// Restore table name info for later parsing
5899+
sys.Command = strings.Join(parts, " ")
5900+
sys.Table = currentValue
5901+
// Skip the normal table parsing since we've set it here
5902+
return sys
5903+
}
5904+
// Not followed by end-of-statement, continue normally
5905+
// But we've consumed tokens, so we need to handle this carefully
5906+
// For now, let's add both to parts and continue
5907+
parts = append(parts, currentValue)
5908+
parts = append(parts, modeValue)
5909+
p.nextToken()
5910+
continue
5911+
}
5912+
}
58845913
}
58855914
parts = append(parts, p.current.Value)
58865915
p.nextToken()
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt12": true,
4-
"stmt33": true,
5-
"stmt54": true,
6-
"stmt76": true,
7-
"stmt94": true
8-
}
9-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt22": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt8": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt8": true,
4-
"stmt9": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt10": true,
4-
"stmt15": true,
5-
"stmt18": true,
6-
"stmt26": true,
7-
"stmt28": true
8-
}
9-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt9": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt24": true,
4-
"stmt43": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt15": true,
4-
"stmt9": true
5-
}
6-
}
1+
{}

0 commit comments

Comments
 (0)