当前位置: 首页>>代码示例>>Golang>>正文


Golang Plan.Close方法代码示例

本文整理汇总了Golang中github.com/pingcap/tidb/plan.Plan.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang Plan.Close方法的具体用法?Golang Plan.Close怎么用?Golang Plan.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pingcap/tidb/plan.Plan的用法示例。


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

示例1: 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

示例2: 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[expressions.ExprEvalIdentFunc] = func(name string) (interface{}, error) {
			return GetIdentValue(name, r.Fields, joined, field.DefaultFieldFlag)
		}
		var b bool
		b, err = expressions.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:studygolang,项目名称:tidb,代码行数:51,代码来源:join.go


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