Skip to content

Commit

Permalink
Fix checking for equality of blank nodes, variables, and functions co…
Browse files Browse the repository at this point in the history
…ntaining either in parser.

Fixes #46.
  • Loading branch information
gkellogg committed May 8, 2023
1 parent b704497 commit 9004d01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sparql/grammar/parser11.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ class Parser
if data[:_Compare_Numeric]
add_prod_datum(:Expression, SPARQL::Algebra::Expression.for(data[:_Compare_Numeric].insert(1, *data[:Expression])))
elsif data[:in]
expr = (data[:Expression] + data[:in]).reject {|v| v.equal?(RDF.nil)}
expr = (data[:Expression] + data[:in]).reject {|v| v.eql?(RDF.nil)}
add_prod_datum(:Expression, SPARQL::Algebra::Expression.for(expr.unshift(:in)))
elsif data[:notin]
expr = (data[:Expression] + data[:notin]).reject {|v| v.equal?(RDF.nil)}
Expand Down Expand Up @@ -2452,7 +2452,7 @@ def merge_modifiers(data)

# Replace aggregates in expr as above
expr.replace_aggregate! do |function|
if avf = aggregates.detect {|(_, f)| f == function}
if avf = aggregates.detect {|(_, f)| f.equal?(function)}
avf.first
else
# Allocate a temporary variable for this function, and retain the mapping for outside the group
Expand Down
16 changes: 16 additions & 0 deletions spec/grammar/misc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@
(bgp (triple ??0 <http://example/c> <http://example/d>))
)}
},
"issue 46" => {
query: %(
PREFIX ex: <http://example.org/>
SELECT ?ev (MIN(?a) as ?a_min) (MIN(?b) as ?b_min)
WHERE {?ev ex:a ?a ; ex:b ?b . }
GROUP BY ?ev
),
sse: %{(project (?ev ?a_min ?b_min)
(extend ((?a_min ??.0) (?b_min ??.1))
(group (?ev) ((??.0 (min ?a)) (??.1 (min ?b)))
(bgp
(triple ?ev <http://example.org/a> ?a)
(triple ?ev <http://example.org/b> ?b)))))
}
}
}.each do |test, options|
it "parses #{test}" do
expect(options[:query]).to generate(options[:sse], logger: logger)
Expand Down

0 comments on commit 9004d01

Please sign in to comment.