Naoya Murakami
null+****@clear*****
Mon May 22 03:31:59 JST 2017
Naoya Murakami 2017-05-22 03:31:59 +0900 (Mon, 22 May 2017) New Revision: 6d460140176dfb5c348820963bda11dbb114c5e9 https://github.com/groonga/groonga/commit/6d460140176dfb5c348820963bda11dbb114c5e9 Merged 958f959: Merge pull request #695 from naoa/fix-bug-vector-slice-for-non-4bytes-vector Message: vector_slice: fix a bug that non 4 bytes vector columns can't slice GitHub: #694 Added files: test/command/suite/select/function/vector/vector_slice/int64_vector.expected test/command/suite/select/function/vector/vector_slice/int64_vector.test Modified files: plugins/functions/vector.c Modified: plugins/functions/vector.c (+44 -1) =================================================================== --- plugins/functions/vector.c 2017-05-19 14:02:25 +0900 (f5df5b1) +++ plugins/functions/vector.c 2017-05-22 03:31:59 +0900 (d9f4017) @@ -259,7 +259,7 @@ func_vector_slice(grn_ctx *ctx, int n_args, grn_obj **args, } break; case GRN_UVECTOR : - { + if (grn_obj_is_reference_column(ctx, target)) { unsigned int i; for (i = from; i < to; i++) { grn_id id; @@ -267,8 +267,51 @@ func_vector_slice(grn_ctx *ctx, int n_args, grn_obj **args, id = grn_uvector_get_element(ctx, target, i, &weight); grn_uvector_add_element(ctx, slice, id, weight); } + } else { +#define PUT_SLICE_VALUES(type) do { \ + unsigned int i; \ + for (i = from; i < to; i++) { \ + GRN_ ## type ## _PUT(ctx, slice, GRN_ ## type ## _VALUE_AT(target, i)); \ + } \ + } while (GRN_FALSE) + switch (target->header.domain) { + case GRN_DB_BOOL : + PUT_SLICE_VALUES(BOOL); + break; + case GRN_DB_INT8 : + PUT_SLICE_VALUES(INT8); + break; + case GRN_DB_UINT8 : + PUT_SLICE_VALUES(UINT8); + break; + case GRN_DB_INT16 : + PUT_SLICE_VALUES(INT16); + break; + case GRN_DB_UINT16 : + PUT_SLICE_VALUES(UINT16); + break; + case GRN_DB_INT32 : + PUT_SLICE_VALUES(INT32); + break; + case GRN_DB_UINT32 : + PUT_SLICE_VALUES(UINT32); + break; + case GRN_DB_INT64 : + PUT_SLICE_VALUES(INT64); + break; + case GRN_DB_UINT64 : + PUT_SLICE_VALUES(UINT64); + break; + case GRN_DB_FLOAT : + PUT_SLICE_VALUES(FLOAT); + break; + case GRN_DB_TIME : + PUT_SLICE_VALUES(TIME); + break; + } } break; +#undef PUT_SLICE_VALUES } return slice; Added: test/command/suite/select/function/vector/vector_slice/int64_vector.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/int64_vector.expected 2017-05-22 03:31:59 +0900 (e00f466) @@ -0,0 +1,63 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tag_ids COLUMN_VECTOR Int64 +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tag_ids": [1, 3, 5]}, +{"_key": "Rroonga", "tag_ids": [2, 4]} +] +[[0,0.0,0.0],2] +select Memos --output_columns '_key, tag_ids, vector_slice(tag_ids, 1, 2)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 2 + ], + [ + [ + "_key", + "ShortText" + ], + [ + "tag_ids", + "Int64" + ], + [ + "vector_slice", + null + ] + ], + [ + "Groonga", + [ + 1, + 3, + 5 + ], + [ + 3, + 5 + ] + ], + [ + "Rroonga", + [ + 2, + 4 + ], + [ + 4 + ] + ] + ] + ] +] Added: test/command/suite/select/function/vector/vector_slice/int64_vector.test (+13 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_slice/int64_vector.test 2017-05-22 03:31:59 +0900 (2053fd8) @@ -0,0 +1,13 @@ +plugin_register functions/vector + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tag_ids COLUMN_VECTOR Int64 + +load --table Memos +[ +{"_key": "Groonga", "tag_ids": [1, 3, 5]}, +{"_key": "Rroonga", "tag_ids": [2, 4]} +] + +select Memos \ + --output_columns '_key, tag_ids, vector_slice(tag_ids, 1, 2)' -------------- next part -------------- HTML����������������������������...Download