Class: SPARQL::Algebra::Operator::Coalesce
- Includes:
- Evaluatable
- Defined in:
- lib/sparql/algebra/operator/coalesce.rb
Overview
The SPARQL coalesce function.
[121] BuiltInCall ::= ... | 'COALESCE' ExpressionList
Constant Summary collapse
- NAME =
:coalesce
Instance Method Summary collapse
-
#evaluate(bindings, **options) ⇒ RDF::Term
The COALESCE function form returns the RDF term value of the first expression that evaluates without error.
-
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Evaluatable
#apply, #memoize, #replace_aggregate!, #replace_vars!
Instance Method Details
#evaluate(bindings, **options) ⇒ RDF::Term
The COALESCE function form returns the RDF term value of the first expression that evaluates without error. In SPARQL, evaluating an unbound variable raises an error.
If none of the arguments evaluates to an RDF term, an error is raised. If no expressions are evaluated without error, an error is raised.
57 58 59 60 61 62 63 64 65 |
# File 'lib/sparql/algebra/operator/coalesce.rb', line 57 def evaluate(bindings, **) operands.each do |op| begin return op.evaluate(bindings, **.merge(depth: [:depth].to_i + 1)) rescue end end raise TypeError, "None of the operands evaluated" end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
72 73 74 |
# File 'lib/sparql/algebra/operator/coalesce.rb', line 72 def to_sparql(**) "COALESCE(#{operands.to_sparql(delimiter: ', ', **)})" end |