Test/AtteanX/Store/DBI.pm

filter: Statementstmt 100% 127 / 127 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 1 totaltotal 99.3% 144 / 145 CC 5 SCAR 3.9
CC
5
Cov
100%
test_quads
3.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.5
« AtteanX/Store/DBI.pm ↑ Summary
1 package Test::AtteanX::Store::DBI;
2  
3 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Test::Roo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Test::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 requires 'create_store'; # create_store( quads => \@triples )
13  
14 7 ▶sub test_quads {
Subroutine test_quads: called CC=3 SCAR=11.0
Pod undocumented
15 7 my @q;
16 7 for my $i (0 .. 5) {
17 42 push(@q, quad(iri('s'), iri('p'), literal($i), iri('g')));
18 42 push(@q, quad(iri('s'), iri('p'), blank("b$i"), iri('g')));
19 }
20  
21 7 my @strings;
22 7 push(@strings, literal('Hi'));
23 7 push(@strings, langliteral('Hello', 'en'));
24 7 push(@strings, langliteral('火星', 'ja'));
25 7 push(@strings, dtliteral(787, 'http://www.w3.org/2001/XMLSchema#integer'));
26 7 foreach my $s (@strings) {
27 28 push(@q, quad(iri('s'), iri('str'), $s, iri('strings')));
28 }
29  
30 7 return \@q;
31 }
32  
33 1 ▶test 'ISLITERAL type constraint SARG' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
34 1 my $self = shift;
35 1 my $store = $self->create_store(quads => $self->test_quads);
36 1 my $model = Attean::QuadModel->new( store => $store );
37 1 my $dbh = $store->dbh;
38 1 my $typecol = $dbh->quote_identifier('type');
39
40 1 my $algebra = Attean->get_parser('SPARQL')->parse('SELECT * WHERE { ?s ?p ?o FILTER ISLITERAL(?o) }');
41 1 my $default_graphs = [iri('g')];
42 1 my $planner = Attean::IDPQueryPlanner->new();
43 1 my $plan = $planner->plan_for_algebra($algebra, $model, $default_graphs);
44  
45 1 isa_ok($plan, 'AtteanX::Store::DBI::Plan');
46 1 my ($sql, @bind) = $plan->sql;
47
48 1 like($sql, qr<SELECT term_id FROM term WHERE $typecol = [?]>, 'generated SQL');
49 1 is($bind[-1], 'literal');
50 1 };
51  
52 1 ▶test 'ISBLANK type constraint SARG' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 1 my $self = shift;
54 1 my $store = $self->create_store(quads => $self->test_quads);
55 1 my $model = Attean::QuadModel->new( store => $store );
56 1 my $dbh = $store->dbh;
57 1 my $typecol = $dbh->quote_identifier('type');
58  
59 1 my $algebra = Attean->get_parser('SPARQL')->parse('SELECT * WHERE { ?s ?p ?o FILTER isBlank(?o) }');
60 1 my $default_graphs = [iri('g')];
61 1 my $planner = Attean::IDPQueryPlanner->new();
62 1 my $plan = $planner->plan_for_algebra($algebra, $model, $default_graphs);
63  
64 1 isa_ok($plan, 'AtteanX::Store::DBI::Plan');
65 1 my ($sql, @bind) = $plan->sql;
66 1 like($sql, qr<SELECT term_id FROM term WHERE $typecol = [?]>, 'generated SQL');
67 1 is($bind[-1], 'blank', 'bound values');
68 1 };
69  
70 1 ▶test 'ISLITERAL type constraint SARG' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
71 1 my $self = shift;
72 1 my $store = $self->create_store(quads => $self->test_quads);
73 1 my $model = Attean::QuadModel->new( store => $store );
74 1 my $dbh = $store->dbh;
75 1 my $typecol = $dbh->quote_identifier('type');
76  
77 1 my $algebra = Attean->get_parser('SPARQL')->parse('SELECT * WHERE { ?s ?p ?o FILTER ISLITERAL(?o) }');
78 1 my $default_graphs = [iri('strings')];
79 1 my $planner = Attean::IDPQueryPlanner->new();
80 1 my $plan = $planner->plan_for_algebra($algebra, $model, $default_graphs);
81  
82 1 isa_ok($plan, 'AtteanX::Store::DBI::Plan');
83 1 my ($sql, @bind) = $plan->sql;
84 1 like($sql, qr<SELECT term_id FROM term WHERE $typecol = [?]>, 'generated SQL');
85 1 is($bind[-1], 'literal', 'bound values');
86 1 };
87  
88 1 ▶test 'ISIRI type constraint SARG' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
89 1 my $self = shift;
90 1 my $store = $self->create_store(quads => $self->test_quads);
91 1 my $model = Attean::QuadModel->new( store => $store );
92 1 my $dbh = $store->dbh;
93 1 my $typecol = $dbh->quote_identifier('type');
94  
95 1 my $algebra = Attean->get_parser('SPARQL')->parse('SELECT * WHERE { ?s ?p ?o FILTER ISIRI(?o) }');
96 1 my $default_graphs = [iri('g')];
97 1 my $planner = Attean::IDPQueryPlanner->new();
98 1 my $plan = $planner->plan_for_algebra($algebra, $model, $default_graphs);
99  
100 1 isa_ok($plan, 'AtteanX::Store::DBI::Plan');
101 1 my ($sql, @bind) = $plan->sql;
102 1 like($sql, qr<SELECT term_id FROM term WHERE $typecol = [?]>, 'generated SQL');
103 1 is($bind[-1], 'iri');
104 1 };
105  
106 1 ▶test 'STRSTARTS' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
107 1 local($Data::Dumper::Indent) = 0;
108 1 my $self = shift;
109 1 my $store = $self->create_store(quads => $self->test_quads);
110 1 my $model = Attean::QuadModel->new( store => $store );
111
112 1 ▶ subtest 'STR()' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
113 1 my $algebra = Attean->get_parser('SPARQL')->parse('SELECT * WHERE { ?s ?p ?o FILTER STRSTARTS(STR(?o), "H") }');
114 1 my $default_graphs = [iri('strings')];
115 1 my $planner = Attean::IDPQueryPlanner->new();
116 1 my $plan = $planner->plan_for_algebra($algebra, $model, $default_graphs);
117  
118 1 my @rows = $plan->evaluate($model)->elements;
119 1 is(scalar(@rows), 2, 'result count');
120 1 foreach my $r (@rows) {
121 2 like($r->value('o')->value, qr/^H/, 'literal value');
122 }
123 1 };
124
125 1 ▶ subtest 'xsd:string' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
126 1 my $algebra = Attean->get_parser('SPARQL')->parse('SELECT * WHERE { ?s ?p ?o FILTER STRSTARTS(?o, "H") }');
127 1 my $default_graphs = [iri('strings')];
128 1 my $planner = Attean::IDPQueryPlanner->new();
129 1 my $plan = $planner->plan_for_algebra($algebra, $model, $default_graphs);
130  
131 1 isa_ok($plan, 'AtteanX::Store::DBI::Plan');
132 1 my $iter = $plan->evaluate($model);
133 1 my @rows = $iter->elements;
134 1 is(scalar(@rows), 2, 'result count: ' . Dumper([$plan->sql]));
135 1 foreach my $r (@rows) {
136 2 like($r->value('o')->value, qr/^H/, 'literal value');
137 }
138 1 };
139
140 1 ▶ subtest 'language string' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
141 1 my $algebra = Attean->get_parser('SPARQL')->parse('SELECT * WHERE { ?s ?p ?o FILTER STRSTARTS(?o, "H"@en) }');
142 1 my $default_graphs = [iri('strings')];
143 1 my $planner = Attean::IDPQueryPlanner->new();
144 1 my $plan = $planner->plan_for_algebra($algebra, $model, $default_graphs);
145  
146 1 isa_ok($plan, 'AtteanX::Store::DBI::Plan');
147 1 my @rows = $plan->evaluate($model)->elements;
148 1 is(scalar(@rows), 1, 'result count');
149 1 is($rows[0]->value('o')->value, 'Hello', 'literal value');
150 1 };
151 1 };
152  
153  
154 1 1;
« AtteanX/Store/DBI.pm ↑ Summary