[Groonga-commit] groonga/groonga at f43015a [master] select: support "initial" stage for dynamic column

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Tue May 10 10:40:41 JST 2016


Kouhei Sutou	2016-05-10 10:40:41 +0900 (Tue, 10 May 2016)

  New Revision: f43015a1b6c87ea219bf334e9a8ee82b72803b6a
  https://github.com/groonga/groonga/commit/f43015a1b6c87ea219bf334e9a8ee82b72803b6a

  Message:
    select: support "initial" stage for dynamic column

  Added files:
    test/command/suite/select/column/stage/initial/filter.expected
    test/command/suite/select/column/stage/initial/filter.test
  Modified files:
    lib/proc/proc_select.c

  Modified: lib/proc/proc_select.c (+29 -5)
===================================================================
--- lib/proc/proc_select.c    2016-05-10 09:51:11 +0900 (cbc99bf)
+++ lib/proc/proc_select.c    2016-05-10 10:40:41 +0900 (03166a5)
@@ -1124,6 +1124,8 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
     }
   }
   if ((table = grn_ctx_get(ctx, data->table.value, data->table.length))) {
+    grn_obj *initial_table = table;
+
     if (data->filter.length > 0 && (data->filter.value[0] == '?') &&
         (ctx->impl->output.type == GRN_CONTENT_JSON)) {
       ctx->rc = grn_ts_select(ctx, table,
@@ -1146,12 +1148,27 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
       }
       goto exit;
     }
+
+    if (data->columns.initial) {
+      grn_posting posting;
+
+      memset(&posting, 0, sizeof(grn_posting));
+      initial_table = grn_table_create(ctx, NULL, 0, NULL,
+                                       GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC,
+                                       table, NULL);
+      GRN_TABLE_EACH(ctx, table, 0, 0, id, NULL, NULL, NULL, {
+        posting.rid = id;
+        grn_ii_posting_add(ctx, &posting, (grn_hash *)initial_table, GRN_OP_OR);
+      });
+      grn_select_apply_columns(ctx, initial_table, data->columns.initial, NULL);
+    }
+
     if (data->query.length > 0 || data->filter.length > 0) {
       grn_obj *v;
-      GRN_EXPR_CREATE_FOR_QUERY(ctx, table, cond, v);
+      GRN_EXPR_CREATE_FOR_QUERY(ctx, initial_table, cond, v);
       if (cond) {
         if (data->match_columns.length) {
-          GRN_EXPR_CREATE_FOR_QUERY(ctx, table, match_columns, v);
+          GRN_EXPR_CREATE_FOR_QUERY(ctx, initial_table, match_columns, v);
           if (match_columns) {
             grn_expr_parse(ctx, match_columns,
                            data->match_columns.value,
@@ -1224,13 +1241,15 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
         GRN_LOG(ctx, GRN_LOG_NOTICE, "query=(%s)", GRN_TEXT_VALUE(&strbuf));
         GRN_OBJ_FIN(ctx, &strbuf);
         */
-        if (!ctx->rc) { res = grn_table_select(ctx, table, cond, NULL, GRN_OP_OR); }
+        if (!ctx->rc) {
+          res = grn_table_select(ctx, initial_table, cond, NULL, GRN_OP_OR);
+        }
       } else {
         /* todo */
         ERRCLR(ctx);
       }
     } else {
-      res = table;
+      res = initial_table;
     }
     nhits = res ? grn_table_size(ctx, res) : 0;
     GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
@@ -1373,7 +1392,12 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
       if (gkeys) {
         grn_table_sort_key_close(ctx, gkeys, ngkeys);
       }
-      if (res != table) { grn_obj_unlink(ctx, res); }
+      if (res != table && res != initial_table) {
+        grn_obj_unlink(ctx, res);
+      }
+      if (initial_table != table) {
+        grn_obj_unlink(ctx, initial_table);
+      }
     } else {
       GRN_OUTPUT_ARRAY_OPEN("RESULT", 0);
     }

  Added: test/command/suite/select/column/stage/initial/filter.expected (+65 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/column/stage/initial/filter.expected    2016-05-10 10:40:41 +0900 (72aa1e9)
@@ -0,0 +1,65 @@
+table_create Items TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Items price COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+load --table Items
+[
+{"_key": "Book",  "price": 1000},
+{"_key": "Note",  "price": 1000},
+{"_key": "Box",   "price":  520},
+{"_key": "Pen",   "price":  510},
+{"_key": "Food",  "price":  500},
+{"_key": "Drink", "price":  300}
+]
+[[0,0.0,0.0],6]
+select Items   --column[price_with_tax].stage initial   --column[price_with_tax].type UInt32   --column[price_with_tax].flags COLUMN_SCALAR   --column[price_with_tax].value 'price * 1.08'   --filter 'price_with_tax > 550'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "price_with_tax",
+          "UInt32"
+        ],
+        [
+          "price",
+          "UInt32"
+        ]
+      ],
+      [
+        1,
+        "Book",
+        1080,
+        1000
+      ],
+      [
+        2,
+        "Note",
+        1080,
+        1000
+      ],
+      [
+        3,
+        "Box",
+        561,
+        520
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/column/stage/initial/filter.test (+19 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/column/stage/initial/filter.test    2016-05-10 10:40:41 +0900 (2ca21e9)
@@ -0,0 +1,19 @@
+table_create Items TABLE_HASH_KEY ShortText
+column_create Items price COLUMN_SCALAR UInt32
+
+load --table Items
+[
+{"_key": "Book",  "price": 1000},
+{"_key": "Note",  "price": 1000},
+{"_key": "Box",   "price":  520},
+{"_key": "Pen",   "price":  510},
+{"_key": "Food",  "price":  500},
+{"_key": "Drink", "price":  300}
+]
+
+select Items \
+  --column[price_with_tax].stage initial \
+  --column[price_with_tax].type UInt32 \
+  --column[price_with_tax].flags COLUMN_SCALAR \
+  --column[price_with_tax].value 'price * 1.08' \
+  --filter 'price_with_tax > 550'
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る