• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang expression.EvalBoolExpr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pingcap/tidb/expression.EvalBoolExpr函数的典型用法代码示例。如果您正苦于以下问题:Golang EvalBoolExpr函数的具体用法?Golang EvalBoolExpr怎么用?Golang EvalBoolExpr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了EvalBoolExpr函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Next

// Next implements plan.Plan Next interface.
func (r *HavingPlan) Next(ctx context.Context) (row *plan.Row, err error) {
	if r.evalArgs == nil {
		r.evalArgs = map[interface{}]interface{}{}
	}
	for {
		var srcRow *plan.Row
		srcRow, err = r.Src.Next(ctx)
		if srcRow == nil || err != nil {
			return nil, errors.Trace(err)
		}
		r.evalArgs[expression.ExprEvalIdentFunc] = func(name string) (interface{}, error) {
			v, err0 := GetIdentValue(name, r.Src.GetFields(), srcRow.Data, field.CheckFieldFlag)
			if err0 == nil {
				return v, nil
			}

			// try to find in outer query
			return getIdentValueFromOuterQuery(ctx, name)
		}
		r.evalArgs[expression.ExprEvalPositionFunc] = func(position int) (interface{}, error) {
			// position is in [1, len(fields)], so we must decrease 1 to get correct index
			// TODO: check position invalidation
			return srcRow.Data[position-1], nil
		}
		var v bool
		v, err = expression.EvalBoolExpr(ctx, r.Expr, r.evalArgs)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if v {
			row = srcRow
			return
		}
	}
}
开发者ID:qiuyesuifeng,项目名称:tidb,代码行数:36,代码来源:having.go


示例2: nextCrossJoin

func (r *JoinPlan) nextCrossJoin(ctx context.Context) (row *plan.Row, err error) {
	for {
		if r.curRow == nil {
			r.curRow, err = r.Left.Next(ctx)
			if err != nil {
				return nil, errors.Trace(err)
			}
			if r.curRow == nil {
				return nil, nil
			}
			if r.On != nil {
				tempExpr := r.On.Clone()
				visitor := NewIdentEvalVisitor(r.Left.GetFields(), r.curRow.Data)
				_, err = tempExpr.Accept(visitor)
				if err != nil {
					return nil, errors.Trace(err)
				}
				var filtered bool
				r.tempPlan, filtered, err = r.Right.Filter(ctx, tempExpr)
				if filtered {
					log.Debugf("cross join use index")
				}
			} else {
				r.tempPlan = r.Right
			}
		}

		var rightRow *plan.Row
		rightRow, err = r.tempPlan.Next(ctx)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if rightRow == nil {
			r.curRow = nil
			r.tempPlan.Close()
			continue
		}
		joinedRow := append(r.curRow.Data, rightRow.Data...)
		if r.On != nil {
			r.evalArgs[expression.ExprEvalIdentFunc] = func(name string) (interface{}, error) {
				return GetIdentValue(name, r.Fields, joinedRow, field.DefaultFieldFlag)
			}

			b, err := expression.EvalBoolExpr(ctx, r.On, r.evalArgs)
			if err != nil {
				return nil, errors.Trace(err)
			}
			if !b {
				// If On condition not satisified, drop this row
				continue
			}
		}
		row = &plan.Row{
			Data:    joinedRow,
			RowKeys: append(r.curRow.RowKeys, rightRow.RowKeys...),
		}
		return
	}
}
开发者ID:maserg,项目名称:tidb,代码行数:59,代码来源:join.go


示例3: findMatchedRows

