Class: SPARQL::Algebra::Operator::Move

Inherits:
SPARQL::Algebra::Operator show all
Includes:
Update
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/move.rb

Overview

The SPARQL UPDATE move operator.

The MOVE operation is a shortcut for moving all data from an input graph into a destination graph. The input graph is removed after insertion and data from the destination graph, if any, is removed before insertion.

[36] Move ::= 'MOVE' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault

Examples:

SPARQL Grammar

MOVE SILENT GRAPH <http://www.example.com/g1> TO DEFAULT

SSE

(update
 (move silent <http://www.example.com/g1> default))

See Also:

Constant Summary collapse

NAME =
[:move]

Constants inherited from SPARQL::Algebra::Operator

ARITY, IsURI, URI

Constants included from Expression

Expression::PATTERN_PARENTS

Constants included from RDF::Util::Logger

RDF::Util::Logger::IOWrapper

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=, #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.

Parameters:

Options Hash (**options):

  • debug (Boolean)

    Query execution debugging

Returns:

Raises:

  • (IOError)

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

See Also:



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
69
70
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/move.rb', line 38

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

  src_name, dest_name = operands[-2..-1]
  raise ArgumentError, "move expected two operands, got #{operands.length}" unless operands.length == 2
  raise ArgumentError, "move from must be IRI or :default" unless src_name == :default || src_name.is_a?(RDF::URI)
  raise ArgumentError, "move 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, "move operation source does not exist" unless silent
  elsif dest_name == src_name
    # No operation
  else
    dest = queryable.enum_graph.detect {|g| g.to_s == dest_name.to_s}
    
    # Clear destination first
    dest.clear! if dest

    # Copy statements using destination graph
    src.each do |statement|
      statement = statement.dup
      statement.graph_name = (dest_name unless dest_name == :default)
      queryable << statement
    end

    # Clear source
    src.clear!
  end
  queryable
end

#to_sparql(**options) ⇒ String

Returns a partial SPARQL grammar for this operator.

Returns:



77
78
79
80
81
82
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-36baa432eb7f/lib/sparql/algebra/operator/move.rb', line 77

def to_sparql(**options)
  *args, last = operands.dup
  args += [:TO, last]
  
  "MOVE " + args.to_sparql(**options)
end