Class: SPARQL::Algebra::Operator::Project
- Inherits:
-
Binary
- Object
- SPARQL::Algebra::Operator
- Binary
- SPARQL::Algebra::Operator::Project
- Includes:
- Query
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/project.rb
Overview
The SPARQL GraphPattern project
operator.
[9] SelectClause ::= 'SELECT' ( 'DISTINCT' | 'REDUCED' )? ( ( Var | ( '(' Expression 'AS' Var ')' ) )+ | '*' )
Basic Projection
Constant Summary collapse
- NAME =
[:project]
Constants inherited from Binary
Constants inherited from SPARQL::Algebra::Operator
Constants included from Expression
Constants included from RDF::Util::Logger
Instance Attribute Summary
Attributes included from Query
Attributes inherited from SPARQL::Algebra::Operator
Instance Method Summary collapse
-
#execute(queryable, **options) {|solution| ... } ⇒ RDF::Query::Solutions
Executes this query on the given
queryable
graph or repository. -
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
-
#validate! ⇒ Operator
Can only project in-scope variables.
-
#variables ⇒ Hash{Symbol => RDF::Query::Variable}
In-scope variables for a select are limited to those projected.
Methods included from Query
#each_solution, #empty?, #failed?, #graph_name=, #matched?, #query_yields_boolean?, #query_yields_solutions?, #query_yields_statements?, #unshift
Methods inherited from Binary
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, #mergable?, #ndvars, #node?, #operand, #optimize, #optimize!, #parent, #parent=, prefixes, #prefixes, prefixes=, #rewrite, #to_binary, to_sparql, #to_sxp, #to_sxp_bin, #variable?, #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?, #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::Binary
Instance Method Details
#execute(queryable, **options) {|solution| ... } ⇒ RDF::Query::Solutions
Executes this query on the given queryable
graph or repository.
Reduces the result set to the variables listed in the first operand
If the first operand is empty, this indicates a SPARQL *
, and all in-scope variables are projected.
103 104 105 106 107 108 109 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/project.rb', line 103 def execute(queryable, **, &block) @solutions = queryable.query(operands.last, **.merge(depth: [:depth].to_i + 1)) @solutions.variable_names = self.variables.keys @solutions = @solutions.project(*(operands.first)) unless operands.first.empty? @solutions.each(&block) if block_given? @solutions end |
#to_sparql(**options) ⇒ String
Returns a partial SPARQL grammar for this operator.
Extracts projections
If there are already extensions or filters, then this is a sub-select.
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/project.rb', line 132 def to_sparql(**) vars = operands[0].empty? ? [:*] : operands[0] if [:extensions] || [:filter_ops] || [:project] # Any of these options indicates we're in a sub-select opts = .dup.delete_if {|k,v| %I{extensions filter_ops project}.include?(k)} content = operands.last.to_sparql(project: vars, **opts) content = "{#{content}}" unless content.start_with?('{') && content.end_with?('}') Operator.to_sparql(content, **) else operands.last.to_sparql(project: vars, **) end end |
#validate! ⇒ Operator
Can only project in-scope variables.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/project.rb', line 64 def validate! if (group = descendants.detect {|o| o.is_a?(Group)}) raise ArgumentError, "project * on group is illegal" if operands.first.empty? query_vars = operands.last.variables variables.keys.each do |v| raise ArgumentError, "projecting #{v.to_sse} not projected from group" unless query_vars.key?(v.to_sym) end end super end |
#variables ⇒ Hash{Symbol => RDF::Query::Variable}
In-scope variables for a select are limited to those projected.
82 83 84 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-796d3be4aa08/lib/sparql/algebra/operator/project.rb', line 82 def variables operands(1).inject({}) {|hash, o| hash.merge(o.variables)} end |