Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop to master, release v5.30 #8

Merged
merged 3 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions lib/sparql/client/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ def union_with_bind_as(*pattern_list)
self
end

def optional_union_with_bind_as(*pattern_list)
options[:optional_unions_with_bind] ||= []

pattern_list.each do |patterns,bind,filter|
options[:optional_unions_with_bind] << [build_patterns(patterns), bind, filter]
end
self
end

def cache_key
return nil if options[:from].nil? || options[:from].empty?
Expand Down Expand Up @@ -394,28 +402,55 @@ def to_s
buffer << "{ #{sq.to_s} } ."
end

buffer += serialize_patterns(patterns)
if options[:unions]
def add_union_with_bind(patterns)
include_union = nil
options[:unions].each do |union_block|
buffer = []
patterns.each do |pattern, options|
buffer << include_union if include_union
buffer << '{'
buffer += serialize_patterns(union_block)
buffer << '} '
buffer += serialize_patterns(pattern)
if options[:filters]
buffer += options[:filters].map do |filter|
str = filter[:values].map do |val|
"?#{filter[:predicate]} = <#{val}>"
end
"FILTER(#{str.join(' || ')}) "
end
end

if options[:binds]
buffer += options[:binds].map { |bind| "BIND( \"#{bind[:value]}\" as ?#{bind[:as]})" }
end


buffer << '}'
include_union = "UNION "
end
buffer
end
if options[:unions_with_bind]

buffer += serialize_patterns(patterns)
if options[:unions]
include_union = nil
options[:unions_with_bind].each do |union_block, value_bind, var_bind|
options[:unions].each do |union_block|

buffer << include_union if include_union
buffer << '{'
buffer += serialize_patterns(union_block)
buffer << "BIND (\"#{value_bind}\" as ?#{var_bind.to_s})"
buffer << '}'
buffer << '} '
include_union = "UNION "
end
end
if options[:unions_with_bind]
buffer << add_union_with_bind(options[:unions_with_bind])
end

if options[:optional_unions_with_bind] && !options[:optional_unions_with_bind].empty?
buffer << 'OPTIONAL {'
buffer << add_union_with_bind(options[:optional_unions_with_bind])
buffer << '}'
end

if options[:optionals]
options[:optionals].each do |patterns|
buffer << 'OPTIONAL {'
Expand Down