func (r *JoinPlan) findMatchedRows(ctx context.Context, row *plan.Row, p plan.Plan, right bool) (err error) {
	r.cursor = 0
	r.matchedRows = nil
	p.Close()
	for {
		var cmpRow *plan.Row
		cmpRow, err = p.Next(ctx)
		if err != nil {
			return errors.Trace(err)
		}
		if cmpRow == nil {
			break
		}

		// Do append(s1, s2) safely. Sometime the s1 capability is larger than its real length, so
		// multi append may overwrite last valid data, e.g,
		//   s1 = make([]interface{}, 0, 1)
		//   s = append(s1, []interface{}{1})
		//   ss = append(ss, s)
		//   s = append(s1, []interface{}{2})
		//   ss = append(ss, s)
		// We will see that ss only contains 2.
		joined := make([]interface{}, 0, len(cmpRow.Data)+len(row.Data))
		if right {
			joined = append(append(joined, cmpRow.Data...), row.Data...)
		} else {
			joined = append(append(joined, row.Data...), cmpRow.Data...)
		}
		r.evalArgs[expression.ExprEvalIdentFunc] = func(name string) (interface{}, error) {
			return GetIdentValue(name, r.Fields, joined, field.DefaultFieldFlag)
		}
		var b bool
		b, err = expression.EvalBoolExpr(ctx, r.On, r.evalArgs)
		if err != nil {
			return errors.Trace(err)
		}
		if b {
			cmpRow.Data = joined
			keys := make([]*plan.RowKeyEntry, 0, len(row.RowKeys)+len(cmpRow.RowKeys))
			cmpRow.RowKeys = append(append(keys, row.RowKeys...), cmpRow.RowKeys...)
			r.matchedRows = append(r.matchedRows, cmpRow)
		}
	}
	if len(r.matchedRows) == 0 {
		if right {
			leftLen := len(r.Fields) - len(r.Right.GetFields())
			row.Data = append(make([]interface{}, leftLen), row.Data...)
		} else {
			rightLen := len(r.Fields) - len(r.Left.GetFields())
			row.Data = append(row.Data, make([]interface{}, rightLen)...)
		}
		r.matchedRows = append(r.matchedRows, row)
	}
	return nil
}
开发者ID:maserg,项目名称:tidb,代码行数:55,代码来源:join.go


示例4: evalCondition

func (s *ShowPlan) evalCondition(ctx context.Context, m map[interface{}]interface{}) (bool, error) {
	var cond expression.Expression
	if s.Pattern != nil {
		cond = s.Pattern
	} else if s.Where != nil {
		cond = s.Where
	}

	if cond == nil {
		return true, nil
	}
	return expression.EvalBoolExpr(ctx, cond, m)
}
开发者ID:netroby,项目名称:tidb,代码行数:13,代码来源:show.go


示例5: findMatchedRows

func (r *JoinPlan) findMatchedRows(ctx context.Context, row *plan.Row, right bool) (err error) {
	var p plan.Plan
	if right {
		p = r.Left
	} else {
		p = r.Right
	}
	r.cursor = 0
	r.matchedRows = nil
	p.Close()
	for {
		var cmpRow *plan.Row
		cmpRow, err = p.Next(ctx)
		if err != nil {
			return errors.Trace(err)
		}
		if cmpRow == nil {
			break
		}
		var joined []interface{}
		if right {
			joined = append(cmpRow.Data, row.Data...)
		} else {
			joined = append(row.Data, cmpRow.Data...)
		}
		r.evalArgs[expression.ExprEvalIdentFunc] = func(name string) (interface{}, error) {
			return GetIdentValue(name, r.Fields, joined, field.DefaultFieldFlag)
		}
		var b bool
		b, err = expression.EvalBoolExpr(ctx, r.On, r.evalArgs)
		if err != nil {
			return errors.Trace(err)
		}
		if b {
			cmpRow.Data = joined
			cmpRow.RowKeys = append(row.RowKeys, cmpRow.RowKeys...)
			r.matchedRows = append(r.matchedRows, cmpRow)
		}
	}
	if len(r.matchedRows) == 0 {
		if right {
			leftLen := len(r.Fields) - len(r.Right.GetFields())
			row.Data = append(make([]interface{}, leftLen), row.Data...)
		} else {
			rightLen := len(r.Fields) - len(r.Left.GetFields())
			row.Data = append(row.Data, make([]interface{}, rightLen)...)
		}
		r.matchedRows = append(r.matchedRows, row)
	}
	return nil
}
开发者ID:nengwang,项目名称:tidb,代码行数:51,代码来源:join.go


示例6: hitWhere

