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 to master - Release 2.3.5 - Optimize order by and filters queries #35

Merged
merged 145 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
f20479f
add tests for the new dsl to write property data types
syphax-bouazzouni Feb 27, 2023
b6cbb1a
append the property :type values to the :enforce array
syphax-bouazzouni Feb 27, 2023
67707a6
Merge pull request #23 from ontoportal-lirmm/feature/add-property-dat…
syphax-bouazzouni Feb 27, 2023
209ea16
update solution mapper to support multilingual
haddadzineddine Feb 27, 2023
207a483
update solution mapper to support multilingual
haddadzineddine Feb 27, 2023
1a7a6bf
fix typo ( name )
haddadzineddine Feb 27, 2023
8cfd2f7
add validators tests file
syphax-bouazzouni Feb 28, 2023
85ca3a5
add validator interface module
syphax-bouazzouni Feb 28, 2023
56adaf6
implement data_type validator
syphax-bouazzouni Feb 28, 2023
27fffc1
migrate existence validator to the new DSL
syphax-bouazzouni Feb 28, 2023
cd67a52
migrate uniqueness validator to the new DSL
syphax-bouazzouni Feb 28, 2023
887653c
implement object_type validator with the new DSL
syphax-bouazzouni Feb 28, 2023
9227510
migrate range validator to the new DSL
syphax-bouazzouni Feb 28, 2023
2d1457d
refactor the enforce module to use the new validators implementation
syphax-bouazzouni Feb 28, 2023
6091f1a
force to regenerate the id when we update related attribute (named_with)
syphax-bouazzouni Feb 28, 2023
24c9939
require the validators implementation
syphax-bouazzouni Feb 28, 2023
46d1b9f
update existence validator to not accept empty to_s objects
syphax-bouazzouni Feb 28, 2023
243bead
Merge branch 'pr/refactor/resources-validators' into refactor/resourc…
syphax-bouazzouni Feb 28, 2023
a998a4e
update exist? test
syphax-bouazzouni Feb 28, 2023
54be764
Merge branch 'pr/refactor/resources-validators' into refactor/resourc…
syphax-bouazzouni Feb 28, 2023
3eb11be
Merge pull request #26 from ontoportal-lirmm/refactor/resources-valid…
syphax-bouazzouni Feb 28, 2023
5168edf
add symmetric validator tests for no_list and list cases
syphax-bouazzouni Feb 28, 2023
810771a
implement symmetric validator
syphax-bouazzouni Feb 28, 2023
0f20d7a
move re used methods to the parent class
syphax-bouazzouni Feb 28, 2023
9e4739c
update symmetric code and error message
syphax-bouazzouni Feb 28, 2023
05bb6cb
add distinct of validator tests
syphax-bouazzouni Feb 28, 2023
fb62419
implement distinct_of validator
syphax-bouazzouni Feb 28, 2023
5cd980d
add superior_equal_to validator tests
syphax-bouazzouni Feb 28, 2023
0d17a84
extract property method to ValidatorBase class
syphax-bouazzouni Feb 28, 2023
5740a6b
implement superior_equal_to validator
syphax-bouazzouni Feb 28, 2023
9707004
add inverse of validator tests
syphax-bouazzouni Feb 28, 2023
9ea0be8
implement inverse_of validator
syphax-bouazzouni Feb 28, 2023
ba8bf8a
use the class method property in distinct of
syphax-bouazzouni Feb 28, 2023
f190ae8
Merge pull request #27 from ontoportal-lirmm/feature/implement-new-va…
syphax-bouazzouni Feb 28, 2023
f061e51
add proc validator tests
syphax-bouazzouni Feb 28, 2023
b7cccab
add instance proc validators
syphax-bouazzouni Feb 28, 2023
73def74
fix call_proc validator to test if the returned values are correct
syphax-bouazzouni Feb 28, 2023
93530e5
Merge pull request #28 from ontoportal-lirmm/feature/implement-new-va…
syphax-bouazzouni Feb 28, 2023
fe85a2b
add model_with_yaml_scheme test
syphax-bouazzouni Feb 28, 2023
4255a09
implement YAMLScheme module
syphax-bouazzouni Feb 28, 2023
0d467ad
use YAMLScheme module in Settings module
syphax-bouazzouni Feb 28, 2023
210e328
Merge pull request #30 from ontoportal-lirmm/feature/add-model-scheme…
syphax-bouazzouni Feb 28, 2023
a903826
use platform lang and code refacto
haddadzineddine Mar 1, 2023
ef7f5cf
filter by lang in properties
haddadzineddine Mar 1, 2023
562065b
do some refactoring
haddadzineddine Mar 1, 2023
6f9e73d
add unmapped_get to goo resources
syphax-bouazzouni Mar 3, 2023
9f91124
update lang filter module to support requested_lang and portal_lang
syphax-bouazzouni Mar 3, 2023
536e22f
use the new lang filter module in the solution_mapper
syphax-bouazzouni Mar 3, 2023
085eb41
remove the usage of the old lang filter module in map_attributes
syphax-bouazzouni Mar 3, 2023
3773c52
Merge branch 'development' into feature/support-multilingual-read-one…
syphax-bouazzouni Mar 3, 2023
48389a0
add request language global variable
syphax-bouazzouni Mar 4, 2023
08bdaa1
fix datatype check for list values
syphax-bouazzouni Mar 4, 2023
44966b6
Merge branch 'feature/implement-new-validators' into development
syphax-bouazzouni Mar 4, 2023
d461c59
Merge remote-tracking branch 'origin/development' into development
syphax-bouazzouni Mar 4, 2023
8086049
Merge branch 'development' into feature/support-multilingual-read-one…
syphax-bouazzouni Mar 4, 2023
5e5c772
remove old unused test if clause
syphax-bouazzouni Mar 4, 2023
4cc7a7f
for no unmapped values cast them to object before sending
syphax-bouazzouni Mar 4, 2023
660e8c5
for resource unmapped_set merge new value if an array
syphax-bouazzouni Mar 4, 2023
d30c574
prevent add_object_to_model if no_lang and previous value exist
syphax-bouazzouni Mar 4, 2023
96e5732
move from the mapper lang_filter related code to lang_filter module
syphax-bouazzouni Mar 4, 2023
92bed92
move internal lang filter module methods to private section
syphax-bouazzouni Mar 4, 2023
bcbf686
add request_store gem to save request language globally
syphax-bouazzouni Mar 4, 2023
f1a5845
save requested language in model_load options
syphax-bouazzouni Mar 4, 2023
ac8709a
force requested_lang and portal_langs to be upcase and symbol
syphax-bouazzouni Mar 5, 2023
8dbb74b
change methodes/vars names
haddadzineddine Mar 6, 2023
f841af8
Merge branch 'feature/support-multilingual-read-one-language-from-req…
haddadzineddine Mar 6, 2023
996922a
get the last item in objects instead of passing the current object
haddadzineddine Mar 6, 2023
dedba29
Merge pull request #24 from ontoportal-lirmm/feature/support-multilin…
syphax-bouazzouni Mar 6, 2023
b769c16
Revert "get the last item in objects instead of passing the current o…
haddadzineddine Mar 6, 2023
30ed9f9
handle this case where values is nil in save_model_values
syphax-bouazzouni Mar 7, 2023
597436e
Merge branch 'feature/support-multilingual-read-one-language-from-req…
syphax-bouazzouni Mar 7, 2023
07b06c3
handle the casf of nil values for the SuperiorEqualTo validator
syphax-bouazzouni Mar 14, 2023
a82a443
Merge branch 'feature/implement-new-validators' into development
syphax-bouazzouni Mar 14, 2023
c83687e
add onUpdate callback tests
syphax-bouazzouni Mar 16, 2023
e4979ff
implement enforce_callback to run an attribute callback
syphax-bouazzouni Mar 16, 2023
c7f7092
move the attribute default callback to the save method
syphax-bouazzouni Mar 16, 2023
f81b15f
implement onUpdate DSL in the ressource settings
syphax-bouazzouni Mar 16, 2023
714f085
call to the attributes onUpdate callback in the save method
syphax-bouazzouni Mar 16, 2023
90f3336
Merge pull request #31 from ontoportal-lirmm/feature/add-models-on-up…
syphax-bouazzouni Mar 16, 2023
f8caff7
in validators bring attribute if needed
syphax-bouazzouni Mar 17, 2023
89d8510
Merge branch 'feature/implement-new-validators' into development
syphax-bouazzouni Mar 17, 2023
7de77a0
make superior_equal_to works for list attributes
syphax-bouazzouni Mar 19, 2023
1895ccd
Merge branch 'feature/implement-new-validators' into development
syphax-bouazzouni Mar 19, 2023
5ca8b16
add email validator test
syphax-bouazzouni Mar 19, 2023
6f4f50f
implement email validator
syphax-bouazzouni Mar 19, 2023
f9b73ce
Merge branch 'feature/implement-new-validators' into development
syphax-bouazzouni Mar 19, 2023
f786879
add filters patterns to select variables
syphax-bouazzouni Apr 22, 2023
a613c80
make make regex filter no-case sensitive
syphax-bouazzouni Apr 22, 2023
88676a1
if requested_lang = 'all' return all
haddadzineddine Apr 23, 2023
688ec5e
support select multilanguage
haddadzineddine Apr 24, 2023
7871af7
show the values with their corresponding language
haddadzineddine Apr 26, 2023
dd5f3ef
use @attributes_to_translate
haddadzineddine Apr 26, 2023
38346eb
Merge pull request #34 from ontoportal-lirmm/fix/filters-with-paginat…
syphax-bouazzouni Apr 28, 2023
1484ad5
Merge pull request #33 from ontoportal-lirmm/feature/make-regex-filte…
syphax-bouazzouni Apr 28, 2023
5f81e7b
change methode name
haddadzineddine Apr 28, 2023
bb685a2
remove platform languages
haddadzineddine Apr 28, 2023
778b696
add complex_order_by unit test
syphax-bouazzouni May 1, 2023
b7a4c56
refactor query_builder to extract internal_variables as instance vari…
syphax-bouazzouni May 1, 2023
4df6681
update order_by to work for joined patterns (object attributes)
syphax-bouazzouni May 1, 2023
c3456c4
Merge pull request #36 from ontoportal-lirmm/feature/add-complex-oder-by
syphax-bouazzouni May 1, 2023
7ffeccd
downcase lang key
haddadzineddine May 9, 2023
3967feb
Fix the issue of undefined 'id' of the language filter module
syphax-bouazzouni May 10, 2023
78e6420
Show literal attribute if we requested all the languages
syphax-bouazzouni May 10, 2023
7e1410c
Use portal language by default in the language filter module
syphax-bouazzouni May 10, 2023
c6660c3
Merge branch 'feature/language-return-all' into development
syphax-bouazzouni May 10, 2023
40df9b0
group unmapped properties by lang
haddadzineddine Jun 1, 2023
cbd0186
Feature: group unmapped properties by language (#38)
haddadzineddine Jun 6, 2023
e0bf04f
assert that pre in an array in get_value_object
haddadzineddine Jun 13, 2023
39b7f2f
add label to attributes_to_translate
haddadzineddine Jun 13, 2023
8af1d47
update define_method
haddadzineddine Jun 20, 2023
5b7c78f
update solution mapper
haddadzineddine Jun 20, 2023
3161fbb
update get_preload_value
haddadzineddine Jun 20, 2023
6c17904
Feature: Support multi lingual - add show_language argument to the a…
haddadzineddine Jun 28, 2023
cca637e
fix save_model_values if unmmaped condition
haddadzineddine Jul 13, 2023
e7a1e75
Merge branch 'development' into support-muli-lang-part-02
haddadzineddine Jul 13, 2023
4f60437
Merge pull request #40 from ontoportal-lirmm/support-muli-lang-part-02
haddadzineddine Jul 13, 2023
94959cd
fix getters for list attributes to not take only the first value
syphax-bouazzouni Jul 14, 2023
37da0d3
remove the languages hash for the unmapped if not a mutli langual asked
syphax-bouazzouni Jul 14, 2023
a650480
move some language helper from the mapper to the lang_filter module
syphax-bouazzouni Jul 14, 2023
6785c4b
move @requested_lang variable from the mapper to the lang_filter module
syphax-bouazzouni Jul 14, 2023
966ab12
remove no more used @attributes_to_translate variable in lang_filter
syphax-bouazzouni Jul 14, 2023
ae7be1f
Merge branch 'development' into support-muli-lang-part-02
syphax-bouazzouni Jul 14, 2023
a990260
fix save_model_values method to not save RDF:Literal object but a string
syphax-bouazzouni Jul 14, 2023
5d0a84b
remove not used method in lang filter module
syphax-bouazzouni Jul 14, 2023
58b07f3
refecator and rename some methods of the lang_filter module
syphax-bouazzouni Jul 14, 2023
efd0436
use the new name of the lang filter methods in the solution mapper
syphax-bouazzouni Jul 14, 2023
e26009a
replace the getters argument to show languages from :show_all_languag…
syphax-bouazzouni Jul 14, 2023
10722be
Merge pull request #41 from ontoportal-lirmm/support-muli-lang-part-02
syphax-bouazzouni Jul 14, 2023
e5d4d1a
catch transform_values of unmapped if it is nil
syphax-bouazzouni Jul 14, 2023
81ce88c
Merge branch 'support-muli-lang-part-02' into development
syphax-bouazzouni Jul 14, 2023
5952f87
change the getters show_all_languages argument from to include_languages
syphax-bouazzouni Jul 14, 2023
a81f12c
make the map_attributes handle the option showing all the languages
syphax-bouazzouni Jul 14, 2023
0c0dba9
Merge pull request #42 from ontoportal-lirmm/feature/support-multi-la…
syphax-bouazzouni Jul 14, 2023
cd7d26d
fix order by an attribute that is already filtered
syphax-bouazzouni Sep 21, 2023
0019b4b
Merge pull request #47 from ontoportal-lirmm/fix/complex-orderby-with…
syphax-bouazzouni Sep 21, 2023
891fa99
don't add the filtered variables to the select clause of the query
syphax-bouazzouni Sep 22, 2023
6946668
Merge branch 'fix/complex-orderby-with-filters' into development
syphax-bouazzouni Sep 22, 2023
e87c21e
add filters patterns to select variables
syphax-bouazzouni Oct 19, 2023
19c9ce1
fix pagination with order_by with filter that returns empty pages for…
syphax-bouazzouni Oct 19, 2023
4c46c8a
Merge pull request #49 from ontoportal-lirmm/fix/filters-with-paginat…
syphax-bouazzouni Oct 19, 2023
c4dd04d
include the in the select variables filtered variables
syphax-bouazzouni Oct 19, 2023
5247e8d
optimize pagination query by not re-doing the filters and order in th…
syphax-bouazzouni Oct 19, 2023
5979402
Merge pull request #50 from ontoportal-lirmm/fix/filters-with-paginat…
syphax-bouazzouni Oct 19, 2023
8c2faa0
Merge branch 'master'
syphax-bouazzouni Dec 4, 2023
9aa0cca
Merge branch 'master' into development
syphax-bouazzouni Dec 4, 2023
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
2 changes: 1 addition & 1 deletion lib/goo/base/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def unmmaped_to_array
end

def unmapped(*args)
@unmapped.transform_values do |language_values|
@unmapped&.transform_values do |language_values|
self.class.not_show_all_languages?(language_values, args) ? language_values.values.flatten: language_values
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/goo/base/where.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def process_query_intl(count=false)

options_load[:ids] = ids if ids
models_by_id = {}
if @page_i && (options_load[:models].length > 0)
options_load.delete(:filters)
options_load.delete(:order_by)
end

if (@page_i && options_load[:models].length > 0) ||
(!@page_i && (@count.nil? || @count > 0))
models_by_id = Goo::SPARQL::Queries.model_load(options_load)
Expand Down
4 changes: 2 additions & 2 deletions lib/goo/sparql/mixins/solution_lang_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def fill_models_with_all_languages(models_by_id)
end


def set_model_value(model, predicate, values)
set_value(model, predicate, values) do
def set_model_value(model, predicate, values, value)
set_value(model, predicate, value) do
model.send("#{predicate}=", values, on_load: true)
end
end
Expand Down
87 changes: 55 additions & 32 deletions lib/goo/sparql/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@ def build_select_query(ids, variables, graphs, patterns,
query_options, properties_to_include)

patterns = graph_match(@collection, @graph_match, graphs, @klass, patterns, query_options, @unions)

aggregate_projections, aggregate_vars,
variables, optional_patterns = get_aggregate_vars(@aggregate, @collection, graphs,
@klass, @unions, variables)

@order_by, variables, optional_patterns = init_order_by(@count, @klass, @order_by, optional_patterns, variables,patterns, query_options, graphs)
variables, patterns = add_some_type_to_id(patterns, query_options, variables)

aggregate_projections, aggregate_vars, variables, optional_patterns = get_aggregate_vars(@aggregate, @collection, graphs, @klass, @unions, variables)
query_filter_str, patterns, optional_patterns, filter_variables =
filter_query_strings(@collection, graphs, @klass, optional_patterns, patterns, @query_filters)
@order_by, variables, optional_patterns = init_order_by(@count, @klass, @order_by, optional_patterns, variables,patterns, query_options, graphs)
order_by_str, order_variables = order_by_string


variables = [] if @count
variables.delete :some_type

select_distinct(variables, aggregate_projections, filter_variables)
select_distinct(variables, aggregate_projections, filter_variables, order_variables)
.from(graphs)
.where(patterns)
.union_bind_in_where(properties_to_include)
Expand All @@ -55,7 +52,10 @@ def build_select_query(ids, variables, graphs, patterns,
@query.union(*@unions) unless @unions.empty?

ids_filter(ids) if ids
order_by if @order_by


@query.order_by(*order_by_str) if @order_by


put_query_aggregate_vars(aggregate_vars) if aggregate_vars
count if @count
Expand Down Expand Up @@ -117,16 +117,17 @@ def put_query_aggregate_vars(aggregate_vars)
self
end

def order_by
order_by_str = @order_by.map do |attr, order|
def order_by_string
order_variables = []
order_str = @order_by&.map do |attr, order|
if order.is_a?(Hash)
sub_attr, order = order.first
attr = @internal_variables_map[sub_attr]
attr = @internal_variables_map.select{ |internal_var, attr_var| attr_var.eql?({attr => sub_attr}) || attr_var.eql?(sub_attr)}.keys.last
end
order_variables << attr
"#{order.to_s.upcase}(?#{attr})"
end
@query.order_by(*order_by_str)
self
[order_str,order_variables]
end

def from(graphs)
Expand All @@ -141,10 +142,11 @@ def from(graphs)
self
end

def select_distinct(variables, aggregate_projections, filter_variables)
def select_distinct(variables, aggregate_variables, filter_variables, order_variables)
select_vars = variables.dup
reject_aggregations_from_vars(select_vars, aggregate_projections) if aggregate_projections
select_vars = (select_vars + filter_variables).uniq if @page # Fix for 4store pagination with a filter
reject_aggregations_from_vars(select_vars, aggregate_variables) if aggregate_variables
# Fix for 4store pagination with a filter https://github.com/ontoportal-lirmm/ontologies_api/issues/25
select_vars = (select_vars + filter_variables + order_variables).uniq if @page
@query = @query.select(*select_vars).distinct(true)
self
end
Expand All @@ -165,23 +167,24 @@ def ids_filter(ids)
def patterns_for_match(klass, attr, value, graphs, patterns, unions,
internal_variables, subject = :id, in_union = false,
in_aggregate = false, query_options = {}, collection = nil)
new_internal_var = value
if value.respond_to?(:each) || value.instance_of?(Symbol)
next_pattern = value.instance_of?(Array) ? value.first : value

#for filters
next_pattern = { next_pattern => [] } if next_pattern.instance_of?(Symbol)

value = "internal_join_var_#{internal_variables.length}".to_sym
new_internal_var = "internal_join_var_#{internal_variables.length}".to_sym
if in_aggregate
value = "#{attr}_agg_#{in_aggregate}".to_sym
new_internal_var = "#{attr}_agg_#{in_aggregate}".to_sym
end
internal_variables << value
@internal_variables_map[attr] = value
internal_variables << new_internal_var
@internal_variables_map[new_internal_var] = value.empty? ? attr : {attr => value}
end

add_rules(attr, klass, query_options)
graph, pattern =
query_pattern(klass, attr, value: value, subject: subject, collection: collection)
query_pattern(klass, attr, value: new_internal_var, subject: subject, collection: collection)
if pattern
if !in_union
patterns << pattern
Expand All @@ -194,7 +197,7 @@ def patterns_for_match(klass, attr, value, graphs, patterns, unions,
range = klass.range(attr)
next_pattern.each do |next_attr, next_value|
patterns_for_match(range, next_attr, next_value, graphs,
patterns, unions, internal_variables, subject = value,
patterns, unions, internal_variables, subject = new_internal_var,
in_union, in_aggregate, collection = collection)
end
end
Expand Down Expand Up @@ -270,15 +273,35 @@ def init_order_by(count, klass, order_by, optional_patterns, variables, patterns
order_by.each do |attr, direction|

if direction.is_a?(Hash)
# TODO this part can be improved/refactored, the complexity was added because order by don't work
# if the pattern is in the mandatory ones (variable `patterns`)
# and optional (variable `optional_patterns`) at the same time
sub_attr, direction = direction.first
graph_match_iteration = Goo::Base::PatternIteration.new(Goo::Base::Pattern.new({attr => [sub_attr]}))
old_internal = internal_variables.dup
old_patterns = optional_patterns.dup

walk_pattern(klass, graph_match_iteration, graphs, optional_patterns, @unions, internal_variables, in_aggregate = false, query_options, @collection)
variables << (internal_variables - old_internal).last
new_variables = (internal_variables - old_internal)
internal_variables.delete(new_variables)
new_patterns = optional_patterns - old_patterns
already_existent_pattern = patterns.select{|x| x[1].eql?(new_patterns.last[1])}.first

if already_existent_pattern
already_existent_variable = already_existent_pattern[2]
optional_patterns = old_patterns
key = @internal_variables_map.select{|key, value| key.eql?(new_variables.last)}.keys.first
@internal_variables_map[key] = (already_existent_variable || new_variables.last) if key

#variables << already_existent_variable
else
#variables << new_variables.last
end

else
quad = query_pattern(klass, attr)
optional_patterns << quad[1]
variables << attr
#variables << attr
end

#patterns << quad[1]
Expand Down Expand Up @@ -325,7 +348,12 @@ def query_filter_sparql(klass, filter, filter_patterns, filter_graphs,
end
filter_var = inspected_patterns[filter_pattern_match]

unless filter_operation.value.instance_of?(Goo::Filter)
if filter_operation.value.instance_of?(Goo::Filter)
filter_operations << "#{sparql_op_string(filter_operation.operator)}"
query_filter_sparql(klass, filter_operation.value, filter_patterns,
filter_graphs, filter_operations,
internal_variables, inspected_patterns, collection)
else
case filter_operation.operator
when :unbound
filter_operations << "!BOUND(?#{filter_var.to_s})"
Expand All @@ -349,11 +377,6 @@ def query_filter_sparql(klass, filter, filter_patterns, filter_graphs,
" #{value.to_ntriples}")
end

else
filter_operations << "#{sparql_op_string(filter_operation.operator)}"
query_filter_sparql(klass, filter_operation.value, filter_patterns,
filter_graphs, filter_operations,
internal_variables, inspected_patterns, collection)
end
end
end
Expand Down Expand Up @@ -399,7 +422,7 @@ def add_some_type_to_id(patterns, query_options, variables)
end

def internal_variables
@internal_variables_map.values
@internal_variables_map.keys
end
end
end
Expand Down
Loading