Exemplo n.º 1
0
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()
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
func newSargable(pred expression.Expression) expression.Visitor {
	s, _ := pred.Accept(_SARGABLE_FACTORY)
	return s.(expression.Visitor)
}
Exemplo n.º 5
0
func newSarg(pred expression.Expression) sarg {
	s, _ := pred.Accept(_SARG_FACTORY)
	return s.(sarg)
}
Exemplo n.º 6
0
func newSubset(expr expression.Expression) expression.Visitor {
	s, _ := expr.Accept(_SUBSET_FACTORY)
	return s.(expression.Visitor)
}