func (s *DeleteStmt) hitWhere(ctx context.Context, fields []*field.ResultField, data []interface{}) (bool, error) {
	if s.Where == nil {
		return true, nil
	}
	m := map[interface{}]interface{}{}
	m[expression.ExprEvalIdentFunc] = func(name string) (interface{}, error) {
		return plans.GetIdentValue(name, fields, data, field.DefaultFieldFlag)
	}

	ok, err := expression.EvalBoolExpr(ctx, s.Where, m)
	if err != nil {
		return false, errors.Trace(err)
	}
	return ok, nil
}
开发者ID:nengwang,项目名称:tidb,代码行数:15,代码来源:delete.go


示例7: hitWhere

func (s *DeleteStmt) hitWhere(ctx context.Context, t table.Table, data []interface{}) (bool, error) {
	if s.Where == nil {
		return true, nil
	}
	m := map[interface{}]interface{}{}

	// Set parameter for evaluating expression.
	for _, col := range t.Cols() {
		m[col.Name.L] = data[col.Offset]
	}
	ok, err := expression.EvalBoolExpr(ctx, s.Where, m)
	if err != nil {
		return false, errors.Trace(err)
	}
	return ok, nil
}
开发者ID:daodaoliang,项目名称:tidb,代码行数:16,代码来源:delete.go


示例8: nextCrossJoin

func (r *JoinPlan) nextCrossJoin(ctx context.Context) (row *plan.Row, err error) {
	for {
		if r.curRow == nil {
			r.curRow, err = r.Left.Next(ctx)
			if err != nil {
				return nil, errors.Trace(err)
			}
			if r.curRow == nil {
				return nil, nil
			}
		}
		var rightRow *plan.Row
		rightRow, err = r.Right.Next(ctx)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if rightRow == nil {
			r.curRow = nil
			r.Right.Close()
			continue
		}
		joinedRow := append(r.curRow.Data, rightRow.Data...)
		if r.On != nil {
			r.evalArgs[expression.ExprEvalIdentFunc] = func(name string) (interface{}, error) {
				return GetIdentValue(name, r.Fields, joinedRow, field.DefaultFieldFlag)
			}

			b, err := expression.EvalBoolExpr(ctx, r.On, r.evalArgs)
			if err != nil {
				return nil, errors.Trace(err)
			}
			if !b {
				// If On condition not satisified, drop this row
				continue
			}
		}
		row = &plan.Row{
			Data:    joinedRow,
			RowKeys: append(r.curRow.RowKeys, rightRow.RowKeys...),
		}
		return
	}
}
开发者ID:nengwang,项目名称:tidb,代码行数:43,代码来源:join.go


示例9: Next

// Next implements plan.Plan Next interface.
func (r *HavingPlan) Next(ctx context.Context) (row *plan.Row, err error) {
	if r.evalArgs == nil {
		r.evalArgs = map[interface{}]interface{}{}
	}
	for {
		var srcRow *plan.Row
		srcRow, err = r.Src.Next(ctx)
		if srcRow == nil || err != nil {
			return nil, errors.Trace(err)
		}
		r.evalArgs[expression.ExprEvalIdentReferFunc] = func(name string, scope int, index int) (interface{}, error) {
			if scope == expression.IdentReferFromTable {
				return srcRow.FromData[index], nil
			} else if scope == expression.IdentReferSelectList {
				return srcRow.Data[index], nil
			}

			// try to find in outer query
			return getIdentValueFromOuterQuery(ctx, name)
		}
		r.evalArgs[expression.ExprEvalPositionFunc] = func(position int) (interface{}, error) {
			// position is in [1, len(fields)], so we must decrease 1 to get correct index
			// TODO: check position invalidation
			return srcRow.Data[position-1], nil
		}
		var v bool
		v, err = expression.EvalBoolExpr(ctx, r.Expr, r.evalArgs)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if v {
			row = srcRow
			return
		}
	}
}
开发者ID:lovedboy,项目名称:tidb,代码行数:37,代码来源:having.go


示例10: fetchAll


