本文整理汇总了Golang中github.com/cockroachdb/cockroach/sql/parser.Expr.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Expr.String方法的具体用法?Golang Expr.String怎么用?Golang Expr.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/sql/parser.Expr
的用法示例。
在下文中一共展示了Expr.String方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Visit
func (v *extractAggregatesVisitor) Visit(expr parser.Expr, pre bool) (parser.Visitor, parser.Expr) {
if !pre || v.err != nil {
return nil, expr
}
// This expression is in the GROUP BY - switch to the copy that will accept
// qvalues for this and any subtrees.
if _, ok := v.groupStrs[expr.String()]; ok && v.groupedCopy != nil {
v = v.groupedCopy
}
switch t := expr.(type) {
case *parser.FuncExpr:
if len(t.Name.Indirect) > 0 {
break
}
if impl, ok := aggregates[strings.ToLower(string(t.Name.Base))]; ok {
if len(t.Exprs) != 1 {
// Type checking has already run on these expressions thus
// if an aggregate function of the wrong arity gets here,
// something has gone really wrong.
panic(fmt.Sprintf("%s has %d arguments (expected 1)", t.Name.Base, len(t.Exprs)))
}
f := &aggregateFunc{
expr: t,
arg: t.Exprs[0],
create: impl,
group: v.n,
buckets: make(map[string]aggregateImpl),
}
if t.Type == parser.Distinct {
f.seen = make(map[string]struct{})
}
v.n.funcs = append(v.n.funcs, f)
return nil, f
}
case *qvalue:
if v.groupedCopy != nil {
v.err = fmt.Errorf("column \"%s\" must appear in the GROUP BY clause or be used in an aggregate function",
t.colRef.get().Name)
return v, expr
}
f := &aggregateFunc{
expr: t,
arg: t,
create: newIdentAggregate,
group: v.n,
buckets: make(map[string]aggregateImpl),
}
v.n.funcs = append(v.n.funcs, f)
return nil, f
}
return v, expr
}
示例2: Visit
func (v *checkAggregateVisitor) Visit(expr parser.Expr, pre bool) (parser.Visitor, parser.Expr) {
if !pre || v.aggrErr != nil {
return nil, expr
}
switch t := expr.(type) {
case *parser.FuncExpr:
if _, ok := aggregates[strings.ToLower(string(t.Name.Base))]; ok {
return nil, expr
}
case *qvalue:
if _, ok := v.groupStrs[t.String()]; ok {
return nil, expr
}
v.aggrErr = fmt.Errorf("column \"%s\" must appear in the GROUP BY clause or be used in an aggregate function", t.col.Name)
return v, expr
}
if _, ok := v.groupStrs[expr.String()]; ok {
return nil, expr
}
return v, expr
}