[Groonga-commit] groonga/groonga at 5b31dae [master] Support evaluating vector as boolean

Back to archive index

Kouhei Sutou null+****@clear*****
Mon May 20 18:58:32 JST 2013


Kouhei Sutou	2013-05-20 18:58:32 +0900 (Mon, 20 May 2013)

  New Revision: 5b31dae776377a1cac4b8c8647fb24a0fd584fc4
  https://github.com/groonga/groonga/commit/5b31dae776377a1cac4b8c8647fb24a0fd584fc4

  Message:
    Support evaluating vector as boolean
    
    Empty vector is evaluated as false. Otherwise the vector is evaluated
    as true.
    
    But is it OK? Empty array is evaluated as true in ECMAScript. Should
    groonga follow the behavior?

  Added files:
    test/command/suite/select/filter/vector/and.expected
    test/command/suite/select/filter/vector/and.test
  Modified files:
    lib/db.h

  Modified: lib/db.h (+3 -0)
===================================================================
--- lib/db.h    2013-05-20 18:50:15 +0900 (d77889c)
+++ lib/db.h    2013-05-20 18:58:32 +0900 (e9553c7)
@@ -392,6 +392,9 @@ grn_rc grn_db_obj_init(grn_ctx *ctx, grn_obj *db, grn_id id, grn_db_obj *obj);
       break;                                            \
     }                                                   \
     break;                                              \
+  case GRN_VECTOR :                                     \
+    result = grn_vector_size(ctx, v) > 0;               \
+    break;                                              \
   default :                                             \
     result = GRN_FALSE;                                 \
     break;                                              \

  Added: test/command/suite/select/filter/vector/and.expected (+46 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/vector/and.expected    2013-05-20 18:58:32 +0900 (0bbc4a3)
@@ -0,0 +1,46 @@
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos tags COLUMN_VECTOR ShortText
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "groonga is very fast", "tags": ["groonga"]},
+{"_key": "no tag"}
+]
+[[0,0.0,0.0],2]
+select Memos --filter 'tags && true'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "tags",
+          "ShortText"
+        ]
+      ],
+      [
+        1,
+        "groonga is very fast",
+        [
+          "groonga"
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/vector/and.test (+10 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/vector/and.test    2013-05-20 18:58:32 +0900 (8c8265a)
@@ -0,0 +1,10 @@
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos tags COLUMN_VECTOR ShortText
+
+load --table Memos
+[
+{"_key": "groonga is very fast", "tags": ["groonga"]},
+{"_key": "no tag"}
+]
+
+select Memos --filter 'tags && true'
-------------- next part --------------
HTML����������������������������...
Download 



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