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


Golang expression.Expression类代码示例

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


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

示例1: VisitFunction

func (this *DNF) VisitFunction(expr expression.Function) (interface{}, error) {
	var exp expression.Expression = expr

	switch expr := expr.(type) {
	case *expression.IsBoolean:
		exp = expression.NewLE(expr.Operand(), expression.TRUE_EXPR)
	case *expression.IsNumber:
		exp = expression.NewAnd(
			expression.NewGT(expr.Operand(), expression.TRUE_EXPR),
			expression.NewLT(expr.Operand(), expression.EMPTY_STRING_EXPR))
	case *expression.IsString:
		exp = expression.NewAnd(
			expression.NewGE(expr.Operand(), expression.EMPTY_STRING_EXPR),
			expression.NewLT(expr.Operand(), expression.EMPTY_ARRAY_EXPR))
	case *expression.IsArray:
		exp = expression.NewAnd(
			expression.NewGE(expr.Operand(), expression.EMPTY_ARRAY_EXPR),
			expression.NewLT(expr.Operand(), _EMPTY_OBJECT_EXPR))
	case *expression.IsObject:
		// Not equivalent to IS OBJECT. Includes BINARY values.
		exp = expression.NewGE(expr.Operand(), _EMPTY_OBJECT_EXPR)
	}

	return exp, exp.MapChildren(this)
}
开发者ID:pkdevboxy,项目名称:query,代码行数:25,代码来源:dnf.go

示例2: minimalIndexes

func minimalIndexes(sargables map[datastore.Index]*indexEntry, pred expression.Expression) (
	map[datastore.Index]*indexEntry, error) {
	for s, se := range sargables {
		for t, te := range sargables {
			if t == s {
				continue
			}

			if narrowerOrEquivalent(se, te) {
				delete(sargables, t)
			}
		}
	}

	minimals := make(map[datastore.Index]*indexEntry, len(sargables))
	for s, se := range sargables {
		spans, err := SargFor(pred, se.sargKeys, len(se.keys))
		if err != nil || len(spans) == 0 {
			logging.Errorp("Sargable index not sarged", logging.Pair{"pred", pred},
				logging.Pair{"sarg_keys", se.sargKeys}, logging.Pair{"error", err})
			return nil, errors.NewPlanError(nil, fmt.Sprintf("Sargable index not sarged; pred=%v, sarg_keys=%v, error=%v",
				pred.String(), se.sargKeys.String(), err))
			return nil, err
		}

		se.spans = spans
		minimals[s] = se
	}

	return minimals, nil
}
开发者ID:mschoch,项目名称:query,代码行数:31,代码来源:build_scan.go

示例3: LessThan

func LessThan(expr1, expr2 expression.Expression) bool {
	value1 := expr1.Value()
	value2 := expr2.Value()

	return value1 != nil && value2 != nil &&
		value1.Collate(value2) < 0
}
开发者ID:pkdevboxy,项目名称:query,代码行数:7,代码来源:lt.go

示例4: Visit

func (this *JSConverter) Visit(expr expression.Expression) string {
	var buf bytes.Buffer
	s, err := expr.Accept(this)
	if err != nil {
		logging.Errorf("Unexpected error in JSConverter: %v", err)
		return ""
	}

	switch s := s.(type) {
	case string:
		buf.WriteString(s)
		for this.stack.Size() != 0 {
			funcExpr := this.stack.Pop().(*funcExpr)
			buf.WriteString(funcExpr.name)
			if funcExpr.operands.Front() != nil {
				buf.WriteString(writeOperands(funcExpr.operands))
			}
		}

	case []byte:
		buf.WriteString(string(s))
		for this.stack.Size() != 0 {
			funcExpr := this.stack.Pop().(*funcExpr)
			buf.WriteString(funcExpr.name)
			if funcExpr.operands.Front() != nil {
				buf.WriteString(writeOperands(funcExpr.operands))
			}
		}

	default:
		buf.WriteString(s.(string))
	}

	return buf.String()
}
开发者ID:pkdevboxy,项目名称:query,代码行数:35,代码来源:jsconverter.go

示例5: constrainAggregate

/*

Constrain the WHERE condition to reflect the aggregate query. For
example:

SELECT AVG(v) FROM widget w;

is rewritten as:

SELECT AVG(v) FROM widget w WHERE v IS NOT NULL;

This enables the query to use an index on v.

*/
func constrainAggregate(cond expression.Expression, aggs map[string]algebra.Aggregate) expression.Expression {
	var first expression.Expression
	for _, agg := range aggs {
		if first == nil {
			first = agg.Operand()
			if first == nil {
				return cond
			}

			continue
		}

		op := agg.Operand()
		if op == nil || !first.EquivalentTo(op) {
			return cond
		}
	}

	if first == nil {
		return cond
	}

	var constraint expression.Expression = expression.NewIsNotNull(first)
	if cond != nil {
		constraint = expression.NewAnd(cond, constraint)
	}

	return constraint
}
开发者ID:jmptrader,项目名称:query,代码行数:43,代码来源:build_select_sub.go

示例6: SubsetOf

func SubsetOf(expr1, expr2 expression.Expression) bool {
	v2 := expr2.Value()
	if v2 != nil {
		return v2.Truth()
	}

	s := newSubset(expr1)
	result, _ := expr2.Accept(s)
	return result.(bool)
}
开发者ID:pkdevboxy,项目名称:query,代码行数:10,代码来源:subset.go

