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

Golang parser.WalkExpr函数代码示例

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

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



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


示例16: checkAggregateExprs

// Check if exprs use aggregation and if they are valid.
// An expression is valid if:
// - it is an aggregate expression, or
// - it appears verbatim in groupBy, or
// - it is not a qvalue, and all of its subexpressions (as defined by
// its Walk implementation) are valid
// NB: "verbatim" above is defined using a string-equality comparison
// as an approximation of a recursive tree-equality comparison.
//
// For example:
// Invalid: `SELECT k, SUM(v) FROM kv`
// - `k` is unaggregated and does not appear in the (missing) GROUP BY.
// Valid:      `SELECT k, SUM(v) FROM kv GROUP BY k`
// Also valid: `SELECT UPPER(k), SUM(v) FROM kv GROUP BY UPPER(k)`
// - `UPPER(k)` appears in GROUP BY.
// Also valid: `SELECT UPPER(k), SUM(v) FROM kv GROUP BY k`
// - `k` appears in GROUP BY, so `UPPER(k)` is OK, but...
// Invalid:    `SELECT k, SUM(v) FROM kv GROUP BY UPPER(k)`
// - `k` does not appear in GROUP BY; UPPER(k) does nothing to help here.
func checkAggregateExprs(groupBy parser.GroupBy, exprs []parser.Expr) error {
	v := checkAggregateVisitor{}

	// TODO(dt): consider other ways of comparing expression trees.
	v.groupStrs = make(map[string]struct{}, len(groupBy))
	for i := range groupBy {
		v.groupStrs[groupBy[i].String()] = struct{}{}
	}

	for _, expr := range exprs {
		_ = parser.WalkExpr(&v, expr)
		if v.aggrErr != nil {
			return v.aggrErr
		}
	}
	return nil
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:36,代码来源:group.go


示例17: 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, sources multiSourceInfo, qvals qvalMap, v *qnameVisitor,
) (parser.Expr, error) {
	if expr == nil {
		return expr, nil
	}
	if v == nil {
		v = new(qnameVisitor)
	}
	*v = qnameVisitor{
		qt: qvalResolver{
			sources: sources,
			qvals:   qvals,
		},
	}
	expr, _ = parser.WalkExpr(v, expr)
	return expr, v.err
}
开发者ID:YuleiXiao,项目名称:cockroach,代码行数:21,代码来源:select_qvalue.go


示例18: processExpression

// processExpression parses the string expression inside an Expression,
// interpreting $0, $1, etc as indexed variables.
func processExpression(exprSpec Expression, h *parser.IndexedVarHelper) (parser.TypedExpr, error) {
	expr, err := parser.ParseExprTraditional(exprSpec.Expr)
	if err != nil {
		return nil, err
	}

	// Convert ValArgs to IndexedVars
	v := valArgsConvert{h: h, err: nil}
	expr, _ = parser.WalkExpr(&v, expr)
	if v.err != nil {
		return nil, v.err
	}

	// Convert to a fully typed expression.
	typedExpr, err := parser.TypeCheck(expr, nil, nil)
	if err != nil {
		return nil, err
	}

	return typedExpr, nil
}
开发者ID:GitGoldie,项目名称:cockroach,代码行数:23,代码来源:dist_sql_expr.go


示例19: extractAggregateFuncs

func extractAggregateFuncs(expr parser.Expr) (parser.Expr, []*aggregateFunc, error) {
	v := extractAggregatesVisitor{}
	expr = parser.WalkExpr(&v, expr)
	return expr, v.funcs, v.err
}
开发者ID:kumarh1982,项目名称:cockroach,代码行数:5,代码来源:group.go


示例20: Walk

func (q *qvalue) Walk(v parser.Visitor) {
	q.datum = parser.WalkExpr(v, q.datum).(parser.Datum)
}
开发者ID:soniabhishek,项目名称:cockroach,代码行数:3,代码来源:select_qvalue.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang parser.ComparisonExpr类代码示例发布时间:2022-05-23
下一篇:
Golang parser.TypeCheckExpr函数代码示例发布时间: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