From 1a43b1c4f6b906b369ee8e0c852e7a28ea1de3ee Mon Sep 17 00:00:00 2001 From: qw4990 Date: Tue, 8 Aug 2023 15:44:39 +0800 Subject: [PATCH 1/2] fixup --- parser/lexer.go | 1 + parser/parser_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/parser/lexer.go b/parser/lexer.go index c379b029d0bac..526ed2eb74ede 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -101,6 +101,7 @@ func (s *Scanner) reset(sql string) { s.stmtStartPos = 0 s.inBangComment = false s.lastKeyword = 0 + s.identifierDot = true } func (s *Scanner) stmtText() string { diff --git a/parser/parser_test.go b/parser/parser_test.go index 1a69534777819..8e6184ca316b9 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -7389,6 +7389,18 @@ func TestTTLTableOption(t *testing.T) { RunTest(t, table, false) } +func TestIssue45898(t *testing.T) { + p := parser.New() + p.ParseSQL("a.") + stmts, _, err := p.ParseSQL("select count(1) from t") + require.NoError(t, err) + var sb strings.Builder + restoreCtx := NewRestoreCtx(DefaultRestoreFlags, &sb) + sb.Reset() + stmts[0].Restore(restoreCtx) + require.Equal(t, sb.String(), "SELECT COUNT(1) FROM `t`") +} + func TestMultiStmt(t *testing.T) { p := parser.New() stmts, _, err := p.Parse("SELECT 'foo'; SELECT 'foo;bar','baz'; select 'foo' , 'bar' , 'baz' ;select 1", "", "") From 082d30d1ce32706f8a452cf8d83529457d61f2fd Mon Sep 17 00:00:00 2001 From: qw4990 Date: Tue, 8 Aug 2023 15:46:31 +0800 Subject: [PATCH 2/2] fixup --- parser/lexer.go | 2 +- parser/parser_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/parser/lexer.go b/parser/lexer.go index 526ed2eb74ede..dcfae1d1f5f54 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -101,7 +101,7 @@ func (s *Scanner) reset(sql string) { s.stmtStartPos = 0 s.inBangComment = false s.lastKeyword = 0 - s.identifierDot = true + s.identifierDot = false } func (s *Scanner) stmtText() string { diff --git a/parser/parser_test.go b/parser/parser_test.go index 8e6184ca316b9..3857cba90f60a 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -7398,7 +7398,7 @@ func TestIssue45898(t *testing.T) { restoreCtx := NewRestoreCtx(DefaultRestoreFlags, &sb) sb.Reset() stmts[0].Restore(restoreCtx) - require.Equal(t, sb.String(), "SELECT COUNT(1) FROM `t`") + require.Equal(t, "SELECT COUNT(1) FROM `t`", sb.String()) } func TestMultiStmt(t *testing.T) {