[ARVADOS] updated: 1.1.1-213-g40d5d40

Git user git at public.curoverse.com
Mon Dec 11 16:34:18 EST 2017


Summary of changes:
 services/api/lib/record_filters.rb                 |  23 +++-
 services/api/test/fixtures/collections.yml         |  28 ++++
 .../api/test/functional/arvados/v1/filters_test.rb | 144 +++++++--------------
 3 files changed, 90 insertions(+), 105 deletions(-)

       via  40d5d40955a88dbd5cd7c25292268f1ab4536bda (commit)
      from  667a7121e08d4fffc24cafdc3ed474374782b959 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 40d5d40955a88dbd5cd7c25292268f1ab4536bda
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Mon Dec 11 16:33:12 2017 -0500

    4019: Expand testing.  Make behavior consistent for != and "not in"
    
    Rename "?" to "exists" and add "not exists".
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz at veritasgenetics.com>

diff --git a/services/api/lib/record_filters.rb b/services/api/lib/record_filters.rb
index ce9fe6b..9ff21d5 100644
--- a/services/api/lib/record_filters.rb
+++ b/services/api/lib/record_filters.rb
@@ -84,27 +84,33 @@ module RecordFilters
               raise ArgumentError.new("Invalid operand type '#{operand.class}' "\
                                       "for '#{operator}' operator in filters")
             end
-          # when '<', '<=', '>', '>='
-          #   cond_out << "#{ar_table_name}.#{subproperty[0]}->? #{operator} ?::jsonb"
-          #   param_out << subproperty[1]
-          #   param_out << SafeJSON.dump(operand)
+          when '<', '<=', '>', '>='
+            cond_out << "#{ar_table_name}.#{subproperty[0]}->? #{operator} ?::jsonb"
+            param_out << subproperty[1]
+            param_out << SafeJSON.dump(operand)
           when 'like', 'ilike'
             cond_out << "#{ar_table_name}.#{subproperty[0]}->>? #{operator} ?"
+            param_out << subproperty[1]
             param_out << operand
           when 'not in'
             if operand.is_a? Array
-              cond_out << "#{ar_table_name}.#{subproperty[0]}->>? NOT IN (?)"
+              cond_out << "#{ar_table_name}.#{subproperty[0]}->>? NOT IN (?) OR #{ar_table_name}.#{subproperty[0]}->>? IS NULL"
               param_out << subproperty[1]
               param_out << operand
+              param_out << subproperty[1]
             else
               raise ArgumentError.new("Invalid operand type '#{operand.class}' "\
                                       "for '#{operator}' operator in filters")
             end
-          when '?'
+          when 'exists', 'not exists'
           if operand
             raise ArgumentError.new("Invalid operand for subproperty existence filter, should be empty or null")
           end
-          cond_out << "jsonb_exists(#{ar_table_name}.#{subproperty[0]}, ?)"
+          if operator.downcase[0..2] == "not" then
+            cond_out << "(NOT jsonb_exists(#{ar_table_name}.#{subproperty[0]}, ?)) OR #{ar_table_name}.#{subproperty[0]} is NULL"
+          else
+            cond_out << "jsonb_exists(#{ar_table_name}.#{subproperty[0]}, ?)"
+          end
           param_out << subproperty[1]
           else
             raise ArgumentError.new("Invalid operator for subproperty search '#{operator}'")
@@ -150,6 +156,9 @@ module RecordFilters
                  [true, false].include?(operand)
               cond_out << "#{ar_table_name}.#{attr} #{operator} ?"
               param_out << operand
+            elsif (attr_type == :integer)
+              cond_out << "#{ar_table_name}.#{attr} #{operator} ?"
+              param_out << operand
             else
               raise ArgumentError.new("Invalid operand type '#{operand.class}' "\
                                       "for '#{operator}' operator in filters")
diff --git a/services/api/test/fixtures/collections.yml b/services/api/test/fixtures/collections.yml
index b265f24..871a357 100644
--- a/services/api/test/fixtures/collections.yml
+++ b/services/api/test/fixtures/collections.yml
@@ -743,6 +743,34 @@ collection_with_prop1_value2:
   properties:
     prop1: value2
 
+collection_with_prop1_value3:
+  uuid: zzzzz-4zz18-withprop1value3
+  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 prop1 value3
+  properties:
+    prop1: value3
+
+collection_with_prop1_other1:
+  uuid: zzzzz-4zz18-withprop1other1
+  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 prop1 other1
+  properties:
+    prop1: other1
+
 collection_with_prop2_1:
   uuid: zzzzz-4zz18-withprop2value1
   portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
