Class: SPARQL::Algebra::Operator::Add

Inherits:
SPARQL::Algebra::Operator show all
Includes:
Update
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/sparql-7b34b4cf091a/lib/sparql/algebra/operator/add.rb

Overview

The SPARQL UPDATE add operator.

The ADD operation is a shortcut for inserting all data from an input graph into a destination graph. Data from the input graph is not affected, and initial data from the destination graph, if any, is kept intact.

Examples:

(add default <a>)

See Also:

Constant Summary collapse

NAME =
[:add]

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Instance Attribute Summary

Attributes inherited from SPARQL::Algebra::Operator

#operands

Instance Method Summary collapse

Methods included from Update

#graph_name=, #unshift, #variables

Methods inherited from SPARQL::Algebra::Operator

#aggregate?, arity, #base_uri, base_uri, base_uri=, #boolean, #constant?, #each_descendant, #eql?, #evaluatable?, evaluate, #executable?, #first_ancestor, for, #initialize, #inspect, #ndvars, #node?, #operand, #optimize, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, #to_sxp, #to_sxp_bin, #validate!, #variable?, #vars

Methods included from Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #optimize, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

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.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to write

  • options (Hash{Symbol => Object}) (defaults to: {})

    any additional keyword options

Options Hash (options):

  • debug (Boolean)

    Query execution debugging

Returns:

Raises:

  • (IOError)

    If from does not exist, unless the silent operator is present

See Also:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-7b34b4cf091a/lib/sparql/algebra/operator/add.rb', line 32

def execute(queryable, options = {})
  debug(options) {"Add"}
  silent = operands.first == :silent
  operands.shift if silent

  src_name, dest_name = operands[-2..-1]
  raise ArgumentError, "add expected two operands, got #{operands.length}" unless operands.length == 2
  raise ArgumentError, "add from must be IRI or :default" unless src_name == :default || src_name.is_a?(RDF::URI)
  raise ArgumentError, "add to must be IRI or :default" unless dest_name == :default || dest_name.is_a?(RDF::URI)
  src = queryable.enum_graph.detect {|g| g.to_s == src_name.to_s}

  if src.nil?
    raise IOError, "add operation source does not exist" unless silent
  else
    src.each do |statement|
      statement = statement.dup
      statement.graph_name = (dest_name unless dest_name == :default)
      queryable << statement
    end
  end
  queryable
end