[Groonga-commit] groonga/groonga at 3e3edcc [master] Support grouping by Int{8, 16, 64}/UInt{8, 16, 64} value

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Wed Apr 13 18:33:38 JST 2016


Kouhei Sutou	2016-04-13 18:33:38 +0900 (Wed, 13 Apr 2016)

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

  Message:
    Support grouping by Int{8,16,64}/UInt{8,16,64} value
    
    We can only 32bit fixed size value (= sizeof(grn_id) value) before this
    change.

  Added files:
    test/command/suite/select/drilldown/plain/uvector.expected
    test/command/suite/select/drilldown/plain/uvector.test
  Modified files:
    lib/db.c

  Modified: lib/db.c (+29 -13)
===================================================================
--- lib/db.c    2016-04-13 14:58:30 +0900 (9725560)
+++ lib/db.c    2016-04-13 18:33:38 +0900 (beb1423)
@@ -3686,20 +3686,36 @@ grn_table_group_single_key_records(grn_ctx *ctx, grn_obj *table,
       switch (bulk.header.type) {
       case GRN_UVECTOR :
         {
-          // todo : support objects except grn_id
-          grn_id *v = (grn_id *)GRN_BULK_HEAD(&bulk);
-          grn_id *ve = (grn_id *)GRN_BULK_CURR(&bulk);
-          while (v < ve) {
-            if ((*v != GRN_ID_NIL) &&
-                grn_table_add_v_inline(ctx, res,
-                                       v, sizeof(grn_id), &value, NULL)) {
-              grn_table_group_add_subrec(ctx, res, value,
-                                         ri ? ri->score : 0,
-                                         (grn_rset_posinfo *)&id, 0,
-                                         calc_target,
-                                         &value_buffer);
+          grn_bool is_reference;
+          unsigned int element_size;
+          uint8_t *elements;
+          int i, n_elements;
+
+          is_reference = !grn_type_id_is_builtin(ctx, bulk.header.type);
+
+          element_size = grn_uvector_element_size(ctx, &bulk);
+          elements = GRN_BULK_HEAD(&bulk);
+          n_elements = GRN_BULK_VSIZE(&bulk) / element_size;
+          for (i = 0; i < n_elements; i++) {
+            uint8_t *element = elements + (element_size * i);
+
+            if (is_reference) {
+              grn_id id = *((grn_id *)element);
+              if (id == GRN_ID_NIL) {
+                continue;
+              }
             }
-            v++;
+
+            if (!grn_table_add_v_inline(ctx, res, element, element_size,
+                                        &value, NULL)) {
+              continue;
+            }
+
+            grn_table_group_add_subrec(ctx, res, value,
+                                       ri ? ri->score : 0,
+                                       (grn_rset_posinfo *)&id, 0,
+                                       calc_target,
+                                       &value_buffer);
           }
         }
         break;

  Added: test/command/suite/select/drilldown/plain/uvector.expected (+71 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/uvector.expected    2016-04-13 18:33:38 +0900 (d4d43b3)
@@ -0,0 +1,71 @@
+table_create Games TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Games scores COLUMN_VECTOR UInt64
+[[0,0.0,0.0],true]
+load --table Games
+[
+{"_key": "Game1", "scores": [100, 200, 300]},
+{"_key": "Game2", "scores": [100, 200, 400]},
+{"_key": "Game3", "scores": [100, 400, 800, 1600]}
+]
+[[0,0.0,0.0],3]
+select Games   --limit 0   --output_columns _id   --drilldown scores   --drilldown_output_columns _key,_nsubrecs   --drilldown_sortby -_nsubrecs,_id
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ]
+      ]
+    ],
+    [
+      [
+        6
+      ],
+      [
+        [
+          "_key",
+          "UInt64"
+        ],
+        [
+          "_nsubrecs",
+          "Int32"
+        ]
+      ],
+      [
+        100,
+        3
+      ],
+      [
+        200,
+        2
+      ],
+      [
+        400,
+        2
+      ],
+      [
+        300,
+        1
+      ],
+      [
+        800,
+        1
+      ],
+      [
+        1600,
+        1
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/drilldown/plain/uvector.test (+16 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/uvector.test    2016-04-13 18:33:38 +0900 (719ff66)
@@ -0,0 +1,16 @@
+table_create Games TABLE_HASH_KEY ShortText
+column_create Games scores COLUMN_VECTOR UInt64
+
+load --table Games
+[
+{"_key": "Game1", "scores": [100, 200, 300]},
+{"_key": "Game2", "scores": [100, 200, 400]},
+{"_key": "Game3", "scores": [100, 400, 800, 1600]}
+]
+
+select Games \
+  --limit 0 \
+  --output_columns _id \
+  --drilldown scores \
+  --drilldown_output_columns _key,_nsubrecs \
+  --drilldown_sortby -_nsubrecs,_id
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index