15781: Adds support for exact match on 'contains' filter.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 30 Jan 2020 14:55:18 +0000 (11:55 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 30 Jan 2020 14:55:18 +0000 (11:55 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

services/api/lib/record_filters.rb
services/api/test/fixtures/collections.yml
services/api/test/functional/arvados/v1/filters_test.rb

index e059a6e70aaaba664af9ca5fd428d765ff4201ee..5688ca6140f17fcef94ed112481cddb06e75c668 100644 (file)
@@ -141,7 +141,8 @@ module RecordFilters
             end
             param_out << proppath
           when 'contains'
-            cond_out << "#{attr_table_name}.#{attr} @> ?::jsonb"
+            cond_out << "#{attr_table_name}.#{attr} @> ?::jsonb OR #{attr_table_name}.#{attr} @> ?::jsonb"
+            param_out << SafeJSON.dump({proppath => operand})
             param_out << SafeJSON.dump({proppath => [operand]})
           else
             raise ArgumentError.new("Invalid operator for subproperty search '#{operator}'")
index ff01de150f925b0188b94a307245d4d7123285c2..84c3559939123a6c12230ff375d5dfa62b956a12 100644 (file)
@@ -1002,6 +1002,21 @@ collection_with_list_prop_even:
   properties:
     listprop: [elem2, 4, elem6]
 
+collection_with_listprop_elem1:
+  uuid: zzzzz-4zz18-listpropelem1
+  current_version_uuid: zzzzz-4zz18-listpropelem1
+  portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
+  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  created_at: 2015-02-13T17:22:54Z
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-d9tiejq69daie8f
+  modified_at: 2015-02-13T17:22:54Z
+  updated_at: 2015-02-13T17:22:54Z
+  manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+  name: collection with list property with string value
+  properties:
+    listprop: elem1
+
 collection_with_uri_prop:
   uuid: zzzzz-4zz18-withuripropval1
   current_version_uuid: zzzzz-4zz18-withuripropval1
index 08ca71f60b9d67dafec09c98343884f5b3865dfc..2484127b21ccad59feccdbc13d6a3e45eb24b17a 100644 (file)
@@ -172,10 +172,10 @@ class Arvados::V1::FiltersTest < ActionController::TestCase
    ['prop2', '<=', 5, [:collection_with_prop2_1, :collection_with_prop2_5], []],
    ['prop2', '>=', 1, [:collection_with_prop2_1, :collection_with_prop2_5], []],
    ['<http://schema.org/example>', '=', "value1", [:collection_with_uri_prop], []],
-   ['listprop', 'contains', 'elem1', [:collection_with_list_prop_odd], [:collection_with_list_prop_even]],
-   ['listprop', 'contains', 5, [:collection_with_list_prop_odd], [:collection_with_list_prop_even]],
-   ['listprop', 'contains', 'elem2', [:collection_with_list_prop_even], [:collection_with_list_prop_odd]],
-   ['listprop', 'contains', 4, [:collection_with_list_prop_even], [:collection_with_list_prop_odd]],
+   ['listprop', 'contains', 'elem1', [:collection_with_list_prop_odd, :collection_with_listprop_elem1], [:collection_with_list_prop_even]],
+   ['listprop', 'contains', 5, [:collection_with_list_prop_odd], [:collection_with_list_prop_even, :collection_with_listprop_elem1]],
+   ['listprop', 'contains', 'elem2', [:collection_with_list_prop_even], [:collection_with_list_prop_odd, :collection_with_listprop_elem1]],
+   ['listprop', 'contains', 4, [:collection_with_list_prop_even], [:collection_with_list_prop_odd, :collection_with_listprop_elem1]],
   ].each do |prop, op, opr, inc, ex|
     test "jsonb filter properties.#{prop} #{op} #{opr})" do
       @controller = Arvados::V1::CollectionsController.new