Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/qql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _parse_insert_bulk_body(self) -> InsertBulkStmt:
model=model, hybrid=hybrid, sparse_model=sparse_model,
)

def _parse_create(self) -> CreateCollectionStmt:
def _parse_create(self) -> CreateCollectionStmt | CreateIndexStmt:
self._expect(TokenKind.CREATE)
if self._peek().kind == TokenKind.COLLECTION:
self._advance()
Expand Down Expand Up @@ -213,7 +213,13 @@ def _parse_quantize_clause(self) -> QuantizationConfig:
always_ram: bool = False
if self._peek().kind == TokenKind.QUANTILE:
self._advance()
quantile = float(self._expect(TokenKind.FLOAT).value)
quantile_tok = self._peek()
quantile = float(self._parse_number())
if not 0.0 <= quantile <= 1.0:
raise QQLSyntaxError(
f"QUANTILE must be between 0 and 1 inclusive, got {quantile}",
quantile_tok.pos,
)
if self._peek().kind == TokenKind.ALWAYS:
self._advance()
self._expect(TokenKind.RAM)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,16 @@ def test_scalar_with_quantile(self):
assert node.quantization.type == QuantizationType.SCALAR
assert node.quantization.quantile == pytest.approx(0.99)

def test_scalar_with_quantile_zero(self):
node = parse("CREATE COLLECTION articles QUANTIZE SCALAR QUANTILE 0")
assert node.quantization.type == QuantizationType.SCALAR
assert node.quantization.quantile == pytest.approx(0.0)

def test_scalar_with_quantile_one(self):
node = parse("CREATE COLLECTION articles QUANTIZE SCALAR QUANTILE 1")
assert node.quantization.type == QuantizationType.SCALAR
assert node.quantization.quantile == pytest.approx(1.0)

def test_scalar_with_always_ram(self):
node = parse("CREATE COLLECTION articles QUANTIZE SCALAR ALWAYS RAM")
assert node.quantization.always_ram is True
Expand Down Expand Up @@ -1013,3 +1023,11 @@ def test_quantize_missing_type_raises(self):
def test_quantize_unknown_type_raises(self):
with pytest.raises(QQLSyntaxError):
parse("CREATE COLLECTION articles QUANTIZE FULL")

def test_scalar_quantile_above_one_raises(self):
with pytest.raises(QQLSyntaxError):
parse("CREATE COLLECTION articles QUANTIZE SCALAR QUANTILE 1.5")

def test_scalar_quantile_integer_above_one_raises(self):
with pytest.raises(QQLSyntaxError):
parse("CREATE COLLECTION articles QUANTIZE SCALAR QUANTILE 2")