diff --git a/services/api/test/functional/arvados/v1/filters_test.rb b/services/api/test/functional/arvados/v1/filters_test.rb
index 61b9e78..6b4ea2a 100644
--- a/services/api/test/functional/arvados/v1/filters_test.rb
+++ b/services/api/test/functional/arvados/v1/filters_test.rb
@@ -152,123 +152,71 @@ class Arvados::V1::FiltersTest < ActionController::TestCase
     assert_equal true, second_page['arvados#pipelineTemplate']>0
   end
 
-  test "jsonb '=' filter" do
-    @controller = Arvados::V1::CollectionsController.new
-    authorize_with :admin
-    get :index, {
-      filters: [ ['properties.prop1', '=', 'value1'] ]
-    }
-    assert_response :success
-    found = assigns(:objects).collect(&:uuid)
-    assert_equal(found, [collections(:collection_with_prop1_value1).uuid])
-  end
-
-  test "jsonb '!=' filter" do
-    @controller = Arvados::V1::CollectionsController.new
-    authorize_with :admin
-    get :index, {
-      filters: [ ['properties.prop1', '!=', 'value1'] ]
-    }
-    assert_response :success
-    found = assigns(:objects).collect(&:uuid)
-    assert_operator found.length, :>, 1
-    assert_includes(found, collections(:collection_with_prop1_value2).uuid)
-  end
-
-  test "jsonb '?'" do
-    @controller = Arvados::V1::CollectionsController.new
-    authorize_with :admin
-    get :index, {
-      filters: [ ['properties.prop1', '?', nil] ]
-    }
-    assert_response :success
-    found = assigns(:objects).collect(&:uuid)
-    assert_equal found.length, 2
-    assert_includes(found, collections(:collection_with_prop1_value1).uuid)
-    assert_includes(found, collections(:collection_with_prop1_value2).uuid)
-  end
-
-  test "jsonb '?' and '!=' filter" do
-    @controller = Arvados::V1::CollectionsController.new
-    authorize_with :admin
-    get :index, {
-      filters: [ ['properties.prop1', '?', nil], ['properties.prop1', '!=', 'value1'] ]
-    }
-    assert_response :success
-    found = assigns(:objects).collect(&:uuid)
-    assert_equal(found, [collections(:collection_with_prop1_value2).uuid])
-  end
+  [['prop1', '=', 'value1', [:collection_with_prop1_value1], [:collection_with_prop1_value2, :collection_with_prop2_1]],
+   ['prop1', '!=', 'value1', [:collection_with_prop1_value2, :collection_with_prop2_1], [:collection_with_prop1_value1]],
+   ['prop1', 'exists', nil, [:collection_with_prop1_value1, :collection_with_prop1_value2, :collection_with_prop1_value3, :collection_with_prop1_other1], [:collection_with_prop2_1]],
+   ['prop1', 'not exists', nil, [:collection_with_prop2_1], [:collection_with_prop1_value1, :collection_with_prop1_value2, :collection_with_prop1_value3, :collection_with_prop1_other1]],
+   ['prop1', 'in', ['value1', 'value2'], [:collection_with_prop1_value1, :collection_with_prop1_value2], [:collection_with_prop1_value3, :collection_with_prop2_1]],
+   ['prop1', 'in', ['value1', 'valueX'], [:collection_with_prop1_value1], [:collection_with_prop1_value3, :collection_with_prop2_1]],
+   ['prop1', 'not in', ['value1', 'value2'], [:collection_with_prop1_value3, :collection_with_prop1_other1, :collection_with_prop2_1], [:collection_with_prop1_value1, :collection_with_prop1_value2]],
+   ['prop1', 'not in', ['value1', 'valueX'], [:collection_with_prop1_value2, :collection_with_prop1_value3, :collection_with_prop1_other1, :collection_with_prop2_1], [:collection_with_prop1_value1]],
+   ['prop1', '>', 'value2', [:collection_with_prop1_value3], [:collection_with_prop1_other1, :collection_with_prop1_value1]],
+   ['prop1', '<', 'value2', [:collection_with_prop1_other1, :collection_with_prop1_value1], [:collection_with_prop1_value2, :collection_with_prop1_value2]],
+   ['prop1', '<=', 'value2', [:collection_with_prop1_other1, :collection_with_prop1_value1, :collection_with_prop1_value2], [:collection_with_prop1_value3]],
+   ['prop1', '>=', 'value2', [:collection_with_prop1_value2, :collection_with_prop1_value3], [:collection_with_prop1_other1, :collection_with_prop1_value1]],
+   ['prop1', 'like', 'value%', [:collection_with_prop1_value1, :collection_with_prop1_value2, :collection_with_prop1_value3], [:collection_with_prop1_other1]],
+   ['prop1', 'like', '%1', [:collection_with_prop1_value1, :collection_with_prop1_other1], [:collection_with_prop1_value2, :collection_with_prop1_value3]],
+   ['prop1', 'ilike', 'VALUE%', [:collection_with_prop1_value1, :collection_with_prop1_value2, :collection_with_prop1_value3], [:collection_with_prop1_other1]],
+   ['prop2', '>',  1, [:collection_with_prop2_5], [:collection_with_prop2_1]],
+   ['prop2', '<',  5, [:collection_with_prop2_1], [:collection_with_prop2_5]],
+   ['prop2', '<=', 5, [:collection_with_prop2_1, :collection_with_prop2_5], []],
+   ['prop2', '>=', 1, [:collection_with_prop2_1, :collection_with_prop2_5], []]
+  ].each do |prop, op, opr, inc, ex|
+    test "jsonb filter properties.#{prop} #{op} #{opr})" do
+      @controller = Arvados::V1::CollectionsController.new
+      authorize_with :admin
+      get :index, {
+            filters: SafeJSON.dump([ ["properties.#{prop}", op, opr] ]),
+            limit: 1000
+          }
+      assert_response :success
+      found = assigns(:objects).collect(&:uuid)
 
