瀏覽代碼

[WIP] Partly fix all_terms().

Stefano Cossu 6 年之前
父節點
當前提交
affcaec59f
共有 2 個文件被更改,包括 47 次插入10 次删除
  1. 10 10
      lakesuperior/store/ldp_rs/lmdb_triplestore.pyx
  2. 37 0
      tests/1_store/test_lmdb_store.py

+ 10 - 10
lakesuperior/store/ldp_rs/lmdb_triplestore.pyx

@@ -359,7 +359,7 @@ cdef class LmdbTriplestore(BaseLmdbStore):
                 data_v.mv_data = &ck
                 data_v.mv_size = KLEN
                 _check(lmdb.mdb_put(
-                    self.txn, self.get_dbi(b'th:t'), &key_v, &data_v, 0
+                    tmp_txn, self.get_dbi(b'th:t'), &key_v, &data_v, 0
                 ))
 
                 # Add to list of contexts.
@@ -368,7 +368,7 @@ cdef class LmdbTriplestore(BaseLmdbStore):
                 data_v.mv_data = &ck # Whatever, length is zero anyways
                 data_v.mv_size = 0
                 _check(lmdb.mdb_put(
-                    self.txn, self.get_dbi(b'c:'), &key_v, &data_v, 0
+                    tmp_txn, self.get_dbi(b'c:'), &key_v, &data_v, 0
                 ))
                 if not self.is_txn_rw:
                     _check(lmdb.mdb_txn_commit(tmp_txn))
@@ -1222,8 +1222,8 @@ cdef class LmdbTriplestore(BaseLmdbStore):
             tkeys_conf.initial_capacity = 1024
             tkeys_conf.load_factor = .75
             tkeys_conf.key_length = KLEN
-            tkeys_conf.key_compare = cc.CC_CMP_POINTER
-            tkeys_conf.hash = cc.POINTER_HASH
+            #tkeys_conf.key_compare = cc.CC_CMP_POINTER
+            #tkeys_conf.hash = cc.POINTER_HASH
 
             cc.hashset_new_conf(&tkeys_conf, tkeys)
 
@@ -1262,9 +1262,10 @@ cdef class LmdbTriplestore(BaseLmdbStore):
         try:
             self._all_term_keys(term_type, &tkeys)
             cc.hashset_iter_init(&it, tkeys)
-            while cc.hashset_iter_next(&it, &cur):
-                #logger.debug('Yielding: {}'.format(key))
-                ret.add(self.from_key(<Key>cur))
+            logger.info(f'All terms size: {cc.hashset_size(tkeys)}')
+            while cc.hashset_iter_next(&it, &cur) != cc.CC_ITER_END:
+                logger.info('Yielding: {}'.format((<Key*>cur)[0]))
+                ret.add(self.from_key((<Key*>cur)[0]))
         finally:
             if tkeys:
                 free(tkeys)
@@ -1493,9 +1494,8 @@ cdef class LmdbTriplestore(BaseLmdbStore):
         key_v.mv_size = KLEN
         data_v.mv_data = value.addr
         data_v.mv_size = value.sz
-        logger.info('Appending value {} to db {} with key: {}'.format(
-            buffer_dump(value), dblabel.decode(), new_idx))
-        #logger.debug('data size: {}'.format(data_v.mv_size))
+        #logger.debug('Appending value {} to db {} with key: {}'.format(
+        #    buffer_dump(value), dblabel.decode(), new_idx))
         lmdb.mdb_put(
                 txn, self.get_dbi(dblabel), &key_v, &data_v,
                 flags | lmdb.MDB_APPEND)

+ 37 - 0
tests/1_store/test_lmdb_store.py

@@ -258,6 +258,43 @@ class TestBasicOps:
 
 
 
+@pytest.mark.usefixtures('store', 'bogus_trp')
+class TestExtendedOps:
+    '''
+    Test additional store operations.
+    '''
+
+    def test_all_terms(self, store, bogus_trp):
+        """
+        Test the "all terms" mehods.
+        """
+        with store.txn_ctx(True):
+            for trp in bogus_trp:
+                store.add(trp)
+
+        with store.txn_ctx():
+            import pdb; pdb.set_trace()
+            all_s = store.all_terms('s')
+            all_p = store.all_terms('p')
+            all_o = store.all_terms('o')
+
+        assert len(all_s) == 1
+        assert len(all_p) == 100
+        assert len(all_o) == 1000
+
+        assert URIRef('urn:test_mp:s1') in all_s
+        assert URIRef('urn:test_mp:s1') not in all_p
+        assert URIRef('urn:test_mp:s1') not in all_o
+
+        assert URIRef('urn:test_mp:p10') not in all_s
+        assert URIRef('urn:test_mp:p10') in all_p
+        assert URIRef('urn:test_mp:p10') not in all_o
+
+        assert URIRef('urn:test_mp:o99') not in all_s
+        assert URIRef('urn:test_mp:o99') not in all_p
+        assert URIRef('urn:test_mp:o99') in all_o
+
+
 @pytest.mark.usefixtures('store', 'bogus_trp')
 class TestEntryCount:
     '''