本文整理汇总了Golang中github.com/pingcap/tidb/ast.ExprNode.Accept方法的典型用法代码示例。如果您正苦于以下问题:Golang ExprNode.Accept方法的具体用法?Golang ExprNode.Accept怎么用?Golang ExprNode.Accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/ast.ExprNode
的用法示例。
在下文中一共展示了ExprNode.Accept方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: convertExpr
func convertExpr(converter *expressionConverter, expr ast.ExprNode) (expression.Expression, error) {
expr.Accept(converter)
if converter.err != nil {
return nil, errors.Trace(converter.err)
}
return converter.exprMap[expr], nil
}
示例2: rewrite
// rewrite function rewrites ast expr to expression.Expression.
// aggMapper maps ast.AggregateFuncExpr to the columns offset in p's output schema.
// asScalar means whether this expression must be treated as a scalar expression.
// And this function returns a result expression, a new plan that may have apply or semi-join.
func (b *planBuilder) rewrite(expr ast.ExprNode, p LogicalPlan, aggMapper map[*ast.AggregateFuncExpr]int, asScalar bool) (
expression.Expression, LogicalPlan, error) {
er := &expressionRewriter{
p: p,
aggrMap: aggMapper,
b: b,
asScalar: asScalar,
ctx: b.ctx,
}
if p != nil {
er.schema = p.GetSchema()
}
expr.Accept(er)
if er.err != nil {
return nil, nil, errors.Trace(er.err)
}
if !asScalar && len(er.ctxStack) == 0 {
return nil, er.p, nil
}
if len(er.ctxStack) != 1 {
return nil, nil, errors.Errorf("context len %v is invalid", len(er.ctxStack))
}
if getRowLen(er.ctxStack[0]) != 1 {
return nil, nil, ErrOperandColumns.GenByArgs(1)
}
result := expression.FoldConstant(b.ctx, er.ctxStack[0])
return result, er.p, nil
}
示例3: Eval
// Eval evaluates an expression to a value.
func Eval(ctx context.Context, expr ast.ExprNode) (interface{}, error) {
e := &Evaluator{ctx: ctx}
expr.Accept(e)
if e.err != nil {
return nil, errors.Trace(e.err)
}
return expr.GetValue(), nil
}
示例4: EvalDatum
// EvalDatum evaluates an expression to a datum.
func EvalDatum(ctx context.Context, expr ast.ExprNode) (d types.Datum, err error) {
e := &Evaluator{ctx: ctx}
expr.Accept(e)
if e.err != nil {
return d, errors.Trace(e.err)
}
return *expr.GetDatum(), nil
}
示例5: rewrite
func (b *planBuilder) rewrite(expr ast.ExprNode, p Plan, aggMapper map[*ast.AggregateFuncExpr]int) (newExpr expression.Expression, newPlan Plan, correlated bool, err error) {
er := &expressionRewriter{p: p, aggrMap: aggMapper, schema: p.GetSchema(), b: b}
expr.Accept(er)
if er.err != nil {
return nil, nil, false, errors.Trace(er.err)
}
if len(er.ctxStack) != 1 {
return nil, nil, false, errors.Errorf("context len %v is invalid", len(er.ctxStack))
}
return er.ctxStack[0], er.p, er.correlated, nil
}
示例6: Eval
// Eval evaluates an expression to a datum.
func Eval(ctx context.Context, expr ast.ExprNode) (d types.Datum, err error) {
if ast.IsEvaluated(expr) {
return *expr.GetDatum(), nil
}
e := &Evaluator{ctx: ctx}
expr.Accept(e)
if e.err != nil {
return d, errors.Trace(e.err)
}
if ast.IsPreEvaluable(expr) && (expr.GetFlag()&ast.FlagHasFunc == 0) {
expr.SetFlag(expr.GetFlag() | ast.FlagPreEvaluated)
}
return *expr.GetDatum(), nil
}
示例7: attachCondition
// attachCondition tries to attach a condition as deep as possible.
// availablePaths are paths join before this path.
// onCond represents whether the conditions is from current join's on condition. The on condition from other joins is treated as where condition.
func (p *joinPath) attachCondition(condition ast.ExprNode, availablePaths []*joinPath, onCond bool) (attached bool) {
filterRate := guesstimateFilterRate(condition)
// table
if p.table != nil || p.subquery != nil {
attacher := conditionAttachChecker{targetPath: p, availablePaths: availablePaths}
condition.Accept(&attacher)
if attacher.invalid {
return false
}
p.conditions = append(p.conditions, condition)
p.filterRate *= filterRate
return true
}
// inner join
if len(p.inners) > 0 {
for _, in := range p.inners {
if in.attachCondition(condition, availablePaths, false) {
p.filterRate *= filterRate
return true
}
}
attacher := &conditionAttachChecker{targetPath: p, availablePaths: availablePaths}
condition.Accept(attacher)
if attacher.invalid {
return false
}
p.conditions = append(p.conditions, condition)
p.filterRate *= filterRate
return true
}
// outer join
if p.outer.attachCondition(condition, availablePaths, false) {
p.filterRate *= filterRate
return true
}
// can't attach any where condition
if onCond && p.inner.attachCondition(condition, availablePaths, false) {
p.filterRate *= filterRate
return true
}
return false
}
示例8: rewrite
// rewrite function rewrites ast expr to expression.Expression.
// aggMapper maps ast.AggregateFuncExpr to the columns offset in p's output schema.
// asScalar means whether this expression must be treated as a scalar expression.
func (b *planBuilder) rewrite(expr ast.ExprNode, p LogicalPlan, aggMapper map[*ast.AggregateFuncExpr]int, asScalar bool) (
newExpr expression.Expression, newPlan LogicalPlan, correlated bool, err error) {
er := &expressionRewriter{
p: p,
aggrMap: aggMapper,
schema: p.GetSchema(),
b: b,
asScalar: asScalar,
}
expr.Accept(er)
if er.err != nil {
return nil, nil, false, errors.Trace(er.err)
}
if !asScalar && len(er.ctxStack) == 0 {
return nil, er.p, er.correlated, nil
}
if len(er.ctxStack) != 1 {
return nil, nil, false, errors.Errorf("context len %v is invalid", len(er.ctxStack))
}
if getRowLen(er.ctxStack[0]) != 1 {
return nil, nil, false, errors.New("Operand should contain 1 column(s)")
}
return er.ctxStack[0], er.p, er.correlated, nil
}