func newSubsetLike(expr expression.BinaryFunction, re *regexp.Regexp) expression.Visitor { if re == nil { // Pattern is not a constant return newSubsetDefault(expr) } prefix, complete := re.LiteralPrefix() if complete { eq := expression.NewEq(expr.First(), expression.NewConstant(prefix)) return newSubsetEq(eq.(*expression.Eq)) } if prefix == "" { return newSubsetDefault(expr) } var and expression.Expression le := expression.NewLE(expression.NewConstant(prefix), expr.First()) last := len(prefix) - 1 if prefix[last] < math.MaxUint8 { bytes := []byte(prefix) bytes[last]++ and = expression.NewAnd(le, expression.NewLT( expr.First(), expression.NewConstant(string(bytes)))) } else { and = expression.NewAnd(le, expression.NewLT( expr.First(), expression.EMPTY_ARRAY_EXPR)) } return newSubsetAnd(and.(*expression.And)) }
func (this *NNF) VisitIn(expr *expression.In) (interface{}, error) { err := expr.MapChildren(this) if err != nil { return nil, err } a, ok := expr.Second().(*expression.ArrayConstruct) if !ok { return expr, nil } first := expr.First() operands := make(expression.Expressions, len(a.Operands())) for i, op := range a.Operands() { operands[i] = expression.NewEq(first, op) } return expression.NewOr(operands...), nil }
func newSargLike(expr expression.BinaryFunction, re *regexp.Regexp) expression.Visitor { prefix := "" if re != nil { prefix, complete := re.LiteralPrefix() if complete { eq := expression.NewEq(expr.First(), expression.NewConstant(prefix)) return newSargEq(eq.(*expression.Eq)) } } rv := &sargLike{} rv.sarg = func(expr2 expression.Expression) (Spans, error) { if expr.EquivalentTo(expr2) { return _SELF_SPANS, nil } if !expr.First().EquivalentTo(expr2) { return nil, nil } span := &Span{} span.Range.Low = expression.Expressions{expression.NewConstant(prefix)} last := len(prefix) - 1 if last >= 0 && prefix[last] < math.MaxUint8 { bytes := []byte(prefix) bytes[last]++ span.Range.High = expression.Expressions{expression.NewConstant(string(bytes))} } else { span.Range.High = _EMPTY_ARRAY } span.Range.Inclusion = datastore.LOW return Spans{span}, nil } return rv }