Class: SPARQL::Algebra::Operator::Coalesce
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- 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
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
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!
Methods inherited from SPARQL::Algebra::Operator
#aggregate?, arity, #base_uri, base_uri, base_uri=, #bind, #boolean, #constant?, #deep_dup, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, #prefixes, prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #validate!, #variable?, #variables, #vars
Methods included from Expression
cast, #constant?, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?
Constructor Details
This class inherits a constructor from SPARQL::Algebra::Operator
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 |