[Groonga-commit] groonga/groonga at 53a246a [master] select drilldown: support group by all_records without grouped table

Back to archive index

naoa null+****@clear*****
Tue Apr 12 08:42:16 JST 2016


naoa	2016-04-12 08:42:16 +0900 (Tue, 12 Apr 2016)

  New Revision: 53a246a5cab703e4680e597e38339482d927d0eb
  https://github.com/groonga/groonga/commit/53a246a5cab703e4680e597e38339482d927d0eb

  Merged 6a28fff: Merge pull request #528 from naoa/add-table-group-all-records

  Message:
    select drilldown: support group by all_records without grouped table

  Added files:
    test/command/suite/select/drilldown/labeled/all_records/no_table.expected
    test/command/suite/select/drilldown/labeled/all_records/no_table.test
  Modified files:
    lib/proc/proc_select.c

  Modified: lib/proc/proc_select.c (+12 -13)
===================================================================
--- lib/proc/proc_select.c    2016-04-11 14:39:21 +0900 (a12727b)
+++ lib/proc/proc_select.c    2016-04-12 08:42:16 +0900 (31be727)
@@ -635,7 +635,7 @@ grn_select_drilldowns_execute(grn_ctx *ctx,
                                        drilldown->keys_len,
                                        target_table, &n_keys);
 
-    if (!keys && !drilldown->table_name) {
+    if (!keys && !drilldown->calc_target_name) {
       GRN_PLUGIN_CLEAR_ERROR(ctx);
       continue;
     }
@@ -1158,12 +1158,10 @@ proc_select_find_all_drilldown_labels(grn_ctx *ctx, grn_user_data *user_data,
   grn_table_cursor *cursor;
   cursor = grn_table_cursor_open(ctx, vars, NULL, 0, NULL, 0, 0, -1, 0);
   if (cursor) {
+#define N_SUFFIXES 3
     const char *prefix = "drilldown[";
     int prefix_len = strlen(prefix);
-    const char *suffix_key = "].keys";
-    int suffix_key_len = strlen(suffix_key);
-    const char *suffix_table = "].table";
-    int suffix_table_len = strlen(suffix_table);
+    const char *suffixes[N_SUFFIXES] = {"].keys", "].table", "].calc_target"};
     int suffix_len;
     while (grn_table_cursor_next(ctx, cursor)) {
       void *key;
@@ -1174,14 +1172,14 @@ proc_select_find_all_drilldown_labels(grn_ctx *ctx, grn_user_data *user_data,
       suffix_len = 0;
       if (name_len >= prefix_len &&
           strncmp(prefix, name, prefix_len) == 0) {
-        if (name_len >= (prefix_len + 1 + suffix_key_len) &&
-            strncmp(suffix_key, name + name_len - suffix_key_len,
-                    suffix_key_len) == 0) {
-          suffix_len = suffix_key_len;
-        } else if (name_len >= (prefix_len + 1 + suffix_table_len) &&
-                   strncmp(suffix_table, name + name_len - suffix_table_len,
-                   suffix_table_len) == 0) {
-          suffix_len = suffix_table_len;
+        int i;
+        for (i = 0; i < N_SUFFIXES; i++) {
+          int len = strlen(suffixes[i]);
+          if (name_len >= (prefix_len + 1 + len) &&
+              strncmp(suffixes[i], name + name_len - len, len) == 0) {
+            suffix_len = len;
+            break;
+          }
         }
         if (suffix_len > 0) {
           grn_table_add(ctx, labels,
@@ -1190,6 +1188,7 @@ proc_select_find_all_drilldown_labels(grn_ctx *ctx, grn_user_data *user_data,
                         NULL);
         }
       }
+#undef N_SUFFIXES
     }
     grn_table_cursor_close(ctx, cursor);
   }

  Added: test/command/suite/select/drilldown/labeled/all_records/no_table.expected (+82 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/labeled/all_records/no_table.expected    2016-04-12 08:42:16 +0900 (317062e)
@@ -0,0 +1,82 @@
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos value COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga is fast!", "value": 10},
+{"_key": "Mroonga is fast!", "value": 2},
+{"_key": "Groonga sticker!", "value": 3},
+{"_key": "Rroonga is fast!", "value": 4}
+]
+[[0,0.0,0.0],4]
+select Memos   --drilldown[sum].calc_types SUM   --drilldown[sum].calc_target value   --drilldown[sum].output_columns _key,_sum
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        4
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "value",
+          "Int64"
+        ]
+      ],
+      [
+        1,
+        "Groonga is fast!",
+        10
+      ],
+      [
+        2,
+        "Mroonga is fast!",
+        2
+      ],
+      [
+        3,
+        "Groonga sticker!",
+        3
+      ],
+      [
+        4,
+        "Rroonga is fast!",
+        4
+      ]
+    ],
+    {
+      "sum": [
+        [
+          1
+        ],
+        [
+          [
+            "_key",
+            "ShortText"
+          ],
+          [
+            "_sum",
+            "Int64"
+          ]
+        ],
+        [
+          "all_records",
+          19
+        ]
+      ]
+    }
+  ]
+]

  Added: test/command/suite/select/drilldown/labeled/all_records/no_table.test (+15 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/labeled/all_records/no_table.test    2016-04-12 08:42:16 +0900 (46146ac)
@@ -0,0 +1,15 @@
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos value COLUMN_SCALAR Int64
+
+load --table Memos
+[
+{"_key": "Groonga is fast!", "value": 10},
+{"_key": "Mroonga is fast!", "value": 2},
+{"_key": "Groonga sticker!", "value": 3},
+{"_key": "Rroonga is fast!", "value": 4}
+]
+
+select Memos \
+  --drilldown[sum].calc_types SUM \
+  --drilldown[sum].calc_target value \
+  --drilldown[sum].output_columns _key,_sum
-------------- next part --------------
HTML����������������������������...
Télécharger 



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