Beispiel #1
0
func encodeStartConstraintDescending(
	spans []span, c *parser.ComparisonExpr) {
	switch c.Operator {
	case parser.Is:
		// An IS NULL expressions allows us to constrain the start of the range
		// to begin at NULL.
		if c.Right != parser.DNull {
			panic("Expected NULL operand for IS operator.")
		}
		for i := range spans {
			spans[i].start = encoding.EncodeNullDescending(spans[i].start)
		}
	case parser.LE, parser.EQ:
		if datum, ok := c.Right.(parser.Datum); ok {
			key, pErr := encodeTableKey(nil, datum, encoding.Descending)
			if pErr != nil {
				panic(pErr)
			}
			// Append the constraint to all of the existing spans.
			for i := range spans {
				spans[i].start = append(spans[i].start, key...)
			}
		}
	case parser.LT:
		// A "<" constraint is the last start constraint. Since the constraint
		// is exclusive and the start key is inclusive, we're going to apply
		// a .PrefixEnd().
		if datum, ok := c.Right.(parser.Datum); ok {
			key, pErr := encodeTableKey(nil, datum, encoding.Descending)
			if pErr != nil {
				panic(pErr)
			}
			// Append the constraint to all of the existing spans.
			for i := range spans {
				spans[i].start = append(spans[i].start, key...)
				spans[i].start = spans[i].start.PrefixEnd()
			}
		}
	default:
		panic(fmt.Errorf("unexpected operator: %s", c.String()))
	}
}
Beispiel #2
0
func encodeEndConstraintDescending(spans []span, c *parser.ComparisonExpr,
	isLastEndConstraint bool) {
	switch c.Operator {
	case parser.IsNot:
		// An IS NULL expressions allows us to constrain the end of the range
		// to stop at NULL.
		if c.Right != parser.DNull {
			panic("Expected NULL operand for IS NOT operator.")
		}
		for i := range spans {
			spans[i].end = encoding.EncodeNotNullDescending(spans[i].end)
		}
	case parser.GE, parser.EQ:
		datum := c.Right.(parser.Datum)
		for i := range spans {
			spans[i].end = encodeInclusiveEndValue(
				spans[i].end, datum, encoding.Descending, isLastEndConstraint)
		}
	case parser.GT:
		panic("'>' operators should have been transformed to '>='.")
	default:
		panic(fmt.Errorf("unexpected operator: %s", c.String()))
	}
}