[Groonga-commit] groonga/groonga at 3fd04c3 [master] between(): support _key as target

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Nov 16 15:59:59 JST 2016


Kouhei Sutou	2016-11-16 15:59:59 +0900 (Wed, 16 Nov 2016)

  New Revision: 3fd04c3bc22421586fa0a8f70a7d78593e65c8cb
  https://github.com/groonga/groonga/commit/3fd04c3bc22421586fa0a8f70a7d78593e65c8cb

  Message:
    between(): support _key as target

  Added files:
    test/command/suite/select/function/between/with_index/key.expected
    test/command/suite/select/function/between/with_index/key.test
    test/command/suite/select/slices/filtered/selector/sub_filter/between_key.expected
    test/command/suite/select/slices/filtered/selector/sub_filter/between_key.test
  Modified files:
    lib/proc.c

  Modified: lib/proc.c (+30 -3)
===================================================================
--- lib/proc.c    2016-11-11 17:52:38 +0900 (6ea095a)
+++ lib/proc.c    2016-11-16 15:59:59 +0900 (975da04)
@@ -2264,6 +2264,10 @@ selector_between_sequential_search_should_use(grn_ctx *ctx,
     return GRN_FALSE;
   }
 
+  if (!index) {
+    return GRN_FALSE;
+  }
+
   if (index->header.flags & GRN_OBJ_WITH_WEIGHT) {
     return GRN_FALSE;
   }
@@ -2493,7 +2497,19 @@ selector_between(grn_ctx *ctx,
   }
 
   if (index) {
-    index_table = grn_ctx_at(ctx, index->header.domain);
+    switch (index->header.type) {
+    case GRN_TABLE_NO_KEY :
+    case GRN_TABLE_HASH_KEY :
+      break;
+    case GRN_TABLE_PAT_KEY :
+    case GRN_TABLE_DAT_KEY :
+      index_table = index;
+      index = NULL;
+      break;
+    default :
+      index_table = grn_ctx_at(ctx, index->header.domain);
+      break;
+    }
   }
 
   if (index_table) {
@@ -2526,8 +2542,19 @@ selector_between(grn_ctx *ctx,
     goto exit;
   }
 
-  while ((id = grn_table_cursor_next(ctx, cursor))) {
-    grn_ii_at(ctx, (grn_ii *)index, id, (grn_hash *)res, op);
+  if (index) {
+    while ((id = grn_table_cursor_next(ctx, cursor))) {
+      grn_ii_at(ctx, (grn_ii *)index, id, (grn_hash *)res, op);
+    }
+  } else {
+    grn_posting posting;
+    memset(&posting, 0, sizeof(grn_posting));
+    posting.sid = 1;
+    posting.pos = 0;
+    while ((id = grn_table_cursor_next(ctx, cursor))) {
+      posting.rid = id;
+      grn_ii_posting_add(ctx, &posting, (grn_hash *)res, op);
+    }
   }
   grn_ii_resolve_sel_and(ctx, (grn_hash *)res, op);
   grn_table_cursor_close(ctx, cursor);

  Added: test/command/suite/select/function/between/with_index/key.expected (+13 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/between/with_index/key.expected    2016-11-16 15:59:59 +0900 (90143a8)
@@ -0,0 +1,13 @@
+table_create Ages TABLE_PAT_KEY Int32
+[[0,0.0,0.0],true]
+load --table Ages
+[
+{"_key": 17},
+{"_key": 18},
+{"_key": 19},
+{"_key": 20},
+{"_key": 21}
+]
+[[0,0.0,0.0],5]
+select Ages --filter 'between(_key, 18, "include", 20, "exclude")'
+[[0,0.0,0.0],[[[2],[["_id","UInt32"],["_key","Int32"]],[2,18],[3,19]]]]

  Added: test/command/suite/select/function/between/with_index/key.test (+12 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/between/with_index/key.test    2016-11-16 15:59:59 +0900 (eb495f6)
@@ -0,0 +1,12 @@
+table_create Ages TABLE_PAT_KEY Int32
+
+load --table Ages
+[
+{"_key": 17},
+{"_key": 18},
+{"_key": 19},
+{"_key": 20},
+{"_key": 21}
+]
+
+select Ages --filter 'between(_key, 18, "include", 20, "exclude")'

  Added: test/command/suite/select/slices/filtered/selector/sub_filter/between_key.expected (+97 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/slices/filtered/selector/sub_filter/between_key.expected    2016-11-16 15:59:59 +0900 (7084061)
@@ -0,0 +1,97 @@
+table_create Times TABLE_PAT_KEY Time
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos date COLUMN_SCALAR Times
+[[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     'sub_filter(date,                 "between(_key,                          \\"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",
+          "Times"
+        ]
+      ],
+      [
+        2,
+        "Mroonga is fast!",
+        1463626801.0
+      ],
+      [
+        3,
+        "Groonga sticker!",
+        1463626802.0
+      ],
+      [
+        4,
+        "Rroonga is fast!",
+        1463626803.0
+      ]
+    ],
+    {
+      "groonga": [
+        [
+          2
+        ],
+        [
+          [
+            "_id",
+            "UInt32"
+          ],
+          [
+            "_key",
+            "ShortText"
+          ],
+          [
+            "date",
+            "Times"
+          ]
+        ],
+        [
+          2,
+          "Mroonga is fast!",
+          1463626801.0
+        ],
+        [
+          3,
+          "Groonga sticker!",
+          1463626802.0
+        ]
+      ]
+    }
+  ]
+]
+#|i| [table][select][index][selector][no-index][sub_filter] <>
+#|i| [table][select][index][selector][between] <Times>
+#|i| [accessor][resolve][data-column][index] <Times.memos_date>
+#|i| [accessor][resolve][table] (temporary) -> <Memos> -> <ShortText>

  Added: test/command/suite/select/slices/filtered/selector/sub_filter/between_key.test (+24 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/slices/filtered/selector/sub_filter/between_key.test    2016-11-16 15:59:59 +0900 (8cf6721)
@@ -0,0 +1,24 @@
+table_create Times TABLE_PAT_KEY Time
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos date COLUMN_SCALAR Times
+
+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 \
+    'sub_filter(date, \
+                "between(_key, \
+                         \\"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