[Groonga-commit] groonga/groonga at 32cf527 [master] Fix a bug that "&!" does nothing when right hand side is "true"

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Sep 2 18:14:40 JST 2015


Kouhei Sutou	2015-09-02 18:14:40 +0900 (Wed, 02 Sep 2015)

  New Revision: 32cf527915a5253e6d67e69413aeebd2700e19fa
  https://github.com/groonga/groonga/commit/32cf527915a5253e6d67e69413aeebd2700e19fa

  Message:
    Fix a bug that "&!" does nothing when right hand side is "true"
    
    "&!" assumed that right hand side is Int32 but it should assume that
    Bool.

  Added files:
    test/command/suite/select/filter/logical_operation/and_not.expected
    test/command/suite/select/filter/logical_operation/and_not.test
  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+7 -5)
===================================================================
--- lib/expr.c    2015-09-02 18:11:35 +0900 (abda6da)
+++ lib/expr.c    2015-09-02 18:14:40 +0900 (e3f3816)
@@ -2976,14 +2976,16 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs)
       case GRN_OP_AND_NOT :
         {
           grn_obj *x, *y;
+          grn_bool x_boolean, y_boolean;
           POP2ALLOC1(x, y, res);
-          if (GRN_INT32_VALUE(x) == 0 || GRN_INT32_VALUE(y) == 1) {
-            GRN_INT32_SET(ctx, res, 0);
+          GRN_TRUEP(ctx, x, x_boolean);
+          GRN_TRUEP(ctx, y, y_boolean);
+          grn_obj_reinit(ctx, res, GRN_DB_BOOL, 0);
+          if (!x_boolean || y_boolean) {
+            GRN_BOOL_SET(ctx, res, GRN_FALSE);
           } else {
-            GRN_INT32_SET(ctx, res, 1);
+            GRN_BOOL_SET(ctx, res, GRN_TRUE);
           }
-          res->header.type = GRN_BULK;
-          res->header.domain = GRN_DB_INT32;
         }
         code++;
         break;

  Added: test/command/suite/select/filter/logical_operation/and_not.expected (+44 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/logical_operation/and_not.expected    2015-09-02 18:14:40 +0900 (334c1a1)
@@ -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 'true &! (name == "Bob")'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        2
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "name",
+          "ShortText"
+        ]
+      ],
+      [
+        1,
+        "Alice"
+      ],
+      [
+        3,
+        "Calros"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/logical_operation/and_not.test (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/logical_operation/and_not.test    2015-09-02 18:14:40 +0900 (7fd20e0)
@@ -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 'true &! (name == "Bob")'
-------------- next part --------------
HTML����������������������������...
下載 



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