//.........这里部分代码省略.........
		for _, desc := range descs {
			row := &plan.Row{
				Data: []interface{}{desc.Name, desc.Desc, desc.DefaultCollation, desc.Maxlen},
			}
			s.rows = append(s.rows, row)
		}
	case stmt.ShowVariables:
		sessionVars := variable.GetSessionVars(ctx)
		for _, v := range variable.SysVars {
			if s.Pattern != nil {
				s.Pattern.Expr = expression.Value{Val: v.Name}
				r, err := s.Pattern.Eval(ctx, nil)
				if err != nil {
					return errors.Trace(err)
				}
				match, ok := r.(bool)
				if !ok {
					return errors.Errorf("Eval like pattern error")
				}
				if !match {
					continue
				}
			} else if s.Where != nil {
				m := map[interface{}]interface{}{}

				m[expression.ExprEvalIdentFunc] = func(name string) (interface{}, error) {
					if strings.EqualFold(name, "Variable_name") {
						return v.Name, nil
					}

					return nil, errors.Errorf("unknown field %s", name)
				}

				match, err := expression.EvalBoolExpr(ctx, s.Where, m)
				if err != nil {
					return errors.Trace(err)
				}
				if !match {
					continue
				}
			}
			value := v.Value
			if !s.GlobalScope {
				// Try to get Session Scope variable value
				sv, ok := sessionVars.Systems[v.Name]
				if ok {
					value = sv
				}
			}
			row := &plan.Row{Data: []interface{}{v.Name, value}}
			s.rows = append(s.rows, row)
		}
	case stmt.ShowCollation:
		collations := charset.GetCollations()
		for _, v := range collations {
			if s.Pattern != nil {
				s.Pattern.Expr = expression.Value{Val: v.Name}
				r, err := s.Pattern.Eval(ctx, nil)
				if err != nil {
					return errors.Trace(err)
				}
				match, ok := r.(bool)
				if !ok {
					return errors.Errorf("Eval like pattern error")
				}
				if !match {
开发者ID:kingland,项目名称:tidb,代码行数:67,代码来源:show.go


示例11: nextCrossJoin

func (r *JoinPlan) nextCrossJoin(ctx context.Context) (row *plan.Row, err error) {
	visitor := newJoinIdentVisitor(0)
	for {
		if r.curRow == nil {
			r.curRow, err = r.Left.Next(ctx)
			if err != nil {
				return nil, errors.Trace(err)
			}
			if r.curRow == nil {
				return nil, nil
			}

			if r.On != nil {
				tempExpr := r.On.Clone()
				visitor.row = r.curRow.Data
				_, err = tempExpr.Accept(visitor)
				if err != nil {
					return nil, errors.Trace(err)
				}
				var filtered bool
				r.tempPlan, filtered, err = r.Right.Filter(ctx, tempExpr)
				if filtered {
					log.Debugf("cross join use index")
				}
			} else {
				r.tempPlan = r.Right
			}
		}

		var rightRow *plan.Row
		rightRow, err = r.tempPlan.Next(ctx)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if rightRow == nil {
			r.curRow = nil
			r.tempPlan.Close()
			continue
		}

		// To prevent outer modify the slice. See comment above.
		joinedRow := make([]interface{}, 0, len(r.curRow.Data)+len(rightRow.Data))
		joinedRow = append(append(joinedRow, r.curRow.Data...), rightRow.Data...)

		if r.On != nil {
			r.evalArgs[expression.ExprEvalIdentReferFunc] = func(name string, scope int, index int) (interface{}, error) {
				return joinedRow[index], nil
			}

			b, err := expression.EvalBoolExpr(ctx, r.On, r.evalArgs)
			if err != nil {
				return nil, errors.Trace(err)
			}
			if !b {
				// If On condition not satisified, drop this row
				continue
			}
		}
		row = &plan.Row{
			Data:    joinedRow,
			RowKeys: append(r.curRow.RowKeys, rightRow.RowKeys...),
		}
		return
	}
}
开发者ID:lovedboy,项目名称:tidb,代码行数:65,代码来源:join.go



注:本文中的github.com/pingcap/tidb/expression.EvalBoolExpr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang expression.GetTimeValue函数代码示例发布时间:2022-05-28
下一篇:
Golang expression.EvalBool函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap