[Groonga-commit] groonga/groonga at aa1bb33 [master] Support searching "!(XXX > VALUE)" by index

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Feb 14 20:40:26 JST 2017


Kouhei Sutou	2017-02-14 20:40:26 +0900 (Tue, 14 Feb 2017)

  New Revision: aa1bb33b24c72e10f533ea891a220607421aa34b
  https://github.com/groonga/groonga/commit/aa1bb33b24c72e10f533ea891a220607421aa34b

  Message:
    Support searching "!(XXX > VALUE)" by index
    
    Not only ">" but also ">=", "<", "<=", "==", "!=" are supported.

  Added files:
    test/command/suite/select/filter/unary_operation/not_equal.expected
    test/command/suite/select/filter/unary_operation/not_equal.test
    test/command/suite/select/filter/unary_operation/not_greater.expected
    test/command/suite/select/filter/unary_operation/not_greater.test
    test/command/suite/select/filter/unary_operation/not_greater_equal.expected
    test/command/suite/select/filter/unary_operation/not_greater_equal.test
    test/command/suite/select/filter/unary_operation/not_less.expected
    test/command/suite/select/filter/unary_operation/not_less.test
    test/command/suite/select/filter/unary_operation/not_less_equal.expected
    test/command/suite/select/filter/unary_operation/not_less_equal.test
    test/command/suite/select/filter/unary_operation/not_not_equal.expected
    test/command/suite/select/filter/unary_operation/not_not_equal.test
  Modified files:
    lib/expr.c
    lib/mrb/scripts/scan_info_builder.rb
    test/mruby/suite/query_optimizer/index/test_match.rb

  Modified: lib/expr.c (+41 -1)
===================================================================
--- lib/expr.c    2017-02-14 20:07:11 +0900 (25dae91)
+++ lib/expr.c    2017-02-14 20:40:26 +0900 (f612215)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
-  Copyright(C) 2010-2016 Brazil
+  Copyright(C) 2010-2017 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -4685,6 +4685,8 @@ grn_scan_info_build_full(grn_ctx *ctx, grn_obj *expr, int *n,
         break;
       }
       break;
+    case GRN_OP_NOT :
+      break;
     default :
       return NULL;
       break;
@@ -4884,6 +4886,44 @@ grn_scan_info_build_full(grn_ctx *ctx, grn_obj *expr, int *n,
       }
       stat = SCAN_COL1;
       break;
+    case GRN_OP_NOT :
+      if (i == 0) {
+        return NULL;
+      }
+      {
+        scan_info *last_si = sis[i - 1];
+        switch (last_si->op) {
+        case GRN_OP_LESS :
+          last_si->op = GRN_OP_GREATER_EQUAL;
+          break;
+        case GRN_OP_LESS_EQUAL :
+          last_si->op = GRN_OP_GREATER;
+          break;
+        case GRN_OP_GREATER :
+          last_si->op = GRN_OP_LESS_EQUAL;
+          break;
+        case GRN_OP_GREATER_EQUAL :
+          last_si->op = GRN_OP_LESS;
+          break;
+        case GRN_OP_EQUAL :
+          last_si->op = GRN_OP_NOT_EQUAL;
+          break;
+        case GRN_OP_NOT_EQUAL :
+          last_si->op = GRN_OP_EQUAL;
+          break;
+        default :
+          {
+            int j;
+            for (j = 0; j < i; j++) {
+              SI_FREE(sis[j]);
+            }
+            GRN_FREE(sis);
+          }
+          return NULL;
+        }
+        last_si->end++;
+      }
+      break;
     default :
       break;
     }

  Modified: lib/mrb/scripts/scan_info_builder.rb (+22 -0)
===================================================================
--- lib/mrb/scripts/scan_info_builder.rb    2017-02-14 20:07:11 +0900 (2e21f9f)
+++ lib/mrb/scripts/scan_info_builder.rb    2017-02-14 20:40:26 +0900 (f58bfa2)
@@ -144,6 +144,26 @@ module Groonga
           index = data.args.pop
           data.start_position = index.value
           status = Status::COL1
