Kouhei Sutou
null+****@clear*****
Wed May 4 22:09:29 JST 2016
Kouhei Sutou 2016-05-04 22:09:29 +0900 (Wed, 04 May 2016) New Revision: ac5631db695c22b8c0584882a0f92c26ef9876a2 https://github.com/groonga/groonga/commit/ac5631db695c22b8c0584882a0f92c26ef9876a2 Message: select output_columns v1: support expression in output_columns Expression includes function call such as "snippet_html(...)". Modified files: lib/output.c test/command/suite/select/cache/command_version.expected test/command/suite/select/cache/command_version.test test/command/suite/select/function/snippet_html/compressed.expected test/command/suite/select/function/snippet_html/compressed.test Modified: lib/output.c (+50 -20) =================================================================== --- lib/output.c 2016-05-04 22:01:13 +0900 (d4ef027) +++ lib/output.c 2016-05-04 22:09:29 +0900 (11a76ee) @@ -1407,16 +1407,39 @@ grn_output_table_columns(grn_ctx *ctx, grn_obj *outbuf, } static inline void -grn_output_table_record_by_expression(grn_ctx *ctx, grn_obj *outbuf, +grn_output_table_record_by_column(grn_ctx *ctx, + grn_obj *outbuf, + grn_content_type output_type, + grn_obj *column, + grn_id id) +{ + grn_text_atoj(ctx, outbuf, output_type, column, id); +} + +static inline void +grn_output_table_record_by_expression(grn_ctx *ctx, + grn_obj *outbuf, grn_content_type output_type, - grn_obj *expression) + grn_obj *expression, + grn_obj *record) { - grn_obj *result; - result = grn_expr_exec(ctx, expression, 0); - if (result) { - grn_output_obj(ctx, outbuf, output_type, result, NULL); + grn_expr *expr = (grn_expr *)expression; + + if (expr->codes_curr == 1 && expr->codes[0].op == GRN_OP_GET_VALUE) { + grn_obj *column = expr->codes[0].value; + grn_output_table_record_by_column(ctx, + outbuf, + output_type, + column, + GRN_RECORD_VALUE(record)); } else { - grn_output_cstr(ctx, outbuf, output_type, ctx->errbuf); + grn_obj *result; + result = grn_expr_exec(ctx, expression, 0); + if (result) { + grn_output_obj(ctx, outbuf, output_type, result, NULL); + } else { + grn_output_cstr(ctx, outbuf, output_type, ctx->errbuf); + } } } @@ -1457,16 +1480,22 @@ grn_output_table_records_by_expression(grn_ctx *ctx, grn_obj *outbuf, expr->codes, expr->codes + second_code_offset); expr->codes_curr = second_code_offset - second_code_n_used_codes + 1; - grn_output_table_record_by_expression(ctx, outbuf, output_type, - format->expression); + grn_output_table_record_by_expression(ctx, + outbuf, + output_type, + format->expression, + record); code_start_offset = expr->codes_curr; is_first_comma = GRN_FALSE; } code_end_offset = code - expr->codes - code_start_offset; expr->codes += code_start_offset; expr->codes_curr = code_end_offset; - grn_output_table_record_by_expression(ctx, outbuf, output_type, - format->expression); + grn_output_table_record_by_expression(ctx, + outbuf, + output_type, + format->expression, + record); expr->codes -= code_start_offset; expr->codes_curr = original_codes_curr; previous_comma_offset = code - expr->codes; @@ -1474,8 +1503,11 @@ grn_output_table_records_by_expression(grn_ctx *ctx, grn_obj *outbuf, } if (!have_comma && expr->codes_curr > 0) { - grn_output_table_record_by_expression(ctx, outbuf, output_type, - format->expression); + grn_output_table_record_by_expression(ctx, + outbuf, + output_type, + format->expression, + record); } grn_output_array_close(ctx, outbuf, output_type); @@ -1495,7 +1527,11 @@ grn_output_table_records_by_columns(grn_ctx *ctx, grn_obj *outbuf, while ((id = grn_table_cursor_next(ctx, tc)) != GRN_ID_NIL) { grn_output_array_open(ctx, outbuf, output_type, "HIT", ncolumns); for (i = 0; i < ncolumns; i++) { - grn_text_atoj(ctx, outbuf, output_type, columns[i], id); + grn_output_table_record_by_column(ctx, + outbuf, + output_type, + columns[i], + id); } grn_output_array_close(ctx, outbuf, output_type); } @@ -2163,12 +2199,6 @@ is_output_columns_format_v1(grn_ctx *ctx, { unsigned int i; - /* TODO: REMOVE ME. If new output_columns handler is marked as stable, - this check is removed. We need more error checks. */ - if (grn_ctx_get_command_version(ctx) == GRN_COMMAND_VERSION_1) { - return GRN_TRUE; - } - for (i = 0; i < output_columns_len; i++) { switch (output_columns[i]) { case ',' : Modified: test/command/suite/select/cache/command_version.expected (+36 -6) =================================================================== --- test/command/suite/select/cache/command_version.expected 2016-05-04 22:01:13 +0900 (8823820) +++ test/command/suite/select/cache/command_version.expected 2016-05-04 22:09:29 +0900 (aa05be5) @@ -5,9 +5,7 @@ load --table Memos {"_key": "Hello Groonga!"} ] [[0,0.0,0.0],1] -select Memos --query '_key:@Groonga' --output_columns 'snippet_html(_key)' -[[0,0.0,0.0],[[[1],[],[]]]] -select Memos --query '_key:@Groonga' --output_columns 'snippet_html(_key)' --command_version 2 +select Memos --filter 'true' --output_columns '_key,_score' [ [ 0, @@ -21,14 +19,46 @@ select Memos --query '_key:@Groonga' --output_columns 'snippet_html(_key)' ], [ [ - "snippet_html", - "null" + "_key", + "ShortText" + ], + [ + "_score", + "Int32" ] ], [ + "Hello Groonga!", + 1 + ] + ] + ] +] +select Memos --filter 'true' --output_columns '_key,_score' --command_version 2 +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_key", + "ShortText" + ], [ - "Hello <span class=\"keyword\">Groonga</span>!" + "_score", + "Float" ] + ], + [ + "Hello Groonga!", + 1.0 ] ] ] Modified: test/command/suite/select/cache/command_version.test (+4 -4) =================================================================== --- test/command/suite/select/cache/command_version.test 2016-05-04 22:01:13 +0900 (5a8cc41) +++ test/command/suite/select/cache/command_version.test 2016-05-04 22:09:29 +0900 (1236b6c) @@ -9,10 +9,10 @@ load --table Memos #@sleep 1 select Memos \ - --query '_key:@Groonga' \ - --output_columns 'snippet_html(_key)' + --filter 'true' \ + --output_columns '_key,_score' select Memos \ - --query '_key:@Groonga' \ - --output_columns 'snippet_html(_key)' \ + --filter 'true' \ + --output_columns '_key,_score' \ --command_version 2 Modified: test/command/suite/select/function/snippet_html/compressed.expected (+1 -1) =================================================================== --- test/command/suite/select/function/snippet_html/compressed.expected 2016-05-04 22:01:13 +0900 (6204d97) +++ test/command/suite/select/function/snippet_html/compressed.expected 2016-05-04 22:09:29 +0900 (863f343) @@ -20,7 +20,7 @@ load --table Documents ["groonga ストレージエンジン", "groonga は独自のカラムストアを持つ列指向のデータベースとしての側面を持っていますが、既存の RDBMS のストレージエンジンとして利用することもできます。たとえば、groonga をベースとする MySQL のストレージエンジンとして mroonga が開発されています。mroonga は MySQL のプラグインとして動的にロードすることが可能であり、groonga のカラムストアをストレージとして利用したり、全文検索エンジンとして groonga を MyISAM や InnoDB と連携させたりすることができます。groonga 単体での利用、およびに MyISAM, InnoDB との連携には一長一短があるので、用途に応じて適切な組み合わせを選ぶことが大切です。詳しくは 関連プロジェクト を参照してください。"] ] [[0,0.0,0.0],9] -select Documents --match_columns content --query 'mroonga MySQL' --output_columns '_key, snippet_html(content)' --command_version 2 +select Documents --match_columns content --query 'mroonga MySQL' --output_columns '_key, snippet_html(content)' [ [ 0, Modified: test/command/suite/select/function/snippet_html/compressed.test (+1 -2) =================================================================== --- test/command/suite/select/function/snippet_html/compressed.test 2016-05-04 22:01:13 +0900 (b19d2fc) +++ test/command/suite/select/function/snippet_html/compressed.test 2016-05-04 22:09:29 +0900 (900d278) @@ -20,5 +20,4 @@ load --table Documents select Documents \ --match_columns content --query 'mroonga MySQL' \ - --output_columns '_key, snippet_html(content)' \ - --command_version 2 + --output_columns '_key, snippet_html(content)' -------------- next part -------------- HTML����������������������������... 下载