Naoya Murakami
null+****@clear*****
Mon Dec 25 21:45:56 JST 2017
Naoya Murakami 2017-12-25 21:45:56 +0900 (Mon, 25 Dec 2017) New Revision: 0f5cdf15222ca68cf831f2f1477cc4ec357e4151 https://github.com/groonga/groonga/commit/0f5cdf15222ca68cf831f2f1477cc4ec357e4151 Merged 8f138e2: Merge pull request #792 from naoa/index-column-source-records-object-option Message: index_column_source_records: use object literal style option Modified files: plugins/functions/index_column.c test/command/suite/select/function/index_column/index_column_source_records/limit.expected test/command/suite/select/function/index_column/index_column_source_records/limit.test Modified: plugins/functions/index_column.c (+54 -6) =================================================================== --- plugins/functions/index_column.c 2017-12-25 16:36:44 +0900 (1132166c2) +++ plugins/functions/index_column.c 2017-12-25 21:45:56 +0900 (acacd2325) @@ -276,12 +276,60 @@ func_index_column_source_records(grn_ctx *ctx, } if (n_args == 2) { - limit = grn_plugin_proc_get_value_int64(ctx, - args[1], - limit, - "index_column_source_records()"); - if (ctx->rc != GRN_SUCCESS) { - return NULL; + grn_obj *options = args[1]; + + switch (options->header.type) { + case GRN_TABLE_HASH_KEY : + { + grn_hash_cursor *cursor; + void *key; + grn_obj *value; + int key_size; + cursor = grn_hash_cursor_open(ctx, (grn_hash *)options, + NULL, 0, NULL, 0, + 0, -1, 0); + if (!cursor) { + GRN_PLUGIN_ERROR(ctx, GRN_NO_MEMORY_AVAILABLE, + "index_column_source_records(): failed to open cursor for options"); + return NULL; + } + while (grn_hash_cursor_next(ctx, cursor) != GRN_ID_NIL) { + grn_hash_cursor_get_key_value(ctx, cursor, &key, &key_size, + (void **)&value); + +#define KEY_EQUAL(name) \ + (key_size == strlen(name) && memcmp(key, name, strlen(name)) == 0) + + if (KEY_EQUAL("limit")) { + limit = grn_plugin_proc_get_value_int64(ctx, value, limit, "index_column_source_records()"); + if (ctx->rc != GRN_SUCCESS) { + grn_hash_cursor_close(ctx, cursor); + return NULL; + } + } else { + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "index_column_source_records(): unknown option name: <%.*s>", + key_size, (char *)key); + grn_hash_cursor_close(ctx, cursor); + return NULL; + } +#undef KEY_EQUAL + } + } + break; + default : + { + grn_obj inspected; + GRN_TEXT_INIT(&inspected, 0); + grn_inspect(ctx, &inspected, options); + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "index_column_source_records(): " + "2nd argument must be string or object literal: <%.*s>", + (int)GRN_TEXT_LEN(&inspected), + GRN_TEXT_VALUE(&inspected)); + GRN_OBJ_FIN(ctx, &inspected); + return NULL; + } } } Modified: test/command/suite/select/function/index_column/index_column_source_records/limit.expected (+1 -1) =================================================================== --- test/command/suite/select/function/index_column/index_column_source_records/limit.expected 2017-12-25 16:36:44 +0900 (6a7d7fc49) +++ test/command/suite/select/function/index_column/index_column_source_records/limit.expected 2017-12-25 21:45:56 +0900 (ea1f3c347) @@ -13,7 +13,7 @@ load --table Memos {"_key": "Rroonga is a Ruby bindings for Groonga."} ] [[0,0.0,0.0],3] -select Terms --limit -1 --sort_keys _id --columns[index_records].stage output --columns[index_records].type Memos --columns[index_records].flags COLUMN_VECTOR --columns[index_records].value 'index_column_source_records("index", 2)' --output_columns '_id, _key, index_records' +select Terms --limit -1 --sort_keys _id --columns[index_records].stage output --columns[index_records].type Memos --columns[index_records].flags COLUMN_VECTOR --columns[index_records].value 'index_column_source_records("index", {"limit": 2})' --output_columns '_id, _key, index_records' [ [ 0, Modified: test/command/suite/select/function/index_column/index_column_source_records/limit.test (+1 -1) =================================================================== --- test/command/suite/select/function/index_column/index_column_source_records/limit.test 2017-12-25 16:36:44 +0900 (a50b16fd9) +++ test/command/suite/select/function/index_column/index_column_source_records/limit.test 2017-12-25 21:45:56 +0900 (144c2430f) @@ -20,5 +20,5 @@ select Terms \ --columns[index_records].stage output \ --columns[index_records].type Memos \ --columns[index_records].flags COLUMN_VECTOR \ - --columns[index_records].value 'index_column_source_records("index", 2)' \ + --columns[index_records].value 'index_column_source_records("index", {"limit": 2})' \ --output_columns '_id, _key, index_records' -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171225/22bedf7a/attachment-0001.htm