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


Golang ast.Expression类代码示例

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


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

示例1: isConstant

func (this *ExpressionSargable) isConstant(e ast.Expression) bool {
	_, err := e.Accept(this.constantChecker)
	if err == nil {
		return true
	}
	return false
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:7,代码来源:expression_sargable.go

示例2: matchesIndex

func (this *ExpressionSargable) matchesIndex(e ast.Expression) bool {
	_, err := e.Accept(this.equivalenceChecker)
	if err == nil {
		return true
	}
	return false
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:7,代码来源:expression_sargable.go

示例3: CanIUseThisIndexForThisWhereClause

func CanIUseThisIndexForThisWhereClause(index catalog.RangeIndex, where ast.Expression, bucket string) (bool, plan.ScanRanges, ast.Expression, error) {

	// convert the index key to formal notation
	indexKeyFormal, err := IndexKeyInFormalNotation(index.Key(), bucket)
	if err != nil {
		return false, nil, nil, err
	}

	// put the where clause into conjunctive normal form
	ennf := ast.NewExpressionNNF()
	whereNNF, err := where.Accept(ennf)
	if err != nil {
		return false, nil, nil, err
	}
	ecnf := ast.NewExpressionCNF()
	whereCNF, err := whereNNF.Accept(ecnf)
	if err != nil {
		return false, nil, nil, err
	}

	switch whereCNF := whereCNF.(type) {
	case *ast.AndOperator:
		// this is an and, we can try to satisfy individual operands
		found := false
		rranges := plan.ScanRanges{}
		for _, oper := range whereCNF.Operands {
			// see if the where clause expression is sargable with respect to the index key
			es := NewExpressionSargable(indexKeyFormal[0])
			oper.Accept(es)
			if es.IsSargable() {
				found = true
				for _, ran := range es.ScanRanges() {
					rranges = MergeRanges(rranges, ran)
					clog.To(planner.CHANNEL, "now ranges are: %v", rranges)
				}
			}
		}
		if found {
			return true, rranges, nil, nil
		}
	default:
		// not an and, we must satisfy the whole expression
		// see if the where clause expression is sargable with respect to the index key
		es := NewExpressionSargable(indexKeyFormal[0])
		whereCNF.Accept(es)
		if es.IsSargable() {
			return true, es.ScanRanges(), nil, nil
		}
	}

	// cannot use this index
	return false, nil, nil, nil
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:53,代码来源:index.go

示例4: Visit

// inorder traversal of the AST to get JS expression out of it
func (this *JsStatement) Visit(e ast.Expression) (ast.Expression, error) {
	switch expr := e.(type) {

	case *ast.DotMemberOperator:
		if this.js.Len() == 0 {
			this.js.WriteString("doc.")
		}
		_, err := expr.Left.Accept(this)
		if err != nil {
			return nil, err
		}
		this.js.WriteString(".")
		_, err = expr.Right.Accept(this)
		if err != nil {
			return nil, err
		}

	case *ast.BracketMemberOperator:
		if this.js.Len() == 0 {
			this.js.WriteString("doc.")
		}
		_, err := expr.Left.Accept(this)
		if err != nil {
			return nil, err
		}
		this.js.WriteString("[")
		_, err = expr.Right.Accept(this)
		if err != nil {
			return nil, err
		}
		this.js.WriteString("]")

	case *ast.Property:
		if this.js.Len() == 0 {
			this.js.WriteString("doc.")
		}
		this.js.WriteString(expr.Path)

	case *ast.LiteralNumber:
		this.js.WriteString(fmt.Sprintf("%v", expr.Val))

	case *ast.LiteralString:
		this.js.WriteString(expr.Val)

	default:
		return e, errors.New("Expression is not supported by indexing currently: " + e.String())

	}
	return e, nil
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:51,代码来源:view_builder.go

示例5: Evaluate

func (this *BaseOperator) Evaluate(e ast.Expression, item *dparval.Value) (*dparval.Value, error) {
	// first ensure the query is avaliable
	item.SetAttachment("query", this.query)
	return e.Evaluate(item)
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:5,代码来源:base.go

示例6: evaluateConstant

func (this *ExpressionSargable) evaluateConstant(e ast.Expression) (*dparval.Value, error) {
	return e.Evaluate(dparval.NewValue(map[string]interface{}{}))
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:3,代码来源:expression_sargable.go


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