Class: SPARQL::Algebra::Operator::LeftJoin
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::LeftJoin
- Includes:
- Query
- Defined in:
- lib/sparql/algebra/operator/left_join.rb
Overview
The SPARQL GraphPattern leftjoin operator.
Constant Summary
- NAME =
[:leftjoin]
Constants inherited from SPARQL::Algebra::Operator
Instance Attribute Summary
Attributes included from Query
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary (collapse)
-
- (RDF::Query::Solutions) execute(queryable, options = {})
Executes each operand with
queryableand performs theleftjoinoperation by adding every solution from the left, merging compatible solutions from the right that match an optional filter. -
- (Union, RDF::Query) optimize
Returns an optimized version of this query.
Methods included from Query
#context=, #each_solution, #failed?, #matched?, #unshift, #variables
Methods inherited from SPARQL::Algebra::Operator
arity, base_uri, #base_uri, base_uri=, #boolean, #constant?, #eql?, #evaluatable?, evaluate, #executable?, for, #initialize, #inspect, #operand, prefixes, #prefixes, prefixes=, #to_sse, #to_sxp, #variable?
Methods included from Evaluatable
Methods included from Expression
cast, #constant?, #evaluate, for, new, open, parse, #to_sse, #variable?
Constructor Details
This class inherits a constructor from SPARQL::Algebra::Operator
Instance Method Details
- (RDF::Query::Solutions) execute(queryable, options = {})
Executes each operand with queryable and performs the leftjoin operation
by adding every solution from the left, merging compatible solutions from the right
that match an optional filter.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sparql/algebra/operator/left_join.rb', line 33 def execute(queryable, = {}) filter = operand(2) debug("LeftJoin", ) left = operand(0).execute(queryable, .merge(:depth => [:depth].to_i + 1)) || {} debug("=>(left) #{left.inspect}", ) right = operand(1).execute(queryable, .merge(:depth => [:depth].to_i + 1)) || {} debug("=>(right) #{right.inspect}", ) # LeftJoin(Ω1, Ω2, expr) = solutions = [] left.each do |s1| load_left = true right.each do |s2| s = s2.merge(s1) expr = filter ? boolean(filter.evaluate(s)).true? : true rescue false debug("===>(evaluate) #{s.inspect}", ) if filter if expr && s1.compatible?(s2) # { merge(μ1, μ2) | μ1 in Ω1 and μ2 in Ω2, and μ1 and μ2 are compatible and expr(merge(μ1, μ2)) is true } debug("=>(merge s1 s2) #{s.inspect}", ) solutions << s load_left = false # Left solution added one or more times due to merge end end if load_left debug("=>(add) #{s1.inspect}", ) solutions << s1 end end @solutions = RDF::Query::Solutions.new(solutions) debug("=> #{@solutions.inspect}", ) @solutions end |
- (Union, RDF::Query) optimize
Returns an optimized version of this query.
If optimize operands, and if the first two operands are both Queries, replace with the unique sum of the query elements
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sparql/algebra/operator/left_join.rb', line 77 def optimize ops = operands.map {|o| o.optimize }.select {|o| o.respond_to?(:empty?) && !o.empty?} expr = ops.pop unless ops.last.executable? expr = nil if expr.respond_to?(:true?) && expr.true? # ops now is one or two executable operators # expr is a filter expression, which may have been optimized to 'true' case ops.length when 0 RDF::Query.new # Empty query, expr doesn't matter when 1 expr ? Filter.new(expr, ops.first) : ops.first else expr ? LeftJoin(ops[0], ops[1], expr) : LeftJoin(ops[0], ops[1]) end end |