當前位置: 首頁>>代碼示例>>Golang>>正文


Golang parser.WalkExpr函數代碼示例

本文整理匯總了Golang中github.com/cockroachdb/cockroach/sql/parser.WalkExpr函數的典型用法代碼示例。如果您正苦於以下問題:Golang WalkExpr函數的具體用法?Golang WalkExpr怎麽用?Golang WalkExpr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了WalkExpr函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: applyConstraints

// applyConstraints applies the constraints on values specified by constraints
// to an expression, simplifying the expression where possible. For example, if
// the expression is "a = 1" and the constraint is "a = 1", the expression can
// be simplified to "true". If the expression is "a = 1 AND b > 2" and the
// constraint is "a = 1", the expression is simplified to "b > 2".
//
// Note that applyConstraints currently only handles simple cases.
func applyConstraints(expr parser.Expr, constraints indexConstraints) parser.Expr {
	v := &applyConstraintsVisitor{}
	for _, c := range constraints {
		v.constraint = c
		expr = parser.WalkExpr(v, expr)
		// We can only continue to apply the constraints if the constraints we have
		// applied so far are equality constraints. There are two cases to
		// consider: the first is that both the start and end constraints are
		// equality.
		if c.start == c.end {
			if c.start.Operator == parser.EQ {
				continue
			}
			// The second case is that both the start and end constraint are an IN
			// operator with only a single value.
			if c.start.Operator == parser.In && len(c.start.Right.(parser.DTuple)) == 1 {
				continue
			}
		}
		break
	}
	if expr == parser.DBool(true) {
		return nil
	}
	return expr
}
開發者ID:surpass,項目名稱:cockroach,代碼行數:33,代碼來源:select.go

示例2: applyConstraints

// applyConstraints applies the constraints on values specified by constraints
// to an expression, simplifying the expression where possible. For example, if
// the expression is "a = 1" and the constraint is "a = 1", the expression can
// be simplified to "true". If the expression is "a = 1 AND b > 2" and the
// constraint is "a = 1", the expression is simplified to "b > 2".
//
// Note that applyConstraints currently only handles simple cases.
func applyConstraints(expr parser.Expr, constraints orIndexConstraints) parser.Expr {
	if len(constraints) != 1 {
		// We only support simplifying the expressions if there aren't multiple
		// disjunctions (top-level OR branches).
		return expr
	}
	v := &applyConstraintsVisitor{}
	for _, c := range constraints[0] {
		v.constraint = c
		expr, _ = parser.WalkExpr(v, expr)
		// We can only continue to apply the constraints if the constraints we have
		// applied so far are equality constraints. There are two cases to
		// consider: the first is that both the start and end constraints are
		// equality.
		if c.start == c.end {
			if c.start.Operator == parser.EQ {
				continue
			}
			// The second case is that both the start and end constraint are an IN
			// operator with only a single value.
			if c.start.Operator == parser.In && len(c.start.Right.(parser.DTuple)) == 1 {
				continue
			}
		}
		break
	}
	if expr == parser.DBool(true) {
		return nil
	}
	return expr
}
開發者ID:petermattis,項目名稱:cockroach,代碼行數:38,代碼來源:index_selection.go

示例3: countVars

// countVars counts how many *QualifiedName and *qvalue nodes are in an expression.
func countVars(expr parser.Expr) (numQNames, numQValues int) {
	v := countVarsVisitor{}
	if expr != nil {
		parser.WalkExpr(&v, expr)
	}
	return v.numQNames, v.numQValues
}
開發者ID:binlijin,項目名稱:cockroach,代碼行數:8,代碼來源:expr_filter_test.go

示例4: collectSubqueryPlans

func (p *planner) collectSubqueryPlans(expr parser.Expr, result []planNode) []planNode {
	if expr == nil {
		return result
	}
	p.collectSubqueryPlansVisitor = collectSubqueryPlansVisitor{plans: result}
	_, _ = parser.WalkExpr(&p.collectSubqueryPlansVisitor, expr)
	return p.collectSubqueryPlansVisitor.plans
}
開發者ID:JKhawaja,項目名稱:cockroach,代碼行數:8,代碼來源:subquery.go

示例5: expandSubqueryPlans

func (p *planner) expandSubqueryPlans(expr parser.Expr) error {
	if expr == nil {
		return nil
	}
	p.subqueryPlanVisitor = subqueryPlanVisitor{doExpand: true}
	_, _ = parser.WalkExpr(&p.subqueryPlanVisitor, expr)
	return p.subqueryPlanVisitor.err
}
開發者ID:JKhawaja,項目名稱:cockroach,代碼行數:8,代碼來源:subquery.go

示例6: Walk

func (q *qvalue) Walk(v parser.Visitor) parser.Expr {
	e, _ := parser.WalkExpr(v, q.datum)
	// Typically Walk implementations are not supposed to modify nodes in-place, in order to
	// preserve the original transaction statement and expressions. However, `qvalue` is our type
	// (which we have "stiched" into an expression) so we aren't modifying an original expression.
	q.datum = e.(parser.Datum)
	return q
}
開發者ID:cuongdo,項目名稱:cockroach,代碼行數:8,代碼來源:select_qvalue.go

