Skip to content

Commit 7d0bdb5

Browse files
Manthan Guptaloryruta
authored andcommitted
Query: bubble up set_parameter_alias_vector_f32 #28
1 parent 685225e commit 7d0bdb5

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

objectbox/c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def c_array_pointer(py_list: Union[List[Any], np.ndarray], c_type):
696696
ctypes.c_size_t])
697697

698698
# OBX_C_API obx_err obx_query_param_alias_vector_float32(OBX_query* query, const char* alias, const float* value, size_t element_count);
699-
# TODO
699+
obx_query_param_alias_vector_float32 = c_fn_rc('obx_query_param_alias_vector_float32', [OBX_query_p, ctypes.c_char_p, ctypes.POINTER(ctypes.c_float), ctypes.c_size_t])
700700

701701
# OBX_C_API obx_err obx_query_param_alias_string(OBX_query* query, const char* alias, const char* value);
702702
obx_query_param_alias_string = c_fn_rc('obx_query_param_alias_string', [OBX_query_p, ctypes.c_char_p, ctypes.c_char_p])

objectbox/query.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,6 @@ def set_parameter_alias_string(self, alias: str, value: str):
135135

136136
def set_parameter_alias_int(self, alias: str, value: int):
137137
return obx_query_param_alias_int(self._c_query, c_str(alias), value)
138+
139+
def set_parameter_alias_vector_f32(self, alias: str, value: Union[List[float], np.ndarray]):
140+
return obx_query_param_alias_vector_float32(self._c_query, c_str(alias), c_array(value, ctypes.c_float), len(value))

tests/test_query.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,19 @@ def test_set_parameter():
252252

253253

254254
def test_set_parameter_alias():
255-
db = load_empty_test_objectbox()
255+
db = create_test_objectbox()
256256
box = objectbox.Box(db, TestEntity)
257257

258258
box.put(TestEntity(str="Foo", int64=2, int32=703, int8=101))
259259
box.put(TestEntity(str="FooBar", int64=10, int32=49, int8=45))
260260

261+
box_vector = objectbox.Box(db, VectorEntity)
262+
box_vector.put(VectorEntity(name="Object 1", vector=[1, 1]))
263+
box_vector.put(VectorEntity(name="Object 2", vector=[2, 2]))
264+
box_vector.put(VectorEntity(name="Object 3", vector=[3, 3]))
265+
box_vector.put(VectorEntity(name="Object 4", vector=[4, 4]))
266+
box_vector.put(VectorEntity(name="Object 5", vector=[5, 5]))
267+
261268
str_prop: Property = TestEntity.properties[1]
262269
qb = box.query(str_prop.equals("Foo").alias("foo_filter"))
263270

@@ -281,3 +288,12 @@ def test_set_parameter_alias():
281288

282289
assert query.count() == 2
283290

291+
vector_prop: Property = VectorEntity.get_property("vector")
292+
293+
query = box_vector.query(vector_prop.nearest_neighbor([3.4, 3.4], 3).alias("nearest_neighbour_filter")).build()
294+
assert query.count() == 3
295+
assert query.find_ids() == sorted([3, 4, 2])
296+
297+
query.set_parameter_alias_vector_f32("nearest_neighbour_filter", [4.9, 4.9])
298+
assert query.count() == 3
299+
assert query.find_ids() == sorted([5, 4, 3])

0 commit comments

Comments
 (0)