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

Golang parser.DTuple类代码示例

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

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



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

示例1: Visit

func (v *subqueryVisitor) Visit(expr parser.Expr, pre bool) (parser.Visitor, parser.Expr) {
	if v.pErr != nil {
		return nil, expr
	}
	if !pre {
		v.path = v.path[:len(v.path)-1]
		return nil, expr
	}
	v.path = append(v.path, expr)

	var exists *parser.ExistsExpr
	subquery, ok := expr.(*parser.Subquery)
	if !ok {
		exists, ok = expr.(*parser.ExistsExpr)
		if !ok {
			return v, expr
		}
		subquery, ok = exists.Subquery.(*parser.Subquery)
		if !ok {
			return v, expr
		}
	}

	// Calling makePlan() might recursively invoke expandSubqueries, so we need a
	// copy of the planner in order for there to have a separate subqueryVisitor.
	planMaker := *v.planner
	var plan planNode
	if plan, v.pErr = planMaker.makePlan(subquery.Select, false); v.pErr != nil {
		return nil, expr
	}

	if exists != nil {
		// For EXISTS expressions, all we want to know is if there is at least one
		// result.
		if plan.Next() {
			return v, parser.DBool(true)
		}
		v.pErr = plan.PErr()
		if v.pErr != nil {
			return nil, expr
		}
		return v, parser.DBool(false)
	}

	columns, multipleRows := v.getSubqueryContext()
	if n := len(plan.Columns()); columns != n {
		switch columns {
		case 1:
			v.pErr = roachpb.NewUErrorf("subquery must return only one column, found %d", n)
		default:
			v.pErr = roachpb.NewUErrorf("subquery must return %d columns, found %d", columns, n)
		}
		return nil, expr
	}

	var result parser.Expr
	if multipleRows {
		var rows parser.DTuple
		for plan.Next() {
			values := plan.Values()
			switch len(values) {
			case 1:
				// This seems hokey, but if we don't do this then the subquery expands
				// to a tuple of tuples instead of a tuple of values and an expression
				// like "k IN (SELECT foo FROM bar)" will fail because we're comparing
				// a single value against a tuple.
				rows = append(rows, values[0])
			default:
				// The result from plan.Values() is only valid until the next call to
				// plan.Next(), so make a copy.
				valuesCopy := make(parser.DTuple, len(values))
				copy(valuesCopy, values)
				rows = append(rows, valuesCopy)
			}
		}
		rows.Normalize()
		result = rows
	} else {
		result = parser.DNull
		for plan.Next() {
			values := plan.Values()
			switch len(values) {
			case 1:
				result = values[0]
			default:
				valuesCopy := make(parser.DTuple, len(values))
				copy(valuesCopy, values)
				result = valuesCopy
			}
			if plan.Next() {
				v.pErr = roachpb.NewUErrorf("more than one row returned by a subquery used as an expression")
				return nil, expr
			}
		}
	}

	v.pErr = plan.PErr()
	if v.pErr != nil {
		return nil, expr
	}
//.........这里部分代码省略.........
开发者ID:billhongs,项目名称:cockroach,代码行数:101,代码来源:subquery.go


示例2: doEval

func (s *subquery) doEval() (parser.Datum, error) {
	var result parser.Datum
	switch s.execMode {
	case execModeExists:
		// For EXISTS expressions, all we want to know is if there is at least one
		// result.
		next, err := s.plan.Next()
		if s.err = err; err != nil {
			return result, err
		}
		if next {
			result = parser.MakeDBool(true)
		}
		if result == nil {
			result = parser.MakeDBool(false)
		}

	case execModeAllRows:
		var rows parser.DTuple
		next, err := s.plan.Next()
		for ; next; next, err = s.plan.Next() {
			values := s.plan.Values()
			switch len(values) {
			case 1:
				// This seems hokey, but if we don't do this then the subquery expands
				// to a tuple of tuples instead of a tuple of values and an expression
				// like "k IN (SELECT foo FROM bar)" will fail because we're comparing
				// a single value against a tuple.
				rows = append(rows, values[0])
			default:
				// The result from plan.Values() is only valid until the next call to
				// plan.Next(), so make a copy.
				valuesCopy := make(parser.DTuple, len(values))
				copy(valuesCopy, values)
				rows = append(rows, &valuesCopy)
			}
		}
		if s.err = err; err != nil {
			return result, err
		}
		if s.wantNormalized {
			rows.Normalize()
		}
		result = &rows

	case execModeOneRow:
		result = parser.DNull
		next, err := s.plan.Next()
		if s.err = err; err != nil {
			return result, err
		}
		if next {
			values := s.plan.Values()
			switch len(values) {
			case 1:
				result = values[0]
			default:
				valuesCopy := make(parser.DTuple, len(values))
				copy(valuesCopy, values)
				result = &valuesCopy
			}
			another, err := s.plan.Next()
			if s.err = err; err != nil {
				return result, err
			}
			if another {
				s.err = fmt.Errorf("more than one row returned by a subquery used as an expression")
				return result, s.err
			}
		}
	}

	return result, nil
}
开发者ID:JKhawaja,项目名称:cockroach,代码行数:74,代码来源:subquery.go


示例3: VisitPre

func (v *subqueryVisitor) VisitPre(expr parser.Expr) (recurse bool, newExpr parser.Expr) {
	if v.err != nil {
		return false, expr
	}
	v.path = append(v.path, expr)

	var exists *parser.ExistsExpr
	subquery, ok := expr.(*parser.Subquery)
	if !ok {
		exists, ok = expr.(*parser.ExistsExpr)
		if !ok {
			return true, expr
		}
		subquery, ok = exists.Subquery.(*parser.Subquery)
		if !ok {
			return true, expr
		}
	}

	// Calling makePlan() might recursively invoke expandSubqueries, so we need a
	// copy of the planner in order for there to have a separate subqueryVisitor.
	// TODO(nvanbenschoten) We should propagate a desired type here.
	// TODO(knz) the instantiation of the subquery's select node should be moved
	//     to the TypeCheck() method once the prepare and execute phase are separated
	//     for select nodes.
	planMaker := *v.planner
	plan, err := planMaker.makePlan(subquery.Select, nil, false)
	if err != nil {
		return false, expr
	}

	if v.evalCtx.PrepareOnly {
		return false, expr
	}

	if v.err = plan.Start(); v.err != nil {
		return false, expr
	}

	if exists != nil {
		// For EXISTS expressions, all we want to know is if there is at least one
		// result.
		if plan.Next() {
			return true, parser.MakeDBool(true)
		}
		v.err = plan.Err()
		if v.err != nil {
			return false, expr
		}
		return true, parser.MakeDBool(false)
	}

	columns, multipleRows := v.getSubqueryContext()
	if n := len(plan.Columns()); columns != n {
		switch columns {
		case 1:
			v.err = fmt.Errorf("subquery must return only one column, found %d", n)
		default:
			v.err = fmt.Errorf("subquery must return %d columns, found %d", columns, n)
		}
		return true, expr
	}

	var result parser.Expr
	if multipleRows {
		var rows parser.DTuple
		for plan.Next() {
			values := plan.Values()
			switch len(values) {
			case 1:
				// This seems hokey, but if we don't do this then the subquery expands
				// to a tuple of tuples instead of a tuple of values and an expression
				// like "k IN (SELECT foo FROM bar)" will fail because we're comparing
				// a single value against a tuple.
				rows = append(rows, values[0])
			default:
				// The result from plan.Values() is only valid until the next call to
				// plan.Next(), so make a copy.
				valuesCopy := make(parser.DTuple, len(values))
				copy(valuesCopy, values)
				rows = append(rows, &valuesCopy)
			}
		}
		rows.Normalize()
		result = &rows
	} else {
		result = parser.DNull
		for plan.Next() {
			values := plan.Values()
			switch len(values) {
			case 1:
				result = values[0]
			default:
				valuesCopy := make(parser.DTuple, len(values))
				copy(valuesCopy, values)
				result = &valuesCopy
			}
			if plan.Next() {
				v.err = fmt.Errorf("more than one row returned by a subquery used as an expression")
				return false, expr
//.........这里部分代码省略.........
开发者ID:GitGoldie,项目名称:cockroach,代码行数:101,代码来源:subquery.go


示例4: Visit

func (v *subqueryVisitor) Visit(expr parser.Expr, pre bool) (parser.Visitor, parser.Expr) {
	if v.err != nil {
		return nil, expr
	}
	if !pre {
		v.path = v.path[:len(v.path)-1]
		return nil, expr
	}
	v.path = append(v.path, expr)

	subquery, ok := expr.(*parser.Subquery)
	if !ok {
		return v, expr
	}

	var plan planNode
	if plan, v.err = v.makePlan(subquery.Select); v.err != nil {
		return nil, expr
	}

	columns, multipleRows := v.getSubqueryContext()
	if n := len(plan.Columns()); columns != n {
		switch columns {
		case 1:
			v.err = fmt.Errorf("subquery must return only one column, found %d", n)
		default:
			v.err = fmt.Errorf("subquery must return %d columns, found %d", columns, n)
		}
		return nil, expr
	}

	var result parser.Expr
	if multipleRows {
		var rows parser.DTuple
		for plan.Next() {
			values := plan.Values()
			switch len(values) {
			case 1:
				// This seems hokey, but if we don't do this then the subquery expands
				// to a tuple of tuples instead of a tuple of values and an expression
				// like "k IN (SELECT foo FROM bar)" will fail because we're comparing
				// a single value against a tuple.
				rows = append(rows, values[0])
			default:
				// The result from plan.Values() is only valid until the next call to
				// plan.Next(), so make a copy.
				valuesCopy := make(parser.DTuple, len(values))
				copy(valuesCopy, values)
				rows = append(rows, valuesCopy)
			}
		}
		rows.Normalize()
		result = rows
	} else {
		result = parser.DNull
		for plan.Next() {
			values := plan.Values()
			switch len(values) {
			case 1:
				result = values[0]
			default:
				valuesCopy := make(parser.DTuple, len(values))
				copy(valuesCopy, values)
				result = valuesCopy
			}
			if plan.Next() {
				v.err = fmt.Errorf("more than one row returned by a subquery used as an expression")
				return nil, expr
			}
		}
	}

	v.err = plan.Err()
	if v.err != nil {
		return nil, expr
	}
	return v, result
}
开发者ID:nporsche,项目名称:cockroach,代码行数:78,代码来源:subquery.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang parser.Datum类代码示例发布时间:2022-05-23
下一篇:
Golang parser.DDecimal类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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