示例7: resolveQNames

func (s *selectNode) resolveQNames(expr parser.Expr) (parser.Expr, *roachpb.Error) {
	if expr == nil {
		return expr, nil
	}
	v := qnameVisitor{selNode: s}
	expr = parser.WalkExpr(&v, expr)
	return expr, v.pErr
}
開發者ID:ekkotron,項目名稱:cockroach,代碼行數:8,代碼來源:select_qvalue.go

示例8: resolveQNames

func (n *scanNode) resolveQNames(expr parser.Expr) (parser.Expr, error) {
	if expr == nil {
		return expr, nil
	}
	v := qnameVisitor{scanNode: n}
	expr = parser.WalkExpr(&v, expr)
	return expr, v.err
}
開發者ID:nkhuyu,項目名稱:cockroach,代碼行數:8,代碼來源:scan.go

示例9: aggregateInWhere

func (p *planner) aggregateInWhere(where *parser.Where) bool {
	if where != nil {
		defer p.isAggregateVisitor.reset()
		_ = parser.WalkExpr(&p.isAggregateVisitor, where.Expr)
		if p.isAggregateVisitor.aggregated {
			return true
		}
	}
	return false
}
開發者ID:danieldeb,項目名稱:cockroach,代碼行數:10,代碼來源:group.go

示例10: startSubqueryPlans

func (p *planner) startSubqueryPlans(expr parser.Expr) error {
	if expr == nil {
		return nil
	}
	// We also run and pre-evaluate the subqueries during start,
	// so as to avoid re-running the sub-query for every row
	// in the results of the surrounding planNode.
	p.subqueryPlanVisitor = subqueryPlanVisitor{doStart: true, doEval: true}
	_, _ = parser.WalkExpr(&p.subqueryPlanVisitor, expr)
	return p.subqueryPlanVisitor.err
}
開發者ID:JKhawaja,項目名稱:cockroach,代碼行數:11,代碼來源:subquery.go

示例11: applyConstraints

// applyConstraints applies the constraints on values specified by constraints
// to an expression, simplifying the expression where possible. For example, if
// the expression is "a = 1" and the constraint is "a = 1", the expression can
// be simplified to "true". If the expression is "a = 1 AND b > 2" and the
// constraint is "a = 1", the expression is simplified to "b > 2".
//
// Note that applyConstraints currently only handles simple cases.
func applyConstraints(expr parser.Expr, constraints indexConstraints) parser.Expr {
	v := &applyConstraintsVisitor{}
	for _, c := range constraints {
		v.constraint = c
		expr = parser.WalkExpr(v, expr)
	}
	if expr == parser.DBool(true) {
		return nil
	}
	return expr
}
開發者ID:JonathanHub,項目名稱:cockroach,代碼行數:18,代碼來源:select.go

示例12: isAggregate

func (p *planner) isAggregate(n *parser.Select) bool {
	if n.Having != nil || len(n.GroupBy) > 0 {
		return true
	}

	for _, target := range n.Exprs {
		_ = parser.WalkExpr(&p.isAggregateVisitor, target.Expr)
		if p.isAggregateVisitor.aggregated {
			return true
		}
	}
	return false
}
開發者ID:l2x,項目名稱:cockroach,代碼行數:13,代碼來源:group.go

示例13: resolveQNames

func resolveQNames(table *tableInfo, qvals qvalMap, expr parser.Expr) (parser.Expr, error) {
	if expr == nil {
		return expr, nil
	}
	v := qnameVisitor{
		qt: qvalResolver{
			table: table,
			qvals: qvals,
		},
	}
	expr = parser.WalkExpr(&v, expr)
	return expr, v.err
}
開發者ID:soniabhishek,項目名稱:cockroach,代碼行數:13,代碼來源:select_qvalue.go

示例14: isAggregateExprs

func isAggregateExprs(n *parser.Select) bool {
	if n.Having != nil || len(n.GroupBy) > 0 {
		return true
	}

	v := isAggregateVisitor{}

	for _, target := range n.Exprs {
		_ = parser.WalkExpr(&v, target.Expr)
		if v.aggregated {
			return true
		}
	}
	return false
}
開發者ID:kaustubhkurve,項目名稱:cockroach,代碼行數:15,代碼來源:group.go

示例15: resolveQNames

// resolveQNames walks the provided expression and resolves all qualified
// names using the tableInfo and qvalMap. The function takes an optional
// qnameVisitor to provide the caller the option of avoiding an allocation.
func resolveQNames(expr parser.Expr, table *tableInfo, qvals qvalMap, v *qnameVisitor) (parser.Expr, error) {
	if expr == nil {
		return expr, nil
	}
	if v == nil {
		v = new(qnameVisitor)
	}
	*v = qnameVisitor{
		qt: qvalResolver{
			table: table,
			qvals: qvals,
		},
	}
	expr, _ = parser.WalkExpr(v, expr)
	return expr, v.err
}
開發者ID:GitGoldie,項目名稱:cockroach,代碼行數:19,代碼來源:select_qvalue.go


注:本文中的github.com/cockroachdb/cockroach/sql/parser.WalkExpr函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。