-  test "jsonb 'in' filter (match all)" do
-    @controller = Arvados::V1::CollectionsController.new
-    authorize_with :admin
-    get :index, {
-      filters: [ ['properties.prop1', 'in', ['value1', 'value2']] ]
-    }
-    assert_response :success
-    found = assigns(:objects).collect(&:uuid)
-    assert_equal found.length, 2
-    assert_includes(found, collections(:collection_with_prop1_value1).uuid)
-    assert_includes(found, collections(:collection_with_prop1_value2).uuid)
-  end
+      inc.each do |i|
+        assert_includes(found, collections(i).uuid)
+      end
 
-  test "jsonb 'in' filter (match some)" do
-    @controller = Arvados::V1::CollectionsController.new
-    authorize_with :admin
-    get :index, {
-      filters: [ ['properties.prop1', 'in', ['value1', 'value3']] ]
-    }
-    assert_response :success
-    found = assigns(:objects).collect(&:uuid)
-    assert_equal(found, [collections(:collection_with_prop1_value1).uuid])
+      ex.each do |e|
+        assert_not_includes(found, collections(e).uuid)
+      end
+    end
   end
 
-  test "jsonb 'not in' filter (match all)" do
+  test "jsonb 'exists' and '!=' filter" do
     @controller = Arvados::V1::CollectionsController.new
     authorize_with :admin
     get :index, {
-      filters: [ ['properties.prop1', 'not in', ['value1', 'value2']] ]
+      filters: [ ['properties.prop1', 'exists', nil], ['properties.prop1', '!=', 'value1'] ]
     }
     assert_response :success
     found = assigns(:objects).collect(&:uuid)
+    assert_equal found.length, 3
     assert_not_includes(found, collections(:collection_with_prop1_value1).uuid)
-    assert_not_includes(found, collections(:collection_with_prop1_value2).uuid)
+    assert_includes(found, collections(:collection_with_prop1_value2).uuid)
+    assert_includes(found, collections(:collection_with_prop1_value3).uuid)
+    assert_includes(found, collections(:collection_with_prop1_other1).uuid)
   end
 
-  test "jsonb 'not in' filter (match some)" do
+  test "replication_desired = 2" do
     @controller = Arvados::V1::CollectionsController.new
     authorize_with :admin
     get :index, {
-      filters: [ ['properties.prop1', 'not in', ['value1', 'value3']] ]
+      filters: SafeJSON.dump([ ['replication_desired', '=', 2] ])
     }
     assert_response :success
     found = assigns(:objects).collect(&:uuid)
-    assert_not_includes(found, collections(:collection_with_prop1_value1).uuid)
-    assert_includes(found, collections(:collection_with_prop1_value2).uuid)
+    assert_includes(found, collections(:replication_desired_2_unconfirmed).uuid)
+    assert_includes(found, collections(:replication_desired_2_confirmed_2).uuid)
   end
 
-  # test "jsonb '>' filter (>3)" do
-  #   @controller = Arvados::V1::CollectionsController.new
-  #   authorize_with :admin
-  #   get :index, {
-  #     filters: [ ['properties.prop2', '>', 3] ]
-  #   }
-  #   assert_response :success
-  #   found = assigns(:objects).collect(&:uuid)
-  #   assert_not_includes(found, collections(:collection_with_prop2_1).uuid)
-  #   assert_includes(found, collections(:collection_with_prop2_5).uuid)
-  # end
-
-  # test "jsonb '>' filter (>'value1')" do
-  #   @controller = Arvados::V1::CollectionsController.new
-  #   authorize_with :admin
-  #   get :index, {
-  #     filters: [ ['properties.prop1', '>', "value1"] ]
-  #   }
-  #   assert_response :success
-  #   found = assigns(:objects).collect(&:uuid)
-  #   assert_not_includes(found, collections(:collection_with_prop1_value1).uuid)
-  #   assert_includes(found, collections(:collection_with_prop1_value2).uuid)
-  # end
-
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list