[Groonga-commit] groonga/groonga [master] Support logical not ("!")

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 23日 (月) 13:19:23 JST


Kouhei Sutou	2012-07-23 13:19:23 +0900 (Mon, 23 Jul 2012)

  New Revision: 198769368a732cacd6cc05d441bd0532ed7aeac4
  https://github.com/groonga/groonga/commit/198769368a732cacd6cc05d441bd0532ed7aeac4

  Merged d428fce: Merge pull request #22 from groonga/support-logical-not

  Log:
    Support logical not ("!")
    
    --filter '!(_key == "Alice")' is avialable but index isn't used.

  Added files:
    test/function/suite/select/filter/logical_operation/not.expected
    test/function/suite/select/filter/logical_operation/not.test
  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+15 -0)
===================================================================
--- lib/expr.c    2012-07-23 11:34:30 +0900 (bc24c8d)
+++ lib/expr.c    2012-07-23 13:19:23 +0900 (e01ac32)
@@ -999,6 +999,11 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op,
       }
       DFI_PUT(e, type, domain, code);
       break;
+    case GRN_OP_NOT :
+      if (nargs == 1) {
+        PUSH_CODE(e, op, obj, nargs, code);
+      }
+      break;
     case GRN_OP_PLUS :
       if (nargs > 1) {
         PUSH_N_ARGS_ARITHMETIC_OP(e, op, obj, nargs, code);
@@ -3336,6 +3341,16 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs)
       case GRN_OP_DECR_POST :
         UNARY_OPERATE_AND_ASSIGN_DISPATCH(EXEC_OPERATE_POST, 1, GRN_OBJ_DECR);
         break;
+      case GRN_OP_NOT :
+        {
+          grn_obj *value;
+          POP1ALLOC1(value, res);
+          grn_obj_reinit(ctx, res, GRN_DB_BOOL, 0);
+          grn_obj_cast(ctx, value, res, GRN_FALSE);
+          GRN_BOOL_SET(ctx, res, !GRN_BOOL_VALUE(res));
+        }
+        code++;
+        break;
       default :
         ERR(GRN_FUNCTION_NOT_IMPLEMENTED, "not implemented operator assigned");
         goto exit;

  Added: test/function/suite/select/filter/logical_operation/not.expected (+44 -0) 100644
===================================================================
--- /dev/null
+++ test/function/suite/select/filter/logical_operation/not.expected    2012-07-23 13:19:23 +0900 (7174c55)
@@ -0,0 +1,44 @@
+table_create Users TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Users name COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Users
+[
+{"name": "Alice"},
+{"name": "Bob"},
+{"name": "Calros"}
+]
+[[0,0.0,0.0],3]
+select Users --filter '!(name == "Alice")'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        2
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "name",
+          "ShortText"
+        ]
+      ],
+      [
+        2,
+        "Bob"
+      ],
+      [
+        3,
+        "Calros"
+      ]
+    ]
+  ]
+]

  Added: test/function/suite/select/filter/logical_operation/not.test (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/function/suite/select/filter/logical_operation/not.test    2012-07-23 13:19:23 +0900 (17a97b4)
@@ -0,0 +1,11 @@
+table_create Users TABLE_NO_KEY
+column_create Users name COLUMN_SCALAR ShortText
+
+load --table Users
+[
+{"name": "Alice"},
+{"name": "Bob"},
+{"name": "Calros"}
+]
+
+select Users --filter '!(name == "Alice")'
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
下载 



Groonga-commit メーリングリストの案内
Back to archive index