def test_int32_k0_k1_k2_k3_prev(self): a_join = self.int32_schema.attr_by_name('a_join') k0 = self.int32_schema.attr_by_name('k0') k1 = self.int32_schema.attr_by_name('k1') k2 = self.int32_schema.attr_by_name('k2') k3 = self.int32_schema.attr_by_name('k3') f = Sos.Filter(a_join) f.add_condition(k0, Sos.COND_LE, -4) f.add_condition(k0, Sos.COND_GE, -12) f.add_condition(k1, Sos.COND_LE, -4) f.add_condition(k1, Sos.COND_GE, -12) f.add_condition(k2, Sos.COND_LE, -4) f.add_condition(k2, Sos.COND_GE, -12) f.add_condition(k3, Sos.COND_LE, -4) f.add_condition(k3, Sos.COND_GE, -12) o = f.end() count = 0 while o: # Dprint(o[:]) count += 1 o = f.prev() Dprint("Misses {0}".format(f.miss_count())) Dprint("Count {0}".format(count)) self.assertTrue(f.miss_count() <= 4) self.assertEqual(count, 9 * 9 * 9 * 9) del f
def __join_test_next_prev(self, join_attr_name, attr_name, min_v, max_v): join_attr = self.schema[join_attr_name] attr = self.schema[attr_name] f = Sos.Filter(join_attr) f.add_condition(attr, Sos.COND_GE, min_v) f.add_condition(attr, Sos.COND_LE, max_v) o = f.begin() next_count = 0 while o: Dprint(o[:]) next_count += 1 self.assertTrue(o[attr_name] >= min_v) self.assertTrue(o[attr_name] <= max_v) o = next(f) # iterate backwards, the count should be the same o = f.end() prev_count = 0 while o: Dprint(o[:]) prev_count += 1 self.assertTrue(o[attr_name] >= min_v) self.assertTrue(o[attr_name] <= max_v) o = f.prev() self.assertEqual(next_count, prev_count)
def test_uint64_k0_k1_k2_k3(self): a_join = self.uint64_schema.attr_by_name('a_join') k0 = self.uint64_schema.attr_by_name('k0') k1 = self.uint64_schema.attr_by_name('k1') k2 = self.uint64_schema.attr_by_name('k2') k3 = self.uint64_schema.attr_by_name('k3') f = Sos.Filter(a_join) f.add_condition(k0, Sos.COND_GE, 4) f.add_condition(k0, Sos.COND_LE, 12) f.add_condition(k1, Sos.COND_GE, 4) f.add_condition(k1, Sos.COND_LE, 12) f.add_condition(k2, Sos.COND_GE, 4) f.add_condition(k2, Sos.COND_LE, 12) f.add_condition(k3, Sos.COND_GE, 4) f.add_condition(k3, Sos.COND_LE, 12) o = f.begin() count = 0 while o: # Dprint(o[:]) count += 1 o = next(f) Dprint("Misses {0}".format(f.miss_count())) Dprint("count {0}".format(count)) self.assertTrue(f.miss_count() <= 4) self.assertEqual(count, 9 * 9 * 9 * 9) del f
def __test_next_prev(self, attr_name, min_v, max_v): attr = self.schema[attr_name] f = Sos.Filter(attr) f.add_condition(attr, Sos.COND_GE, min_v) f.add_condition(attr, Sos.COND_LE, max_v) o = f.begin() next_count = 0 while o: next_count += 1 v = o[attr_name] if type(v) == numpy.ndarray: v = v.tolist() Dprint("{0} >= {1}".format(v, min_v)) Dprint("{0} <= {1}".format(v, max_v)) self.assertTrue(v >= min_v) self.assertTrue(v <= max_v) o = next(f) self.assertTrue(next_count > 0) # iterate backwards, the count should be the same o = f.end() prev_count = 0 while o: prev_count += 1 v = o[attr_name] if type(v) == numpy.ndarray: v = v.tolist() Dprint("{0} >= {1}".format(v, min_v)) Dprint("{0} <= {1}".format(v, max_v)) self.assertTrue(v >= min_v) self.assertTrue(v <= max_v) o = f.prev() self.assertTrue(prev_count > 0) self.assertEqual(next_count, prev_count)
def test_10_filter_fwd(self): ts_attr = self.schema['timestamp'] for i in range(len(data_float)): f = Sos.Filter(ts_attr) f.add_condition(ts_attr, Sos.COND_GE, data_float[i][1]) Dprint(data_float[i][1]) o = f.begin() count = len(data_float) - i while o: count -= 1 Dprint(o[:]) o = next(f) self.assertEqual( count, 0 ) Dprint("--------------------------------")
def test_11_filter_rev(self): ts_attr = self.schema['timestamp'] for i in range(len(data_float) -1, -1, -1): f = Sos.Filter(ts_attr) f.add_condition(ts_attr, Sos.COND_GE, data_float[0][1]) f.add_condition(ts_attr, Sos.COND_LE, data_float[i][1]) Dprint(data_float[0][1], data_float[i][1]) o = f.end() count = i + 1 while o: count -= 1 Dprint(o[:]) o = f.prev() self.assertEqual( count, 0 ) Dprint("--------------------------------")
def test_uint16_k0(self): a_join = self.uint16_schema.attr_by_name('a_join') k0 = self.uint16_schema.attr_by_name('k0') f = Sos.Filter(a_join) f.add_condition(k0, Sos.COND_GE, 4) f.add_condition(k0, Sos.COND_LE, 12) o = f.begin() count = 0 while o: # Dprint(o[:]) count += 1 o = next(f) Dprint("Misses {0}".format(f.miss_count())) Dprint("Count {0}".format(count)) self.assertTrue(f.miss_count() <= 1) self.assertEqual(count, 9 * 16 * 16 * 16) del f
def test_int64_k0_rev(self): a_join = self.int64_schema.attr_by_name('a_join') k0 = self.int64_schema.attr_by_name('k0') f = Sos.Filter(a_join) f.add_condition(k0, Sos.COND_LE, -4) f.add_condition(k0, Sos.COND_GE, -12) o = f.end() count = 0 while o: # Dprint(o[:]) count += 1 o = f.prev() Dprint("Misses {0}".format(f.miss_count())) Dprint("Count {0}".format(count)) self.assertTrue(f.miss_count() <= 1) self.assertEqual(count, 9 * 17 * 17 * 17) del f
def test_00_generate_tuple(self): self.__generate_data_tuple() for d in data_tuple: o = self.schema.alloc() o[:] = ( d[1], d[2] ) rc = o.index_add() self.assertEqual( rc, 0 ) Dprint( o[:] ) del o
def test_int32_k0_k1(self): a_join = self.int32_schema.attr_by_name('a_join') k0 = self.int32_schema.attr_by_name('k0') k1 = self.int32_schema.attr_by_name('k1') f = Sos.Filter(a_join) f.add_condition(k0, Sos.COND_LE, -4) f.add_condition(k0, Sos.COND_GE, -12) f.add_condition(k1, Sos.COND_LE, -4) f.add_condition(k1, Sos.COND_GE, -12) o = f.begin() count = 0 while o: # Dprint(o[:]) count += 1 o = next(f) Dprint("Misses {0}".format(f.miss_count())) Dprint("count {0}".format(count)) self.assertTrue(f.miss_count() <= 2) self.assertEqual(count, 9 * 9 * 17 * 17) del f
def _test_int_key_type(self, attr_name, value): attr = self.schema[attr_name] idx = attr.index() # generate key from value key = attr.key(value) o = idx.find(key) if o is not None: Dprint(o[:]) self.assertIsNotNone(o) self.assertEqual(o[attr_name], value)
def test_10_struct(self): attr = self.schema['struct'] idx = attr.index() # generate key from value value = '-503' key = attr.key(value) o = idx.find(key) if o is not None: Dprint(o[:]) self.assertIsNotNone(o) self.assertEqual(o['struct'][:len(value)], bytearray(value))
def __query_test(self, index, job_id, comp_id, start, end, expected_count): join = self.schema.attr_by_name(index) time_a = self.schema['timestamp'] f = Sos.Filter(join) if job_id is not None: job_a = self.schema['job_id'] f.add_condition(job_a, Sos.COND_EQ, job_id) if comp_id is not None: comp_a = self.schema['component_id'] f.add_condition(comp_a, Sos.COND_EQ, comp_id) f.add_condition(time_a, Sos.COND_GE, start) f.add_condition(time_a, Sos.COND_LT, end) o = f.begin() count = 0 while o: # Dprint(o[:4]) count += 1 o = next(f) Dprint("Misses {0}".format(f.miss_count())) Dprint("Count {0}".format(count)) self.assertTrue(f.miss_count() <= 3) self.assertEqual(count, expected_count) del f
def _test_array_key_type(self, attr_name, value): attr = self.schema[attr_name] idx = attr.index() # generate key from value key = attr.key(value) o = idx.find(key) self.assertTrue(o is not None) Dprint(o[:]) a = o[attr_name] b = value self.assertEqual(len(a), len(b)) for i in range(len(a)): self.assertEqual(a[i], b[i])
def checkit(self, attr_name, min_v, max_v): # iterate forward, checking that everything the Query iterator returns # is also found by traversing with a non-filtered attribute iter o = self.query.begin() it = self.schema1.attr_by_name(attr_name).attr_iter() rc = it.begin() next_count = 0 while o: next_count += 1 v = o[0] if type(v) == numpy.ndarray: v = v.tolist() Dprint("{0} >= {1}".format(v, min_v)) Dprint("{0} <= {1}".format(v, max_v)) self.assertTrue(v >= min_v) self.assertTrue(v <= max_v) foundit = False while rc: o2 = it.item() v2 = o2[attr_name] if type(v2) == numpy.ndarray: v2 = v2.tolist() Dprint("checking {0}".format(v2)) if v2 < v: rc = next(it) else: self.assertTrue(v == v2) foundit = True next(it) break self.assertTrue(foundit) o = next(self.query) self.assertTrue(next_count > 0) # iterate backwards, the count should be the same o = self.query.end() rc = it.end() prev_count = 0 while o: prev_count += 1 v = o[0] if type(v) == numpy.ndarray: v = v.tolist() Dprint("{0} >= {1}".format(v, min_v)) Dprint("{0} <= {1}".format(v, max_v)) self.assertTrue(v >= min_v) self.assertTrue(v <= max_v) foundit = False while rc: o2 = it.item() v2 = o2[attr_name] if type(v2) == numpy.ndarray: v2 = v2.tolist() Dprint("checking {0}".format(v2)) rc = it.prev() if v2 > v: continue else: self.assertTrue(v == v2) foundit = True break self.assertTrue(foundit) o = self.query.prev() self.assertEqual(next_count, prev_count)