Class: SPARQL::Algebra::Operator::Modify
- Inherits:
-
SPARQL::Algebra::Operator
- Object
- SPARQL::Algebra::Operator
- SPARQL::Algebra::Operator::Modify
- Includes:
- Update
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/modify.rb
Overview
The SPARQL UPDATE modify
operator.
Wraps delete/insert
If options
contains any of the Protocol attributes, it is treated as if there is a USING or USING NAMED clause inserted.
using-graph-uri
using-named-graph-uri
[41] Modify ::= ( 'WITH' iri )? ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' GroupGraphPattern
Constant Summary collapse
- NAME =
[:modify]
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Constants included from RDF::Util::Logger
Instance Attribute Summary
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#execute(queryable, **options) ⇒ RDF::Queryable
Executes this upate on the given
writable
graph or repository. -
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Methods included from Update
#graph_name=, #unshift, #variables
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, #formulae, #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?, #evaluate, extension, extension?, extensions, for, #invalid?, new, #node?, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?
Methods included from RDF::Util::Logger
#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger
Constructor Details
This class inherits a constructor from SPARQL::Algebra::Operator
Instance Method Details
#execute(queryable, **options) ⇒ RDF::Queryable
Executes this upate on the given writable
graph or repository.
Execute the first operand to get solutions, and apply those solutions to the subsequent operators.
If options
contains any of the Protocol attributes, any using
clause is removed and a new using
clause is added with entries taken from the using-graph-uri
and using-named-graph-uri
.
It is an error to supply the using-graph-uri or using-named-graph-uri parameters when using this protocol to convey a SPARQL 1.1 Update request that contains an operation that uses the USING, USING NAMED, or WITH clause.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/modify.rb', line 58 def execute(queryable, **) debug() {"Modify"} query = operands.shift if %i(using-graph-uri using-named-graph-uri).any? {|k| .key?(k)} raise ArgumentError, "query contains USING/WITH clause, which is incompatible with using-graph-uri or using-named-graph-uri query parameters" if query.is_a?(Operator::Using) || query.is_a?(Operator::With) debug("=> Insert USING clause", ) defaults = Array(.delete(:'using-graph-uri')).map {|uri| RDF::URI(uri)} named = Array(.delete(:'using-named-graph-uri')).map {|uri| [:named, RDF::URI(uri)]} query = Operator::Using.new((defaults + named), query, **) end queryable.query(query, **.merge(depth: [:depth].to_i + 1)) do |solution| debug() {"(solution)=>#{solution.inspect}"} # Execute each operand with queryable and solution operands.each do |op| op.execute(queryable, solutions: solution, **.merge(depth: [:depth].to_i + 1)) end end queryable end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/modify.rb', line 90 def to_sparql(**) if operands.first.is_a?(With) operands.first.to_sparql(**) else # The content of the WHERE clause, may be USING content = operands.first.to_sparql(top_level: false, **) # DELETE | INSERT | DELETE INSERT str = operands[1..-1].to_sparql(top_level: false, delimiter: "\n", **) + "\n" # Append the WHERE or USING clause str << if operands.first.is_a?(Using) content else Operator.to_sparql(content, project: nil, **) end end end |