Database Reference
In-Depth Information
Join. The Join merges the compatible mappings of two multisets of solution map-
pings. A Join can be expressed as a JOIN in Pig Latin on the shared variables (cf. P3,
assuming the results of the BGPs are stored in BGP1 and BGP2 ). Again, FOREACH
is used to remove unnecessary columns and update the schema information as illus-
trated in the following.
P3. Persons Who Know Somebody with the Same Age
SP Join(BGP(?a knows ?b),
BGP(?a age ?c . ?b age ?c))
PL j1 = JOIN BGP1 BY (a,b), BGP2 BY (a,b);
P3 = FOREACH j1 GENERATE
BGP1::a AS a, BGP1::b AS b, c;
LeftJoin. The LeftJoin operator adds additional information to the result, if it
exists. This additional information can be restricted by a filter expression. In Pig Latin,
we can first use a FILTER to restrict the values of the additional information before
performing an OUTER JOIN on the shared variables as illustrated in the following.
P4. Persons with Mailbox and Optional Age
SP LeftJoin(BGP(?a mbox ?b),
BGP(?a age ?c), ?c >= 18)
PL f1= FILTER BGP2 BY c >= 18;
lj= JOIN BGP1 BY a LEFT OUTER, BGP2 BY a;
P4= FOREACH lj GENERATE BGP1::a AS a, b, c;
Union. The Union operator combines two multisets of solution mappings (Ω 1 2 )
to a single multiset without any further changes, that is, it unifies the results of two
graph patterns. The problem of Union is that for two mappings μ 1 ∈ Ω 1 and μ 2 ∈ Ω 2
it can be that dom 1 ) ≠ dom 2 ) as it is the case for P5 where ?b is not defined in the
second BGP. To have a common schema in Pig Latin we add a new column to the
result of the second BGP and use null values to indicate that the variable binding for
?b is not defined.
P5. Persons Who Know “Bob” and Have a Mailbox or Persons Who Know “John”
SP Union(BGP(?a knows Bob . ?a mbox ?b),
BGP(?a knows John))
PL BGP2 = FOREACH BGP2 GENERATE a, null as b;
P5 = UNION BGP1, BGP2;
Graph. A SPARQL query data set is a collection of RDF graphs with one default
graph and zero or more additional named graphs . In general, a graph pattern is
Search WWH ::




Custom Search