示例7: sargFor

func sargFor(pred, expr expression.Expression, missingHigh bool) (plan.Spans, error) {
	s := newSarg(pred)
	s.SetMissingHigh(missingHigh)

	r, err := expr.Accept(s)
	if err != nil || r == nil {
		return nil, err
	}

	rs := r.(plan.Spans)
	return rs, nil
}
开发者ID:pkdevboxy,项目名称:query,代码行数:12,代码来源:sarg.go

示例8: NewExecute

/*
The function NewExecute returns a pointer to the Execute
struct with the input argument expressions value as a field.
*/
func NewExecute(prepared expression.Expression) *Execute {
	var preparedValue value.Value

	switch prepared := prepared.(type) {
	case *expression.Identifier:
		preparedValue = value.NewValue(prepared.Alias())
	default:
		preparedValue = prepared.Value()
	}

	rv := &Execute{
		prepared: preparedValue,
	}

	rv.stmt = rv
	return rv
}
开发者ID:pkdevboxy,项目名称:query,代码行数:21,代码来源:execute.go

示例9: NewPair

/*
Create a key value pair using the operands of the input
expression Array construct and return.
*/
func NewPair(expr expression.Expression) (*Pair, error) {
	array, ok := expr.(*expression.ArrayConstruct)
	if !ok {
		return nil, fmt.Errorf("Invalid VALUES expression %s", expr.String())
	}

	operands := array.Operands()
	if len(operands) != 2 {
		return nil, fmt.Errorf("Invalid VALUES expression %s", expr.String())
	}

	pair := &Pair{
		Key:   operands[0],
		Value: operands[1],
	}

	return pair, nil
}
开发者ID:pkdevboxy,项目名称:query,代码行数:22,代码来源:pair.go

示例10: dnfComplexity

func dnfComplexity(expr expression.Expression, max int) int {
	comp := 0

	switch expr := expr.(type) {
	case *expression.Or:
		comp = len(expr.Operands())
	}

	if comp < max {
		children := expr.Children()
		for _, child := range children {
			childComp := dnfComplexity(child, max-comp)
			comp += childComp
			if comp >= max {
				break
			}
		}
	}

	return comp
}
开发者ID:pkdevboxy,项目名称:query,代码行数:21,代码来源:dnf.go

示例11: VisitNot

func (this *DNF) VisitNot(expr *expression.Not) (interface{}, error) {
	err := expr.MapChildren(this)
	if err != nil {
		return nil, err
	}

	var exp expression.Expression = expr

	switch operand := expr.Operand().(type) {
	case *expression.Not:
		exp = operand.Operand()
	case *expression.And:
		operands := make(expression.Expressions, len(operand.Operands()))
		for i, op := range operand.Operands() {
			operands[i] = expression.NewNot(op)
		}

		exp = expression.NewOr(operands...)
	case *expression.Or:
		operands := make(expression.Expressions, len(operand.Operands()))
		for i, op := range operand.Operands() {
			operands[i] = expression.NewNot(op)
		}

		and := expression.NewAnd(operands...)
		return this.VisitAnd(and)
	case *expression.Eq:
		exp = expression.NewOr(expression.NewLT(operand.First(), operand.Second()),
			expression.NewLT(operand.Second(), operand.First()))
	case *expression.LT:
		exp = expression.NewLE(operand.Second(), operand.First())
	case *expression.LE:
		exp = expression.NewLT(operand.Second(), operand.First())
	default:
		return expr, nil
	}

	return exp, exp.MapChildren(this)
}
开发者ID:pkdevboxy,项目名称:query,代码行数:39,代码来源:dnf.go

示例12: newSargDefault

func newSargDefault(pred expression.Expression) *sargDefault {
	var spans plan.Spans
	if pred.PropagatesNull() {
		spans = _VALUED_SPANS
	} else if pred.PropagatesMissing() {
		spans = _FULL_SPANS
	}

	rv := &sargDefault{}
	rv.sarger = func(expr2 expression.Expression) (plan.Spans, error) {
		if SubsetOf(pred, expr2) {
			return _SELF_SPANS, nil
		}

		if spans != nil && pred.DependsOn(expr2) {
			return spans, nil
		}

		return nil, nil
	}

	return rv
}
开发者ID:pkdevboxy,项目名称:query,代码行数:23,代码来源:sarg_default.go

示例13: LessThanOrEquals

func LessThanOrEquals(expr1, expr2 expression.Expression) bool {
	return LessThan(expr1, expr2) || expr1.EquivalentTo(expr2)
}
开发者ID:pkdevboxy,项目名称:query,代码行数:3,代码来源:lt.go

示例14: newSubset

func newSubset(expr expression.Expression) expression.Visitor {
	s, _ := expr.Accept(_SUBSET_FACTORY)
	return s.(expression.Visitor)
}
开发者ID:pkdevboxy,项目名称:query,代码行数:4,代码来源:subset.go

示例15: formalize

// Formalize e by prefixing field names with the bucketName
func (this *JsStatement) formalize(bucketName string, e expression.Expression) (expression.Expression, error) {
	f := expression.NewFormalizer()
	f.Keyspace = bucketName
	f.Allowed.SetField(bucketName, true)
	return f.Map(e.Copy())
}
开发者ID:jmptrader,项目名称:query,代码行数:7,代码来源:view_builder.go


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