Kouhei Sutou
null+****@clear*****
Wed Apr 19 11:06:49 JST 2017
Kouhei Sutou 2017-04-19 11:06:49 +0900 (Wed, 19 Apr 2017) New Revision: f940037f6121f649e5c6ae5875b3a1d4a921da36 https://github.com/groonga/groonga/commit/f940037f6121f649e5c6ae5875b3a1d4a921da36 Message: expr_code: count called function to the number of arguments It's internal change but it breaks a compatibility that uses grn_expr_append_op() such as Rroonga. Added files: test/command/suite/sharding/logical_count/condition/range/partial.expected test/command/suite/sharding/logical_count/condition/range/partial.test Modified files: lib/expr.c lib/expr_code.c lib/grn_ecmascript.c lib/grn_ecmascript.lemon lib/mrb/scripts/expression_tree/function_call.rb lib/mrb/scripts/expression_tree_builder.rb lib/window_function.c plugins/sharding/range_expression_builder.rb plugins/suggest/suggest.c Modified: lib/expr.c (+8 -8) =================================================================== --- lib/expr.c 2017-04-18 13:26:37 +0900 (e41b79c) +++ lib/expr.c 2017-04-19 11:06:49 +0900 (fdfd985) @@ -903,11 +903,11 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op, case GRN_OP_CALL : { grn_obj *proc = NULL; - if (e->codes_curr - nargs > 0) { + if (e->codes_curr - (nargs - 1) > 0) { int i; grn_expr_code *code; code = &(e->codes[e->codes_curr - 1]); - for (i = 0; i < nargs; i++) { + for (i = 0; i < nargs - 1; i++) { int rest_n_codes = 1; while (rest_n_codes > 0) { rest_n_codes += code->nargs; @@ -951,7 +951,7 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op, } PUSH_CODE(e, op, obj, nargs, code); { - int i = nargs; + int i = nargs - 1; while (i--) { dfi = grn_expr_dfi_pop(e); } } if (!obj) { dfi = grn_expr_dfi_pop(e); } @@ -2595,16 +2595,16 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs) { grn_obj *proc; if (code->value) { - if (sp < s_ + code->nargs) { + if (sp < s_ + code->nargs - 1) { ERR(GRN_INVALID_ARGUMENT, "stack error"); goto exit; } proc = code->value; WITH_SPSAVE({ - grn_proc_call(ctx, proc, code->nargs, expr); + grn_proc_call(ctx, proc, code->nargs - 1, expr); }); } else { - int offset = code->nargs + 1; + int offset = code->nargs; if (sp < s_ + offset) { ERR(GRN_INVALID_ARGUMENT, "stack error"); goto exit; @@ -2622,7 +2622,7 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs) goto exit; } else { WITH_SPSAVE({ - grn_proc_call(ctx, proc, code->nargs, expr); + grn_proc_call(ctx, proc, code->nargs - 1, expr); }); } if (ctx->rc) { @@ -7075,7 +7075,7 @@ parse_query(grn_ctx *ctx, efs_info *q) /* dummy token */ PARSE(GRN_EXPR_TOKEN_QSTRING); grn_expr_append_obj(ctx, q->e, all_records, GRN_OP_PUSH, 1); - grn_expr_append_op(ctx, q->e, GRN_OP_CALL, 0); + grn_expr_append_op(ctx, q->e, GRN_OP_CALL, 1); } } op->op = GRN_OP_AND_NOT; Modified: lib/expr_code.c (+4 -20) =================================================================== --- lib/expr_code.c 2017-04-18 13:26:37 +0900 (4f03867) +++ lib/expr_code.c 2017-04-19 11:06:49 +0900 (c12a3cb) @@ -24,7 +24,6 @@ grn_expr_code_n_used_codes(grn_ctx *ctx, { unsigned int n_codes; int i, n_args; - grn_bool have_proc_push_code = GRN_FALSE; grn_expr_code *sub_code; if (start == target) { @@ -32,16 +31,10 @@ grn_expr_code_n_used_codes(grn_ctx *ctx, } n_args = target->nargs; - if (target->op == GRN_OP_CALL) { - if (!target->value) { - have_proc_push_code = GRN_TRUE; - } - } else { - if (target->value) { - n_args--; - if (n_args == 0) { - return 1; - } + if (target->value) { + n_args--; + if (n_args == 0) { + return 1; } } @@ -58,14 +51,5 @@ grn_expr_code_n_used_codes(grn_ctx *ctx, } } - if (have_proc_push_code) { - n_codes++; - sub_code--; - if (sub_code < start) { - /* TODO: report error */ - return 0; - } - } - return n_codes; } Modified: lib/grn_ecmascript.c (+1 -1) =================================================================== --- lib/grn_ecmascript.c 2017-04-18 13:26:37 +0900 (30cea9e) +++ lib/grn_ecmascript.c 2017-04-19 11:06:49 +0900 (77618c6) @@ -1946,7 +1946,7 @@ static void yy_reduce( case 65: /* call_expression ::= member_expression arguments */ #line 371 "grn_ecmascript.lemon" { - grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_CALL, yymsp[0].minor.yy0); + grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_CALL, 1 + yymsp[0].minor.yy0); } #line 1952 "grn_ecmascript.c" break; Modified: lib/grn_ecmascript.lemon (+1 -1) =================================================================== --- lib/grn_ecmascript.lemon 2017-04-18 13:26:37 +0900 (24305ae) +++ lib/grn_ecmascript.lemon 2017-04-19 11:06:49 +0900 (fac6ac1) @@ -369,7 +369,7 @@ lefthand_side_expression ::= call_expression. lefthand_side_expression ::= member_expression. call_expression ::= member_expression arguments(A). { - grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_CALL, A); + grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_CALL, 1 + A); } member_expression ::= primary_expression. Modified: lib/mrb/scripts/expression_tree/function_call.rb (+1 -1) =================================================================== --- lib/mrb/scripts/expression_tree/function_call.rb 2017-04-18 13:26:37 +0900 (dd61480) +++ lib/mrb/scripts/expression_tree/function_call.rb 2017-04-19 11:06:49 +0900 (55dca34) @@ -13,7 +13,7 @@ module Groonga @arguments.each do |argument| argument.build(expression) end - expression.append_operator(Operator::CALL, @arguments.size) + expression.append_operator(Operator::CALL, 1 +****@argum*****) end def estimate_size(table) Modified: lib/mrb/scripts/expression_tree_builder.rb (+1 -1) =================================================================== --- lib/mrb/scripts/expression_tree_builder.rb 2017-04-18 13:26:37 +0900 (9dd0386) +++ lib/mrb/scripts/expression_tree_builder.rb 2017-04-19 11:06:49 +0900 (f2cc297) @@ -85,7 +85,7 @@ module Groonga stack.push(node) when Operator::CALL arguments = [] - code.n_args.times do + (code.n_args - 1).times do arguments.unshift(stack.pop) end procedure = stack.pop Modified: lib/window_function.c (+1 -1) =================================================================== --- lib/window_function.c 2017-04-18 13:26:37 +0900 (bb5648d) +++ lib/window_function.c 2017-04-19 11:06:49 +0900 (6804aef) @@ -241,7 +241,7 @@ grn_expr_is_window_function_call(grn_ctx *ctx, if (call->op != GRN_OP_CALL) { return GRN_FALSE; } - if (call->nargs != (expr->codes_curr - 2)) { + if (call->nargs != (expr->codes_curr - 1)) { return GRN_FALSE; } Modified: plugins/sharding/range_expression_builder.rb (+1 -1) =================================================================== --- plugins/sharding/range_expression_builder.rb 2017-04-18 13:26:37 +0900 (cc80735) +++ plugins/sharding/range_expression_builder.rb 2017-04-19 11:06:49 +0900 (26e2c82) @@ -55,7 +55,7 @@ module Groonga expression.append_constant(@target_range.max, Operator::PUSH, 1) expression.append_constant(@target_range.max_border, Operator::PUSH, 1) - expression.append_operator(Operator::CALL, 5) + expression.append_operator(Operator::CALL, 6) build_condition(expression) end Modified: plugins/suggest/suggest.c (+1 -1) =================================================================== --- plugins/suggest/suggest.c 2017-04-18 13:26:37 +0900 (07a8689) +++ plugins/suggest/suggest.c 2017-04-19 11:06:49 +0900 (96a38d1) @@ -462,7 +462,7 @@ correct(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost, key, GRN_OP_GET_VALUE, 1); grn_expr_append_const(ctx, expr, query, GRN_OP_PUSH, 1); - grn_expr_append_op(ctx, expr, GRN_OP_CALL, 2); + grn_expr_append_op(ctx, expr, GRN_OP_CALL, 3); grn_expr_append_op(ctx, expr, GRN_OP_MINUS_ASSIGN, 2); if ((tc = grn_table_cursor_open(ctx, res, NULL, 0, NULL, 0, 0, -1, 0))) { Added: test/command/suite/sharding/logical_count/condition/range/partial.expected (+48 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_count/condition/range/partial.expected 2017-04-19 11:06:49 +0900 (73d47c6) @@ -0,0 +1,48 @@ +plugin_register sharding +[[0,0.0,0.0],true] +table_create Logs_20150203 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150203 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150203 message COLUMN_SCALAR Text +[[0,0.0,0.0],true] +table_create Logs_20150204 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150204 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150204 message COLUMN_SCALAR Text +[[0,0.0,0.0],true] +table_create Logs_20150205 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150205 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150205 message COLUMN_SCALAR Text +[[0,0.0,0.0],true] +load --table Logs_20150203 +[ +{"timestamp": "2015-02-03 23:59:58", "message": "Start"}, +{"timestamp": "2015-02-03 23:59:58", "message": "Shutdown"}, +{"timestamp": "2015-02-03 23:59:59", "message": "Start"}, +{"timestamp": "2015-02-03 23:59:59", "message": "Shutdown"} +] +[[0,0.0,0.0],4] +load --table Logs_20150204 +[ +{"timestamp": "2015-02-04 00:00:00", "message": "Start"}, +{"timestamp": "2015-02-04 00:00:00", "message": "Shutdown"}, +{"timestamp": "2015-02-04 00:00:01", "message": "Start"}, +{"timestamp": "2015-02-04 00:00:01", "message": "Shutdown"}, +{"timestamp": "2015-02-04 23:59:59", "message": "Start"}, +{"timestamp": "2015-02-04 23:59:59", "message": "Shutdown"} +] +[[0,0.0,0.0],6] +load --table Logs_20150205 +[ +{"timestamp": "2015-02-05 00:00:00", "message": "Start"}, +{"timestamp": "2015-02-05 00:00:00", "message": "Shutdown"}, +{"timestamp": "2015-02-05 00:00:01", "message": "Start"}, +{"timestamp": "2015-02-05 00:00:01", "message": "Shutdown"} +] +[[0,0.0,0.0],4] +logical_count Logs timestamp --filter 'message == "Shutdown"' --min "2015-02-04 00:00:01" --min_border "include" --max "2015-02-04 23:59:59" --max_border "include" +[[0,0.0,0.0],2] Added: test/command/suite/sharding/logical_count/condition/range/partial.test (+49 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_count/condition/range/partial.test 2017-04-19 11:06:49 +0900 (b5da042) @@ -0,0 +1,49 @@ +#@on-error omit +plugin_register sharding +#@on-error default + +table_create Logs_20150203 TABLE_NO_KEY +column_create Logs_20150203 timestamp COLUMN_SCALAR Time +column_create Logs_20150203 message COLUMN_SCALAR Text + +table_create Logs_20150204 TABLE_NO_KEY +column_create Logs_20150204 timestamp COLUMN_SCALAR Time +column_create Logs_20150204 message COLUMN_SCALAR Text + +table_create Logs_20150205 TABLE_NO_KEY +column_create Logs_20150205 timestamp COLUMN_SCALAR Time +column_create Logs_20150205 message COLUMN_SCALAR Text + +load --table Logs_20150203 +[ +{"timestamp": "2015-02-03 23:59:58", "message": "Start"}, +{"timestamp": "2015-02-03 23:59:58", "message": "Shutdown"}, +{"timestamp": "2015-02-03 23:59:59", "message": "Start"}, +{"timestamp": "2015-02-03 23:59:59", "message": "Shutdown"} +] + +load --table Logs_20150204 +[ +{"timestamp": "2015-02-04 00:00:00", "message": "Start"}, +{"timestamp": "2015-02-04 00:00:00", "message": "Shutdown"}, +{"timestamp": "2015-02-04 00:00:01", "message": "Start"}, +{"timestamp": "2015-02-04 00:00:01", "message": "Shutdown"}, +{"timestamp": "2015-02-04 23:59:59", "message": "Start"}, +{"timestamp": "2015-02-04 23:59:59", "message": "Shutdown"} +] + +load --table Logs_20150205 +[ +{"timestamp": "2015-02-05 00:00:00", "message": "Start"}, +{"timestamp": "2015-02-05 00:00:00", "message": "Shutdown"}, +{"timestamp": "2015-02-05 00:00:01", "message": "Start"}, +{"timestamp": "2015-02-05 00:00:01", "message": "Shutdown"} +] + +logical_count Logs timestamp \ + --filter 'message == "Shutdown"' \ + --min "2015-02-04 00:00:01" \ + --min_border "include" \ + --max "2015-02-04 23:59:59" \ + --max_border "include" + -------------- next part -------------- HTML����������������������������...Download