[Groonga-commit] groonga/groonga at 6408ebb [master] between: support index search in slices

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Nov 11 15:49:43 JST 2016


Kouhei Sutou	2016-11-11 15:49:43 +0900 (Fri, 11 Nov 2016)

  New Revision: 6408ebb85011337dccd1f661c95036bc9f0d2dc1
  https://github.com/groonga/groonga/commit/6408ebb85011337dccd1f661c95036bc9f0d2dc1

  Message:
    between: support index search in slices

  Added files:
    test/command/suite/select/slices/filtered/selector/between.expected
    test/command/suite/select/slices/filtered/selector/between.test
  Modified files:
    lib/proc.c

  Modified: lib/proc.c (+71 -10)
===================================================================
--- lib/proc.c    2016-11-11 15:10:02 +0900 (e122ed2)
+++ lib/proc.c    2016-11-11 15:49:43 +0900 (74e22c1)
@@ -2461,9 +2461,13 @@ selector_between_sequential_search(grn_ctx *ctx,
 }
 
 static grn_rc
-selector_between(grn_ctx *ctx, grn_obj *table, grn_obj *index,
-                 int nargs, grn_obj **args,
-                 grn_obj *res, grn_operator op)
+selector_between_no_accessor(grn_ctx *ctx,
+                             grn_obj *table,
+                             grn_obj *index,
+                             int nargs,
+                             grn_obj **args,
+                             grn_obj *res,
+                             grn_operator op)
 {
   grn_rc rc = GRN_SUCCESS;
   int offset = 0;
@@ -2489,11 +2493,7 @@ selector_between(grn_ctx *ctx, grn_obj *table, grn_obj *index,
   }
 
   if (index) {
-    if (index->header.type == GRN_ACCESSOR) {
-      /* TODO */
-    } else {
-      index_table = grn_ctx_at(ctx, index->header.domain);
-    }
+    index_table = grn_ctx_at(ctx, index->header.domain);
   }
 
   if (index_table) {
@@ -2534,8 +2534,69 @@ selector_between(grn_ctx *ctx, grn_obj *table, grn_obj *index,
 
 exit :
   between_data_fin(ctx, &data);
-  if (index_table) {
-    grn_obj_unlink(ctx, index_table);
+
+  return rc;
+}
+
+static grn_rc
+selector_between(grn_ctx *ctx,
+                 grn_obj *table,
+                 grn_obj *index,
+                 int nargs,
+                 grn_obj **args,
+                 grn_obj *res,
+                 grn_operator op)
+{
+  grn_rc rc = GRN_SUCCESS;
+
+  if (index && index->header.type == GRN_ACCESSOR) {
+    grn_obj *accessor = index;
+    unsigned int accessor_deep = 0;
+    grn_obj *base_table = NULL;
+    grn_obj *base_index = NULL;
+    grn_obj *base_res = NULL;
+    grn_accessor *a;
+
+    for (a = (grn_accessor *)accessor; a; a = a->next) {
+      if (a->next) {
+        accessor_deep++;
+      } else {
+        grn_index_datum index_data;
+        unsigned int n_index_datum;
+
+        base_table = grn_ctx_at(ctx, a->obj->header.domain);
+        n_index_datum = grn_column_find_index_data(ctx,
+                                                   a->obj,
+                                                   GRN_OP_LESS,
+                                                   &index_data,
+                                                   1);
+        if (n_index_datum > 0) {
+          base_index = index_data.index;
+        }
+        base_res = grn_table_create(ctx, NULL, 0, NULL,
+                                    GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC,
+                                    base_table, NULL);
+      }
+    }
+    rc = selector_between_no_accessor(ctx,
+                                      base_table,
+                                      base_index,
+                                      nargs,
+                                      args,
+                                      base_res,
+                                      GRN_OP_OR);
+    if (rc == GRN_SUCCESS) {
+      grn_accessor_resolve(ctx, accessor, accessor_deep, base_res, res, op);
+    }
+    grn_obj_close(ctx, base_res);
+  } else {
+    rc = selector_between_no_accessor(ctx,
+                                      table,
+                                      index,
+                                      nargs,
+                                      args,
+                                      res,
+                                      op);
   }
 
   return rc;

  Added: test/command/suite/select/slices/filtered/selector/between.expected (+95 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/slices/filtered/selector/between.expected    2016-11-11 15:49:43 +0900 (381f1c5)
@@ -0,0 +1,95 @@
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos date COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create Times TABLE_PAT_KEY Time
+[[0,0.0,0.0],true]
+column_create Times memos_date COLUMN_INDEX Memos date
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga is fast!", "date": "2016-05-19 12:00:00"},
+{"_key": "Mroonga is fast!", "date": "2016-05-19 12:00:01"},
+{"_key": "Groonga sticker!", "date": "2016-05-19 12:00:02"},
+{"_key": "Rroonga is fast!", "date": "2016-05-19 12:00:03"}
+]
+[[0,0.0,0.0],4]
+log_level --level info
+[[0,0.0,0.0],true]
+select Memos   --filter '_id > 1'   --slices[groonga].filter 'between(date,                                     "2016-05-19 12:00:00", "include",                                     "2016-05-19 12:00:03", "exclude")'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "date",
+          "Time"
+        ]
+      ],
+      [
+        2,
+        "Mroonga is fast!",
+        1463626801.0
+      ],
+      [
+        3,
+        "Groonga sticker!",
+        1463626802.0
+      ],
+      [
+        4,
+        "Rroonga is fast!",
+        1463626803.0
+      ]
+    ],
+    {
+      "groonga": [
+        [
+          2
+        ],
+        [
+          [
+            "_id",
+            "UInt32"
+          ],
+          [
+            "_key",
+            "ShortText"
+          ],
+          [
+            "date",
+            "Time"
+          ]
+        ],
+        [
+          2,
+          "Mroonga is fast!",
+          1463626801.0
+        ],
+        [
+          3,
+          "Groonga sticker!",
+          1463626802.0
+        ]
+      ]
+    }
+  ]
+]
+#|i| [table][select][index][selector][between] <>
+#|i| [accessor][resolve][table] (temporary) -> <Memos> -> <ShortText>

  Added: test/command/suite/select/slices/filtered/selector/between.test (+21 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/slices/filtered/selector/between.test    2016-11-11 15:49:43 +0900 (f3a9c43)
@@ -0,0 +1,21 @@
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos date COLUMN_SCALAR Time
+
+table_create Times TABLE_PAT_KEY Time
+column_create Times memos_date COLUMN_INDEX Memos date
+
+load --table Memos
+[
+{"_key": "Groonga is fast!", "date": "2016-05-19 12:00:00"},
+{"_key": "Mroonga is fast!", "date": "2016-05-19 12:00:01"},
+{"_key": "Groonga sticker!", "date": "2016-05-19 12:00:02"},
+{"_key": "Rroonga is fast!", "date": "2016-05-19 12:00:03"}
+]
+
+log_level --level info
+#@add-important-log-levels info
+select Memos \
+  --filter '_id > 1' \
+  --slices[groonga].filter 'between(date, \
+                                    "2016-05-19 12:00:00", "include", \
+                                    "2016-05-19 12:00:03", "exclude")'
-------------- next part --------------
HTML����������������������������...
Download 



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