[Groonga-commit] groonga/groonga at b7fb300 [master] index_column_diff: add support for reference scalar column

Back to archive index
Kouhei Sutou null+****@clear*****
Sat Mar 23 06:58:22 JST 2019


Kouhei Sutou	2019-03-23 06:58:22 +0900 (Sat, 23 Mar 2019)

  Revision: b7fb300e2b85fcb9649d506db2b6cb7cf1b2e500
  https://github.com/groonga/groonga/commit/b7fb300e2b85fcb9649d506db2b6cb7cf1b2e500

  Message:
    index_column_diff: add support for reference scalar column

  Added files:
    test/command/suite/index_column_diff/reference.expected
    test/command/suite/index_column_diff/reference.test
  Modified files:
    lib/index_column.c
    lib/obj.c

  Modified: lib/index_column.c (+13 -4)
===================================================================
--- lib/index_column.c    2019-03-23 06:46:22 +0900 (64e5a1fc0)
+++ lib/index_column.c    2019-03-23 06:58:22 +0900 (7d3e9cd42)
@@ -816,6 +816,7 @@ grn_index_column_diff_compute(grn_ctx *ctx,
     grn_index_column_diff_progress(ctx, data);
     for (size_t i = 0; i < n_source_columns; i++) {
       grn_obj *source = GRN_PTR_VALUE_AT(source_columns, i);
+      const grn_bool is_reference = grn_obj_is_reference_column(ctx, source);
 
       data->current.posting.rid = id;
       data->current.posting.sid = i + 1;
@@ -839,10 +840,18 @@ grn_index_column_diff_compute(grn_ctx *ctx,
         }
         break;
       case GRN_BULK :
-        grn_index_column_diff_process_token(ctx,
-                                            data,
-                                            GRN_BULK_HEAD(value),
-                                            GRN_BULK_VSIZE(value));
+        if (is_reference) {
+          if (GRN_BULK_VSIZE(value) > 0) {
+            data->current.token_id = GRN_RECORD_VALUE(value);
+            data->current.posting.pos = 0;
+            grn_index_column_diff_process_token_id(ctx, data);
+          }
+        } else {
+          grn_index_column_diff_process_token(ctx,
+                                              data,
+                                              GRN_BULK_HEAD(value),
+                                              GRN_BULK_VSIZE(value));
+        }
         break;
       default :
         break;

  Modified: lib/obj.c (+6 -3)
===================================================================
--- lib/obj.c    2019-03-23 06:46:22 +0900 (7bd63e2b2)
+++ lib/obj.c    2019-03-23 06:58:22 +0900 (4660e9e26)
@@ -219,13 +219,16 @@ grn_obj_is_weight_vector_column(grn_ctx *ctx, grn_obj *obj)
 grn_bool
 grn_obj_is_reference_column(grn_ctx *ctx, grn_obj *obj)
 {
-  grn_obj *range;
-
   if (!grn_obj_is_column(ctx, obj)) {
     return GRN_FALSE;
   }
 
-  range = grn_ctx_at(ctx, grn_obj_get_range(ctx, obj));
+  const grn_id range_id = grn_obj_get_range(ctx, obj);
+  if (grn_id_is_builtin(ctx, range_id)) {
+    return GRN_FALSE;
+  }
+
+  grn_obj *range = range = grn_ctx_at(ctx, range_id);
   if (!range) {
     return GRN_FALSE;
   }

  Added: test/command/suite/index_column_diff/reference.expected (+60 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/index_column_diff/reference.expected    2019-03-23 06:58:22 +0900 (195fc7e95)
@@ -0,0 +1,60 @@
+table_create Values TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Data TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Data value COLUMN_SCALAR Values
+[[0,0.0,0.0],true]
+column_create Values data_index COLUMN_INDEX Data value
+[[0,0.0,0.0],true]
+load --table Data
+[
+{"value": "Hello World"},
+{"value": "Hello Groonga"}
+]
+[[0,0.0,0.0],2]
+truncate Values.data_index
+[[0,0.0,0.0],true]
+load --table Data
+[
+{"value": "Good-by World"},
+{"value": "Good-by Groonga"}
+]
+[[0,0.0,0.0],2]
+index_column_diff Values data_index
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    {
+      "token": {
+        "id": 1,
+        "value": "Hello World"
+      },
+      "remains": [
+
+      ],
+      "missings": [
+        {
+          "record_id": 1
+        }
+      ]
+    },
+    {
+      "token": {
+        "id": 2,
+        "value": "Hello Groonga"
+      },
+      "remains": [
+
+      ],
+      "missings": [
+        {
+          "record_id": 2
+        }
+      ]
+    }
+  ]
+]

  Added: test/command/suite/index_column_diff/reference.test (+22 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/index_column_diff/reference.test    2019-03-23 06:58:22 +0900 (b0e9e94ee)
@@ -0,0 +1,22 @@
+table_create Values TABLE_HASH_KEY ShortText
+
+table_create Data TABLE_NO_KEY
+column_create Data value COLUMN_SCALAR Values
+
+column_create Values data_index COLUMN_INDEX Data value
+
+load --table Data
+[
+{"value": "Hello World"},
+{"value": "Hello Groonga"}
+]
+
+truncate Values.data_index
+
+load --table Data
+[
+{"value": "Good-by World"},
+{"value": "Good-by Groonga"}
+]
+
+index_column_diff Values data_index
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190323/d7c973fd/attachment-0001.html>


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