Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -5903,6 +5903,7 @@ func (s *SystemFlushExpr) Accept(visitor ASTVisitor) error {
type SystemReloadExpr struct {
ReloadPos Pos
StatementEnd Pos
OnCluster *ClusterClause
Dictionary *TableIdentifier
Type string
}
Expand All @@ -5918,6 +5919,11 @@ func (s *SystemReloadExpr) End() Pos {
func (s *SystemReloadExpr) Accept(visitor ASTVisitor) error {
visitor.Enter(s)
defer visitor.Leave(s)
if s.OnCluster != nil {
if err := s.OnCluster.Accept(visitor); err != nil {
return err
}
}
if s.Dictionary != nil {
if err := s.Dictionary.Accept(visitor); err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions parser/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,10 @@ func (s *SystemFlushExpr) FormatSQL(formatter *Formatter) {
func (s *SystemReloadExpr) FormatSQL(formatter *Formatter) {
formatter.WriteString("RELOAD ")
formatter.WriteString(s.Type)
if s.OnCluster != nil {
formatter.WriteByte(whitespace)
formatter.WriteExpr(s.OnCluster)
}
if s.Dictionary != nil {
formatter.WriteByte(whitespace)
formatter.WriteExpr(s.Dictionary)
Expand Down
74 changes: 50 additions & 24 deletions parser/parse_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,65 @@ func (p *Parser) parseSystemReloadExpr(pos Pos) (*SystemReloadExpr, error) {
return nil, err
}

var typ string
var statementEnd Pos
// Only RELOAD DICTIONARY takes a dictionary name.
hasDictionaryName := false
switch {
case p.matchKeyword(KeywordDictionaries):
curToken := p.current()
typ = KeywordDictionaries
statementEnd = p.current().End
_ = p.lexer.consumeToken()
case p.matchKeyword(KeywordDictionary):
typ = KeywordDictionary
statementEnd = p.current().End
hasDictionaryName = true
_ = p.lexer.consumeToken()
return &SystemReloadExpr{
ReloadPos: pos,
StatementEnd: curToken.End,
Type: KeywordDictionaries,
}, nil
case p.tryConsumeKeywords(KeywordDictionary):
dictionary, err := p.parseTableIdentifier(p.Pos())
if err != nil {
return nil, err
}
return &SystemReloadExpr{
ReloadPos: pos,
StatementEnd: dictionary.End(),
Type: KeywordDictionary,
Dictionary: dictionary,
}, nil
case p.tryConsumeKeywords(KeywordEmbedded):
curToken := p.current()
typ = "EMBEDDED DICTIONARIES"
statementEnd = p.current().End
if err := p.expectKeyword(KeywordDictionaries); err != nil {
return nil, err
}
return &SystemReloadExpr{
ReloadPos: pos,
StatementEnd: curToken.End,
Type: "EMBEDDED DICTIONARIES",
}, nil
default:
return nil, fmt.Errorf("expected DICTIONARIES|CONFIG")
return nil, fmt.Errorf("expected DICTIONARIES|DICTIONARY|EMBEDDED")
}

onCluster, err := p.tryParseClusterClause(p.Pos())
if err != nil {
return nil, err
}
if onCluster != nil {
statementEnd = onCluster.End()
}

var dictionary *TableIdentifier
if hasDictionaryName {
dictionary, err = p.parseTableIdentifier(p.Pos())
if err != nil {
return nil, err
}
statementEnd = dictionary.End()

// ClickHouse also accepts ON CLUSTER after the dictionary name.
if onCluster == nil {
onCluster, err = p.tryParseClusterClause(p.Pos())
if err != nil {
return nil, err
}
if onCluster != nil {
statementEnd = onCluster.End()
}
}
}

return &SystemReloadExpr{
ReloadPos: pos,
StatementEnd: statementEnd,
OnCluster: onCluster,
Type: typ,
Dictionary: dictionary,
}, nil
}

func (p *Parser) parseSystemSyncExpr(pos Pos) (*SystemSyncExpr, error) {
Expand Down
12 changes: 12 additions & 0 deletions parser/testdata/ddl/format/beautify/systems.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
SYSTEM FLUSH LOGS;
SYSTEM DROP UNCOMPRESSED CACHE;
SYSTEM DROP FILESYSTEM CACHE;
SYSTEM RELOAD DICTIONARIES;
SYSTEM RELOAD DICTIONARIES ON CLUSTER akvorado;
SYSTEM RELOAD DICTIONARY akvorado.asns;
SYSTEM RELOAD DICTIONARY ON CLUSTER akvorado akvorado.asns;
SYSTEM RELOAD DICTIONARY akvorado.asns ON CLUSTER akvorado;
SYSTEM RELOAD EMBEDDED DICTIONARIES ON CLUSTER akvorado;


-- Beautify SQL:
SYSTEM FLUSH LOGS;
SYSTEM DROP UNCOMPRESSED CACHE;
SYSTEM DROP FILESYSTEM CACHE;
SYSTEM RELOAD DICTIONARIES;
SYSTEM RELOAD DICTIONARIES ON CLUSTER akvorado;
SYSTEM RELOAD DICTIONARY akvorado.asns;
SYSTEM RELOAD DICTIONARY ON CLUSTER akvorado akvorado.asns;
SYSTEM RELOAD DICTIONARY ON CLUSTER akvorado akvorado.asns;
SYSTEM RELOAD EMBEDDED DICTIONARIES ON CLUSTER akvorado;
12 changes: 12 additions & 0 deletions parser/testdata/ddl/format/systems.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
SYSTEM FLUSH LOGS;
SYSTEM DROP UNCOMPRESSED CACHE;
SYSTEM DROP FILESYSTEM CACHE;
SYSTEM RELOAD DICTIONARIES;
SYSTEM RELOAD DICTIONARIES ON CLUSTER akvorado;
SYSTEM RELOAD DICTIONARY akvorado.asns;
SYSTEM RELOAD DICTIONARY ON CLUSTER akvorado akvorado.asns;
SYSTEM RELOAD DICTIONARY akvorado.asns ON CLUSTER akvorado;
SYSTEM RELOAD EMBEDDED DICTIONARIES ON CLUSTER akvorado;


-- Format SQL:
SYSTEM FLUSH LOGS;
SYSTEM DROP UNCOMPRESSED CACHE;
SYSTEM DROP FILESYSTEM CACHE;
SYSTEM RELOAD DICTIONARIES;
SYSTEM RELOAD DICTIONARIES ON CLUSTER akvorado;
SYSTEM RELOAD DICTIONARY akvorado.asns;
SYSTEM RELOAD DICTIONARY ON CLUSTER akvorado akvorado.asns;
SYSTEM RELOAD DICTIONARY ON CLUSTER akvorado akvorado.asns;
SYSTEM RELOAD EMBEDDED DICTIONARIES ON CLUSTER akvorado;
131 changes: 131 additions & 0 deletions parser/testdata/ddl/output/systems.sql.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,136 @@
"StatementEnd": 79,
"Type": "FILESYSTEM CACHE"
}
},
{
"SystemPos": 81,
"Expr": {
"ReloadPos": 88,
"StatementEnd": 107,
"OnCluster": null,
"Dictionary": null,
"Type": "DICTIONARIES"
}
},
{
"SystemPos": 109,
"Expr": {
"ReloadPos": 116,
"StatementEnd": 155,
"OnCluster": {
"OnPos": 136,
"Expr": {
"Name": "akvorado",
"QuoteType": 1,
"NamePos": 147,
"NameEnd": 155
}
},
"Dictionary": null,
"Type": "DICTIONARIES"
}
},
{
"SystemPos": 157,
"Expr": {
"ReloadPos": 164,
"StatementEnd": 195,
"OnCluster": null,
"Dictionary": {
"Database": {
"Name": "akvorado",
"QuoteType": 1,
"NamePos": 182,
"NameEnd": 190
},
"Table": {
"Name": "asns",
"QuoteType": 1,
"NamePos": 191,
"NameEnd": 195
}
},
"Type": "DICTIONARY"
}
},
{
"SystemPos": 197,
"Expr": {
"ReloadPos": 204,
"StatementEnd": 255,
"OnCluster": {
"OnPos": 222,
"Expr": {
"Name": "akvorado",
"QuoteType": 1,
"NamePos": 233,
"NameEnd": 241
}
},
"Dictionary": {
"Database": {
"Name": "akvorado",
"QuoteType": 1,
"NamePos": 242,
"NameEnd": 250
},
"Table": {
"Name": "asns",
"QuoteType": 1,
"NamePos": 251,
"NameEnd": 255
}
},
"Type": "DICTIONARY"
}
},
{
"SystemPos": 257,
"Expr": {
"ReloadPos": 264,
"StatementEnd": 315,
"OnCluster": {
"OnPos": 296,
"Expr": {
"Name": "akvorado",
"QuoteType": 1,
"NamePos": 307,
"NameEnd": 315
}
},
"Dictionary": {
"Database": {
"Name": "akvorado",
"QuoteType": 1,
"NamePos": 282,
"NameEnd": 290
},
"Table": {
"Name": "asns",
"QuoteType": 1,
"NamePos": 291,
"NameEnd": 295
}
},
"Type": "DICTIONARY"
}
},
{
"SystemPos": 317,
"Expr": {
"ReloadPos": 324,
"StatementEnd": 372,
"OnCluster": {
"OnPos": 353,
"Expr": {
"Name": "akvorado",
"QuoteType": 1,
"NamePos": 364,
"NameEnd": 372
}
},
"Dictionary": null,
"Type": "EMBEDDED DICTIONARIES"
}
}
]
6 changes: 6 additions & 0 deletions parser/testdata/ddl/systems.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
SYSTEM FLUSH LOGS;
SYSTEM DROP UNCOMPRESSED CACHE;
SYSTEM DROP FILESYSTEM CACHE;
SYSTEM RELOAD DICTIONARIES;
SYSTEM RELOAD DICTIONARIES ON CLUSTER akvorado;
SYSTEM RELOAD DICTIONARY akvorado.asns;
SYSTEM RELOAD DICTIONARY ON CLUSTER akvorado akvorado.asns;
SYSTEM RELOAD DICTIONARY akvorado.asns ON CLUSTER akvorado;
SYSTEM RELOAD EMBEDDED DICTIONARIES ON CLUSTER akvorado;
3 changes: 3 additions & 0 deletions parser/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ func Walk(node Expr, fn WalkFunc) bool {
return false
}
case *SystemReloadExpr:
if !Walk(n.OnCluster, fn) {
return false
}
if !Walk(n.Dictionary, fn) {
return false
}
Expand Down
Loading