2020-08-06 20:58:47 +03:00
|
|
|
package ast
|
|
|
|
|
2022-12-18 11:35:59 +03:00
|
|
|
var (
|
|
|
|
_ Node = (*Func)(nil)
|
|
|
|
_ ColExpr = (*Func)(nil)
|
|
|
|
)
|
2020-08-06 20:58:47 +03:00
|
|
|
|
|
|
|
// Func models a function. For example, "COUNT()".
|
|
|
|
type Func struct {
|
|
|
|
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.
|
|
|
|
func (fn *Func) FuncName() string {
|
|
|
|
return fn.fnName
|
|
|
|
}
|
|
|
|
|
2023-03-19 07:58:00 +03:00
|
|
|
// String returns a log/debug-friendly representation.
|
2020-08-06 20:58:47 +03:00
|
|
|
func (fn *Func) 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
|
|
|
}
|
|
|
|
|
|
|
|
// ColExpr implements ColExpr.
|
|
|
|
func (fn *Func) ColExpr() (string, error) {
|
|
|
|
return fn.ctx.GetText(), nil
|
|
|
|
}
|
|
|
|
|
2023-03-19 07:58:00 +03:00
|
|
|
// Alias implements ColExpr.
|
|
|
|
func (fn *Func) Alias() string {
|
|
|
|
return fn.alias
|
|
|
|
}
|
|
|
|
|
2020-08-06 20:58:47 +03:00
|
|
|
// SetChildren implements Node.
|
|
|
|
func (fn *Func) SetChildren(children []Node) error {
|
|
|
|
fn.setChildren(children)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsColName implements ColExpr.
|
|
|
|
func (fn *Func) IsColName() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fn *Func) AddChild(child Node) error {
|
|
|
|
// TODO: add check for valid Func child types
|
|
|
|
fn.addChild(child)
|
|
|
|
return child.SetParent(fn)
|
|
|
|
}
|