Skip to content

Commit 16c282f

Browse files
committed
set parameter alias: test multiple aliases in one query #36
1 parent b1e7acd commit 16c282f

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

tests/test_query.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,23 @@ def test_set_parameter_alias():
313313
box_vector.put(VectorEntity(name="Object 4", vector=[4, 4]))
314314
box_vector.put(VectorEntity(name="Object 5", vector=[5, 5]))
315315

316-
str_prop: Property = TestEntity.properties[1]
317-
qb = box.query(str_prop.equals("Foo").alias("foo_filter"))
316+
str_prop: Property = TestEntity.get_property("str")
317+
int32_prop: Property = TestEntity.get_property("int32")
318+
int64_prop: Property = TestEntity.get_property("int64")
318319

320+
# Test set parameter alias on string
321+
qb = box.query(str_prop.equals("Foo").alias("foo_filter"))
319322
query = qb.build()
323+
320324
assert query.find()[0].str == "Foo"
321325
assert query.count() == 1
322326

323327
query.set_parameter_alias_string("foo_filter", "FooBar")
324-
325328
assert query.find()[0].str == "FooBar"
326329
assert query.count() == 1
327330

328-
int_prop: Property = TestEntity.properties[3]
329-
qb = box.query(int_prop.greater_than(5).alias("greater_than_filter"))
331+
# Test set parameter alias on int64
332+
qb = box.query(int64_prop.greater_than(5).alias("greater_than_filter"))
330333

331334
query = qb.build()
332335
assert query.count() == 1
@@ -336,6 +339,21 @@ def test_set_parameter_alias():
336339

337340
assert query.count() == 2
338341

342+
# Test set parameter alias on string/int32
343+
qb = box.query(str_prop.equals("Foo").alias("str condition"))
344+
int32_prop.greater_than(700).alias("int32 condition").apply(qb)
345+
query = qb.build()
346+
347+
assert query.count() == 1
348+
assert query.find()[0].str == "Foo"
349+
350+
query.set_parameter_alias_string("str condition", "FooBar") # FooBar int32 isn't higher than 700 (49)
351+
assert query.count() == 0
352+
353+
query.set_parameter_alias_int("int32 condition", 40)
354+
assert query.find()[0].str == "FooBar"
355+
356+
# Test set parameter alias on vector
339357
vector_prop: Property = VectorEntity.get_property("vector")
340358

341359
query = box_vector.query(vector_prop.nearest_neighbor([3.4, 3.4], 3).alias("nearest_neighbour_filter")).build()

0 commit comments

Comments
 (0)