+        when Operator::NOT
+          last_data = @data_list.last
+          return nil if last_data.nil?
+          case last_data.op
+          when Operator::LESS
+            last_data.op = Operator::GREATER_EQUAL
+          when Operator::LESS_EQUAL
+            last_data.op = Operator::GREATER
+          when Operator::GREATER
+            last_data.op = Operator::LESS_EQUAL
+          when Operator::GREATER_EQUAL
+            last_data.op = Operator::LESS
+          when Operator::EQUAL
+            last_data.op = Operator::NOT_EQUAL
+          when Operator::NOT_EQUAL
+            last_data.op = Operator::EQUAL
+          else
+            return nil
+          end
+          last_data.end += 1
         end
       end
 
@@ -241,6 +261,8 @@ module Groonga
           else
             return false
           end
+        when Operator::NOT
+          # Do nothing
         else
           return false
         end

  Added: test/command/suite/select/filter/unary_operation/not_equal.expected (+15 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_equal.expected    2017-02-14 20:40:26 +0900 (891e677)
@@ -0,0 +1,15 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+[[0,0.0,0.0],true]
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+[[0,0.0,0.0],3]
+log_level --level info
+[[0,0.0,0.0],true]
+select Numbers --filter '!(_key == 29)'
+[[0,0.0,0.0],[[[2],[["_id","UInt32"],["_key","UInt32"]],[1,2],[3,2929]]]]
+log_level --level notice
+[[0,0.0,0.0],true]

  Added: test/command/suite/select/filter/unary_operation/not_equal.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_equal.test    2017-02-14 20:40:26 +0900 (c28df48)
@@ -0,0 +1,14 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+
+log_level --level info
+#@add-important-log-levels info
+select Numbers --filter '!(_key == 29)'
+#@remove-important-log-levels info
+log_level --level notice

  Added: test/command/suite/select/filter/unary_operation/not_greater.expected (+16 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_greater.expected    2017-02-14 20:40:26 +0900 (1413000)
@@ -0,0 +1,16 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+[[0,0.0,0.0],true]
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+[[0,0.0,0.0],3]
+log_level --level info
+[[0,0.0,0.0],true]
+select Numbers --filter '!(_key > 29)'
+[[0,0.0,0.0],[[[2],[["_id","UInt32"],["_key","UInt32"]],[1,2],[2,29]]]]
+#|i| [table][select][index][range][key] <Numbers>
+log_level --level notice
+[[0,0.0,0.0],true]

  Added: test/command/suite/select/filter/unary_operation/not_greater.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_greater.test    2017-02-14 20:40:26 +0900 (11d1b5b)
@@ -0,0 +1,14 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+
+log_level --level info
+#@add-important-log-levels info
+select Numbers --filter '!(_key > 29)'
+#@remove-important-log-levels info
+log_level --level notice

  Added: test/command/suite/select/filter/unary_operation/not_greater_equal.expected (+16 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_greater_equal.expected    2017-02-14 20:40:26 +0900 (d16bd16)
@@ -0,0 +1,16 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+[[0,0.0,0.0],true]
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+[[0,0.0,0.0],3]
+log_level --level info
+[[0,0.0,0.0],true]
+select Numbers --filter '!(_key >= 29)'
+[[0,0.0,0.0],[[[1],[["_id","UInt32"],["_key","UInt32"]],[1,2]]]]
+#|i| [table][select][index][range][key] <Numbers>
+log_level --level notice
+[[0,0.0,0.0],true]

  Added: test/command/suite/select/filter/unary_operation/not_greater_equal.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_greater_equal.test    2017-02-14 20:40:26 +0900 (5ed6ee5)
@@ -0,0 +1,14 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+
+log_level --level info
+#@add-important-log-levels info
+select Numbers --filter '!(_key >= 29)'
+#@remove-important-log-levels info
+log_level --level notice

  Added: test/command/suite/select/filter/unary_operation/not_less.expected (+16 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_less.expected    2017-02-14 20:40:26 +0900 (fd9c07f)
@@ -0,0 +1,16 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+[[0,0.0,0.0],true]
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+[[0,0.0,0.0],3]
+log_level --level info
+[[0,0.0,0.0],true]
+select Numbers --filter '!(_key < 29)'
+[[0,0.0,0.0],[[[2],[["_id","UInt32"],["_key","UInt32"]],[2,29],[3,2929]]]]
+#|i| [table][select][index][range][key] <Numbers>
+log_level --level notice
+[[0,0.0,0.0],true]

  Added: test/command/suite/select/filter/unary_operation/not_less.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_less.test    2017-02-14 20:40:26 +0900 (e5513f9)
@@ -0,0 +1,14 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+
+log_level --level info
+#@add-important-log-levels info
+select Numbers --filter '!(_key < 29)'
+#@remove-important-log-levels info
+log_level --level notice

  Added: test/command/suite/select/filter/unary_operation/not_less_equal.expected (+16 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_less_equal.expected    2017-02-14 20:40:26 +0900 (6355af9)
@@ -0,0 +1,16 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+[[0,0.0,0.0],true]
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+[[0,0.0,0.0],3]
+log_level --level info
+[[0,0.0,0.0],true]
+select Numbers --filter '!(_key <= 29)'
+[[0,0.0,0.0],[[[1],[["_id","UInt32"],["_key","UInt32"]],[3,2929]]]]
+#|i| [table][select][index][range][key] <Numbers>
+log_level --level notice
+[[0,0.0,0.0],true]

  Added: test/command/suite/select/filter/unary_operation/not_less_equal.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_less_equal.test    2017-02-14 20:40:26 +0900 (69b1fcc)
@@ -0,0 +1,14 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+
+log_level --level info
+#@add-important-log-levels info
+select Numbers --filter '!(_key <= 29)'
+#@remove-important-log-levels info
+log_level --level notice

  Added: test/command/suite/select/filter/unary_operation/not_not_equal.expected (+16 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_not_equal.expected    2017-02-14 20:40:26 +0900 (031a5ab)
@@ -0,0 +1,16 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+[[0,0.0,0.0],true]
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+[[0,0.0,0.0],3]
+log_level --level info
+[[0,0.0,0.0],true]
+select Numbers --filter '!(_key != 29)'
+[[0,0.0,0.0],[[[1],[["_id","UInt32"],["_key","UInt32"]],[2,29]]]]
+#|i| [table][select][index][equal][accessor][key] <Numbers>
+log_level --level notice
+[[0,0.0,0.0],true]

  Added: test/command/suite/select/filter/unary_operation/not_not_equal.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/unary_operation/not_not_equal.test    2017-02-14 20:40:26 +0900 (2290d42)
@@ -0,0 +1,14 @@
+table_create Numbers TABLE_PAT_KEY UInt32
+
+load --table Numbers
+[
+{"_key": 2},
+{"_key": 29},
+{"_key": 2929}
+]
+
+log_level --level info
+#@add-important-log-levels info
+select Numbers --filter '!(_key != 29)'
+#@remove-important-log-levels info
+log_level --level notice

  Modified: test/mruby/suite/query_optimizer/index/test_match.rb (+1 -1)
===================================================================
--- test/mruby/suite/query_optimizer/index/test_match.rb    2017-02-14 20:07:11 +0900 (7a304bc)
+++ test/mruby/suite/query_optimizer/index/test_match.rb    2017-02-14 20:40:26 +0900 (9551f72)
@@ -1,4 +1,4 @@
-class TestIndex < QueryOptimizerTestCase
+class TestMatch < QueryOptimizerTestCase
   def setup
     Groonga::Schema.define do |schema|
       schema.create_table("Logs") do |table|
-------------- next part --------------
HTML����������������������������...
Descargar 



More information about the Groonga-commit mailing list
Back to archive index