Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use v5.14;
- use autodie;
- use utf8;
- use Test::Modern;
- use CHI;
- use Attean;
- use Attean::RDF;
- use AtteanX::QueryPlanner::Cache::LDF;
- use AtteanX::Store::Memory;
- #use Carp::Always;
- use Data::Dumper;
- use AtteanX::Store::SPARQL;
- use AtteanX::Store::LDF;
- use AtteanX::Model::SPARQLCache::LDF;
- use Log::Any::Adapter;
- Log::Any::Adapter->set($ENV{LOG_ADAPTER} || 'Stderr', category => qr/AtteanX::QueryPlanner::Cache AtteanX::Model::SPARQLCache::LDF/) if ($ENV{TEST_VERBOSE});
- my $cache = CHI->new( driver => 'Memory', global => 1 );
- my $p = AtteanX::QueryPlanner::Cache::LDF->new;
- isa_ok($p, 'Attean::QueryPlanner');
- isa_ok($p, 'AtteanX::QueryPlanner::Cache::LDF');
- does_ok($p, 'Attean::API::CostPlanner');
- package TestLDFCreateStore {
- use Moo;
- with 'Test::Attean::Store::LDF::Role::CreateStore';
- };
- my $test = TestLDFCreateStore->new;
- {
- my $sparqlstore = Attean->get_store('SPARQL')->new('endpoint_url' => iri('http://test.invalid/sparql'));
- isa_ok($sparqlstore, 'AtteanX::Store::SPARQL');
- my $graph = iri('http://test.invalid/graph');
- my $t = triple(variable('s'), iri('p'), literal('1'));
- my $u = triple(variable('s'), iri('p'), variable('o'));
- my $v = triple(variable('s'), iri('q'), blank('xyz'));
- my $w = triple(variable('a'), iri('b'), iri('c'));
- my $x = triple(variable('s'), iri('q'), iri('a'));
- my $y = triple(variable('o'), iri('b'), literal('2'));
- my $z = triple(variable('a'), iri('c'), variable('s'));
- my $s = triple(iri('a'), variable('p'), variable('o'));
- my $ldfstore = $test->create_store(triples => [$t,$u,$v,$w,$x,$y,$z,$s]);
- isa_ok($ldfstore, 'AtteanX::Store::LDF');
- my $model = AtteanX::Model::SPARQLCache::LDF->new( store => $sparqlstore,
- ldf_store => $ldfstore,
- cache => $cache );
- isa_ok($model, 'AtteanX::Model::SPARQLCache::LDF');
- isa_ok($model, 'AtteanX::Model::SPARQLCache');
- isa_ok($model, 'AtteanX::Model::SPARQL');
- $cache->set('?v001 <p> "1" .', ['<http://example.org/foo>', '<http://example.org/bar>']);
- $cache->set('?v001 <p> "dahut" .', ['<http://example.com/foo>', '<http://example.com/bar>']);
- $cache->set('?v001 <dahut> "1" .', ['<http://example.org/dahut>']);
- $cache->set('?v002 <p> ?v001 .', {'<http://example.org/foo>' => ['<http://example.org/bar>'],
- '<http://example.com/foo>' => ['<http://example.org/baz>', '<http://example.org/foobar>']});
- $cache->set('?v001 <p> "dahut" .', ['<http://example.com/foo>', '<http://example.com/bar>']);
- $cache->set('?v002 <dahut> ?v001 .', {'<http://example.org/dahut>' => ['"Foobar"']});
- subtest '2-triple BGP with join variable with cache one cached' => sub {
- my $bgp = Attean::Algebra::BGP->new(triples => [$t, $x]);
- my @plans = $p->plans_for_algebra($bgp, $model, [$graph]);
- is(scalar @plans, 5, 'Got 5 plans');
- foreach my $plan (@plans){
- print "\n". $plan->as_string;
- }
- # The first two plans should be the "best", containing a HashJoin over
- # a Table and a LDF.
- foreach my $plan (@plans[0..1]) {
- does_ok($plan, 'Attean::API::Plan::Join', 'First 2 plans are joins');
- my @tables = $plan->subpatterns_of_type('Attean::Plan::Table');
- is(scalar(@tables), 1, 'First 2 plans contain 1 table sub-plan');
- my @ldfs = $plan->subpatterns_of_type('AtteanX::Store::LDF::Plan::Triple');
- is(scalar(@ldfs), 1, 'First 2 plans contain 1 table sub-plan');
- }
- my $plan = $plans[0];
- # sorting the strings should result in the Attean::Plan::Table being first
- my @children = sort { "$a" cmp "$b" } @{$plan->children};
- foreach my $cplan (@children) {
- does_ok($cplan, 'Attean::API::Plan', 'Each child of 2-triple BGP');
- }
- my ($table,$ldfplan) = @children;
- isa_ok($table, 'Attean::Plan::Table', 'Should join on Table first');
- isa_ok($ldfplan, 'AtteanX::Store::LDF::Plan::Triple', 'Then on LDF triple');
- is($ldfplan->plan_as_string, 'LDFTriple { ?s, <q>, <a> }', 'Child plan OK');
- };
- }
- done_testing;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement