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


Golang parser.DTuple类代码示例

本文整理汇总了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;未经允许,请勿转载。