2020-08-06 20:58:47 +03:00
|
|
|
package ast
|
|
|
|
|
2022-12-18 11:35:59 +03:00
|
|
|
var (
|
2023-03-26 04:20:53 +03:00
|
|
|
_ Node = (*FuncNode)(nil)
|
|
|
|
_ ResultColumn = (*FuncNode)(nil)
|
2022-12-18 11:35:59 +03:00
|
|
|
)
|
2020-08-06 20:58:47 +03:00
|
|
|
|
2023-03-26 04:20:53 +03:00
|
|
|
// FuncNode models a function. For example, "COUNT()".
|
|
|
|
type FuncNode struct {
|
2020-08-06 20:58:47 +03:00
|
|
|
baseNode
|
|
|
|
fnName string
|
2023-03-19 07:58:00 +03:00
|
|
|
alias string
|
2020-08-06 20:58:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// FuncName returns the function name.
|
2023-03-26 04:20:53 +03:00
|
|
|
func (fn *FuncNode) FuncName() string {
|
2020-08-06 20:58:47 +03:00
|
|
|
return fn.fnName
|
|
|
|
}
|
|
|
|
|
2023-03-19 07:58:00 +03:00
|
|
|
// String returns a log/debug-friendly representation.
|
2023-03-26 04:20:53 +03:00
|
|
|
func (fn *FuncNode) String() string {
|
2023-03-19 07:58:00 +03:00
|
|
|
str := nodeString(fn)
|
|
|
|
if fn.alias != "" {
|
|
|
|
str += ":" + fn.alias
|
|
|
|
}
|
|
|
|
return str
|
2020-08-06 20:58:47 +03:00
|
|
|
}
|
|
|
|
|
2023-03-22 09:17:34 +03:00
|
|
|
// Text implements ResultColumn.
|
2023-03-26 04:20:53 +03:00
|
|
|
func (fn *FuncNode) Text() string {
|
2023-03-22 09:17:34 +03:00
|
|
|
return fn.ctx.GetText()
|
2020-08-06 20:58:47 +03:00
|
|
|
}
|
|
|
|
|
2023-03-22 09:17:34 +03:00
|
|
|
// Alias implements ResultColumn.
|
2023-03-26 04:20:53 +03:00
|
|
|
func (fn *FuncNode) Alias() string {
|
2023-03-19 07:58:00 +03:00
|
|
|
return fn.alias
|
|
|
|
}
|
|
|
|
|
2020-08-06 20:58:47 +03:00
|
|
|
// SetChildren implements Node.
|
2023-03-26 04:20:53 +03:00
|
|
|
func (fn *FuncNode) SetChildren(children []Node) error {
|
2020-08-06 20:58:47 +03:00
|
|
|
fn.setChildren(children)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-22 09:17:34 +03:00
|
|
|
// IsColumn implements ResultColumn.
|
2023-03-26 04:20:53 +03:00
|
|
|
func (fn *FuncNode) IsColumn() bool {
|
2020-08-06 20:58:47 +03:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-03-26 04:20:53 +03:00
|
|
|
func (fn *FuncNode) AddChild(child Node) error {
|
|
|
|
// TODO: add check for valid FuncNode child types
|
2020-08-06 20:58:47 +03:00
|
|
|
fn.addChild(child)
|
|
|
|
return child.SetParent(fn)
|
|
|
|
}
|