Fix bug with BGP queries provided as maps

This commit is contained in:
Marcel Otto 2020-10-12 23:02:56 +02:00
parent 9ecc59b542
commit d3c6336782
2 changed files with 15 additions and 2 deletions

View file

@ -72,7 +72,7 @@ defmodule RDF.Query do
{:ok, matcher.execute(query, graph, opts)} {:ok, matcher.execute(query, graph, opts)}
end end
def execute(query, graph, opts) when is_list(query) or is_tuple(query) do def execute(query, graph, opts) do
with {:ok, bgp} <- Builder.bgp(query) do with {:ok, bgp} <- Builder.bgp(query) do
execute(bgp, graph, opts) execute(bgp, graph, opts)
end end
@ -140,7 +140,7 @@ defmodule RDF.Query do
{:ok, matcher.stream(query, graph, opts)} {:ok, matcher.stream(query, graph, opts)}
end end
def stream(query, graph, opts) when is_list(query) or is_tuple(query) do def stream(query, graph, opts) do
with {:ok, bgp} <- Builder.bgp(query) do with {:ok, bgp} <- Builder.bgp(query) do
stream(bgp, graph, opts) stream(bgp, graph, opts)
end end

View file

@ -21,6 +21,7 @@ defmodule RDF.QueryTest do
def example_graph, do: @example_graph def example_graph, do: @example_graph
@example_query [{:s?, FOAF.name(), ~L"Peter Goodguy"}] @example_query [{:s?, FOAF.name(), ~L"Peter Goodguy"}]
@example_query_map %{s?: %{FOAF.name() => ~L"Peter Goodguy"}}
test "execute/2" do test "execute/2" do
assert RDF.Query.execute(RDF.Query.bgp(@example_query), @example_graph) == assert RDF.Query.execute(RDF.Query.bgp(@example_query), @example_graph) ==
@ -28,6 +29,9 @@ defmodule RDF.QueryTest do
assert RDF.Query.execute(@example_query, @example_graph) == assert RDF.Query.execute(@example_query, @example_graph) ==
{:ok, BGP.Stream.execute(RDF.Query.bgp(@example_query), @example_graph)} {:ok, BGP.Stream.execute(RDF.Query.bgp(@example_query), @example_graph)}
assert RDF.Query.execute(@example_query_map, @example_graph) ==
{:ok, BGP.Stream.execute(RDF.Query.bgp(@example_query_map), @example_graph)}
end end
test "execute!/2" do test "execute!/2" do
@ -36,6 +40,9 @@ defmodule RDF.QueryTest do
assert RDF.Query.execute!(@example_query, @example_graph) == assert RDF.Query.execute!(@example_query, @example_graph) ==
BGP.Stream.execute(RDF.Query.bgp(@example_query), @example_graph) BGP.Stream.execute(RDF.Query.bgp(@example_query), @example_graph)
assert RDF.Query.execute!(@example_query_map, @example_graph) ==
BGP.Stream.execute(RDF.Query.bgp(@example_query_map), @example_graph)
end end
test "stream/2" do test "stream/2" do
@ -44,6 +51,9 @@ defmodule RDF.QueryTest do
assert RDF.Query.stream(@example_query, @example_graph) == assert RDF.Query.stream(@example_query, @example_graph) ==
{:ok, BGP.Stream.stream(RDF.Query.bgp(@example_query), @example_graph)} {:ok, BGP.Stream.stream(RDF.Query.bgp(@example_query), @example_graph)}
assert RDF.Query.stream(@example_query_map, @example_graph) ==
{:ok, BGP.Stream.stream(RDF.Query.bgp(@example_query_map), @example_graph)}
end end
test "stream!/2" do test "stream!/2" do
@ -52,5 +62,8 @@ defmodule RDF.QueryTest do
assert RDF.Query.stream!(@example_query, @example_graph) == assert RDF.Query.stream!(@example_query, @example_graph) ==
BGP.Stream.stream(RDF.Query.bgp(@example_query), @example_graph) BGP.Stream.stream(RDF.Query.bgp(@example_query), @example_graph)
assert RDF.Query.stream!(@example_query_map, @example_graph) ==
BGP.Stream.stream(RDF.Query.bgp(@example_query_map), @example_graph)
end end
end end