Skip to content

Commit

Permalink
added support 'IF NOT EXISTS' for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
orginux committed Nov 2, 2023
1 parent 7b0f30e commit 2d3c6a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ func (c *CreateView) String(level int) string {

type CreateFunction struct {
CreatePos Pos
IfNotExists bool
FunctionName *Ident
OnCluster *OnClusterExpr
Params *ParamExprList
Expand All @@ -884,6 +885,9 @@ func (c *CreateFunction) End() Pos {
func (c *CreateFunction) String(level int) string {
var builder strings.Builder
builder.WriteString("CREATE FUNCTION ")
if c.IfNotExists {
builder.WriteString("IF NOT EXISTS ")
}
builder.WriteString(c.FunctionName.String(level))
if c.OnCluster != nil {
builder.WriteString(NewLine(level))
Expand Down
5 changes: 5 additions & 0 deletions parser/parser_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,10 @@ func (p *Parser) parseCreateFunction(pos Pos) (*CreateFunction, error) {
if err := p.consumeKeyword(KeywordFunction); err != nil {
return nil, err
}
ifNotExists, err := p.tryParseIfNotExists()
if err != nil {
return nil, err
}
functionName, err := p.parseIdent()
if err != nil {
return nil, err
Expand All @@ -1287,6 +1291,7 @@ func (p *Parser) parseCreateFunction(pos Pos) (*CreateFunction, error) {
}
return &CreateFunction{
CreatePos: pos,
IfNotExists: ifNotExists,
FunctionName: functionName,
OnCluster: onCluster,
Params: params,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{
"CreatePos": 0,
"IfNotExists": false,
"FunctionName": {
"Name": "linear_equation",
"Unquoted": false,
Expand Down

0 comments on commit 2d3c6a8

Please sign in to comment.