22
33import aerospike
44from aerospike_helpers .operations import operations
5+ from aerospike_helpers .operations import hll_operations as hll_ops
6+ from aerospike_helpers .operations import map_operations
57from aerospike_helpers .expressions .resources import ResultType
6- from aerospike_helpers .expressions .base import GE , Eq , LoopVarStr , LoopVarFloat , LoopVarInt , LoopVarMap , LoopVarList , ModifyByPath , SelectByPath , MapBin , LoopVarBool , LoopVarBlob , ResultRemove , LoopVarGeoJson , LoopVarNil , CmpGeo
7- from aerospike_helpers .expressions .map import MapGetByKey
8+ from aerospike_helpers .expressions .base import GE , Eq , LoopVarStr , LoopVarFloat , LoopVarInt , LoopVarMap , LoopVarList , ModifyByPath , SelectByPath , MapBin , LoopVarBool , LoopVarBlob , ResultRemove , LoopVarGeoJson , LoopVarNil , CmpGeo , LoopVarHLL , HLLBin
9+ from aerospike_helpers .expressions .map import MapGetByKey , MapPut
810from aerospike_helpers .expressions .list import ListSize
911from aerospike_helpers .expressions .arithmetic import Sub
12+ from aerospike_helpers .expressions import hll
1013from aerospike_helpers .operations import expression_operations as expr_ops
1114from aerospike_helpers import cdt_ctx
1215from aerospike import exception as e
@@ -30,7 +33,7 @@ class TestPathExprOperations:
3033 MAP_OF_NESTED_MAPS_BIN_NAME = "map_of_maps_bin"
3134 NESTED_LIST_BIN_NAME = "list_of_lists"
3235 MAP_WITH_GEOJSON_BIN_NAME = "map_w_geo_bin"
33-
36+
3437 GEOJSON_VALUE = aerospike .geojson ('{"type": "Point", "coordinates": [-80.604333, 28.608389]}' )
3538 RECORD_BINS = {
3639 MAP_BIN_NAME : {
@@ -165,7 +168,7 @@ def insert_record(self):
165168 )
166169 ]
167170 )
168- def test_exp_path_basic_functionality (self , op , expected_bins ):
171+ def test_select_by_path_operation (self , op , expected_bins ):
169172 ops = [
170173 op
171174 ]
@@ -178,7 +181,7 @@ def test_exp_path_basic_functionality(self, op, expected_bins):
178181 20.0
179182 ).compile ()
180183
181- def test_exp_path_with_filter (self ):
184+ def test_select_by_path_operation_with_filter (self ):
182185 ops = [
183186 operations .select_by_path (
184187 bin_name = self .MAP_OF_NESTED_MAPS_BIN_NAME ,
@@ -296,6 +299,44 @@ def test_exp_loopvar_list(self):
296299 [4 , 5 ]
297300 ]
298301
302+ MAP_WITH_HLL_BIN_NAME = "map_w_hll_bin"
303+
304+ @pytest .fixture
305+ def setup_hll_bin (self ):
306+ ops = [
307+ # Insert root level HLL bin
308+ # Using a second operation to move the hll value into a map doesn't work...
309+ hll_ops .hll_add (bin_name = self .MAP_WITH_HLL_BIN_NAME , values = [i for i in range (5000 )], index_bit_count = 4 , mh_bit_count = 4 ),
310+ ]
311+ self .as_connection .operate (self .key , ops )
312+
313+ _ , _ , bins = self .as_connection .get (self .key )
314+ self .expected_hll_value = bins [self .MAP_WITH_HLL_BIN_NAME ]
315+
316+ map_with_hll_value = {
317+ "a" : bins [self .MAP_WITH_HLL_BIN_NAME ]
318+ }
319+ self .as_connection .put (self .key , bins = {self .MAP_WITH_HLL_BIN_NAME : map_with_hll_value })
320+
321+ yield
322+
323+ self .as_connection .remove_bin (self .key , list = [self .MAP_WITH_HLL_BIN_NAME ])
324+
325+ def test_exp_loopvar_hll (self , setup_hll_bin ):
326+ # HLL bin value should always be returned
327+ filter_expr = GE (hll .HLLGetCount (bin = LoopVarHLL (var_id = aerospike .EXP_LOOPVAR_VALUE )), 0 ).compile ()
328+ ops = [
329+ operations .select_by_path (
330+ bin_name = self .MAP_WITH_HLL_BIN_NAME ,
331+ ctx = [
332+ cdt_ctx .cdt_ctx_all_children_with_filter (filter_expr )
333+ ],
334+ flags = aerospike .EXP_PATH_SELECT_VALUE
335+ )
336+ ]
337+ with self .expected_context_for_pos_tests :
338+ _ , _ , bins = self .as_connection .operate (self .key , ops )
339+ assert bins [self .MAP_WITH_HLL_BIN_NAME ] == [self .expected_hll_value ]
299340
300341 SUBTRACT_FIVE_FROM_ITERATED_FLOAT_EXPR = Sub (LoopVarFloat (aerospike .EXP_LOOPVAR_VALUE ), 5.0 ).compile ()
301342 # Expected results
@@ -306,7 +347,7 @@ def test_exp_loopvar_list(self):
306347 aerospike .EXP_PATH_MODIFY_NO_FAIL ,
307348 aerospike .EXP_PATH_MODIFY_DEFAULT ,
308349 ])
309- def test_cdt_modify (self , flags ):
350+ def test_modify_by_path_operation (self , flags ):
310351 ops = [
311352 operations .modify_by_path (
312353 bin_name = self .MAP_OF_NESTED_MAPS_BIN_NAME ,
@@ -332,7 +373,7 @@ def test_cdt_modify(self, flags):
332373 assert bins [self .MAP_OF_NESTED_MAPS_BIN_NAME ] == self .SECOND_LEVEL_INTEGERS_MINUS_FIVE
333374
334375
335- # Test path expression flags
376+ # Test path expression select flags
336377
337378 def test_exp_path_flag_matching_tree (self ):
338379 ops = [
@@ -457,7 +498,7 @@ def test_neg_invalid_ctx(self, ctx_list, expected_context, op_method, op_kwargs)
457498 with expected_context :
458499 self .as_connection .operate (self .key , ops )
459500
460- def test_exp_select_by_path (self ):
501+ def test_select_by_path_expression (self ):
461502 ctx = [
462503 cdt_ctx .cdt_ctx_all_children (),
463504 cdt_ctx .cdt_ctx_all_children ()
0 commit comments