def test_hdt_simple_scan(subj, pred, obj, expected): with HDTFileConnector('tests/data/watdiv.10M.hdt') as backend: iterator, c = backend.search(subj, pred, obj) assert iterator.has_next() while iterator.has_next() and len(expected) > 0: assert_next_triple(iterator, expected) assert not iterator.has_next() assert len(expected) == 0
def test_hdt_resume_scan(subj, pred, obj, expected): # don't test for scan that yield one matching RDF triple if len(expected) > 1: with HDTFileConnector('tests/data/watdiv.10M.hdt') as backend: iterator, c = backend.search(subj, pred, obj) assert iterator.has_next() # read first triple, then stop and reload a new iterator assert_next_triple(iterator, expected) last_read = iterator.last_read() iterator, c = backend.search(subj, pred, obj, last_read=last_read) while iterator.has_next() and len(expected) > 0: assert_next_triple(iterator, expected) assert not iterator.has_next() assert len(expected) == 0
# scan_test.py # Author: Thomas MINIER - MIT License 2017-2020 import pytest from sage.query_engine.sage_engine import SageEngine from sage.query_engine.iterators.scan import ScanIterator from sage.query_engine.iterators.projection import ProjectionIterator from sage.database.hdt.connector import HDTFileConnector hdtDoc = HDTFileConnector('tests/data/test.hdt') engine = SageEngine() triple = { 'subject': '?s1', 'predicate': 'http://example.org/p1', 'object': '?common', 'graph': 'watdiv100' } @pytest.mark.asyncio async def test_projection_read(): iterator, card = hdtDoc.search(triple['subject'], triple['predicate'], triple['object']) scan = ScanIterator(iterator, triple, card) proj = ProjectionIterator(scan, ['?common']) (results, saved, done, _) = await engine.execute(proj, 10e7) assert len(results) == card for res in results: assert '?common' in res and '?s1' not in res assert done
def test_hdt_scan_unknown_pattern(): with HDTFileConnector('tests/data/watdiv.10M.hdt') as backend: iterator, c = backend.search('http://example.org#toto', None, None) assert next(iterator) is None
# filter_iterator_test.py # Author: Thomas MINIER - MIT License 2017-2020 import pytest from sage.query_engine.sage_engine import SageEngine from sage.query_engine.iterators.scan import ScanIterator from sage.query_engine.iterators.filter import FilterIterator from sage.query_engine.iterators.projection import ProjectionIterator from sage.query_engine.iterators.loader import load from sage.database.hdt.connector import HDTFileConnector from tests.utils import DummyDataset import math hdtDoc = HDTFileConnector('tests/data/watdiv.10M.hdt') engine = SageEngine() triple = { 'subject': 'http://db.uwaterloo.ca/~galuc/wsdbm/Offer1000', 'predicate': '?p', 'object': '?o', 'graph': 'watdiv100' } @pytest.mark.asyncio async def test_simple_filter_iterator(): expression = "?p = <http://schema.org/eligibleRegion>" iterator, card = hdtDoc.search(triple['subject'], triple['predicate'], triple['object']) scan = ProjectionIterator(ScanIterator(iterator, triple, card)) iterator = FilterIterator(scan, expression) (results, saved, done, _) = await engine.execute(iterator, math.inf) assert len(results) == 4
def test_hdt_scan_unknown_pattern(): with HDTFileConnector('tests/data/watdiv.10M.hdt') as backend: with pytest.raises(StopIteration): iterator, c = backend.search('http://example.org#toto', None, None) next(iterator)
# scan_test.py # Author: Thomas MINIER - MIT License 2017-2020 import pytest import asyncio from rdflib.plugins.sparql.algebra import translateQuery, translateUpdate from rdflib.plugins.sparql.parser import parseQuery, parseUpdate from sage.query_engine.sage_engine import SageEngine from sage.database.hdt.connector import HDTFileConnector from sage.query_engine.optimizer.query_parser import parse_query from tests.utils import DummyDataset hdtDoc = HDTFileConnector('tests/data/context.hdt') dataset = DummyDataset(hdtDoc, 'context') engine = SageEngine() queries = [(""" select ?md5 where { ?s <http://isa> ?o BIND(URI(CONCAT("http://",MD5(CONCAT(STR(?s),STR(<http://isa>),STR(?o))))) as ?md5) } """, 5), (""" select ?o1 where { ?s <http://isa> ?o BIND(URI(CONCAT("http://",MD5(CONCAT(STR(?s),STR(<http://isa>),STR(?o))))) as ?md5) ?md5 <http://source> ?o1 } """, 5), (""" select ?md5 where {