Kouhei Sutou
null+****@clear*****
Sun Jan 26 21:56:15 JST 2014
Kouhei Sutou 2014-01-26 21:56:15 +0900 (Sun, 26 Jan 2014) New Revision: c007a6819aa3840054297b061b35066deaf173f1 https://github.com/groonga/groonga/commit/c007a6819aa3840054297b061b35066deaf173f1 Message: Adjust "||" behavior to ECMAScript "x || y" returns the first not false value. If x is not false value, "x || y" returns "x" itself not "true". If x is false value and y is not false value, "x || y" returns "y" itself not "true". If both "x" and "y" are false value, "x || y" returns "false". It is not changed. Before: null || "string value" -> true null || null -> false After: null || "string value" -> "string value" (changed) null || null -> false (not changed) Added files: test/command/suite/select/filter/logical_operation/or.expected test/command/suite/select/filter/logical_operation/or.test Modified files: lib/expr.c Modified: lib/expr.c (+18 -7) =================================================================== --- lib/expr.c 2014-01-26 21:42:27 +0900 (1875062) +++ lib/expr.c 2014-01-26 21:56:15 +0900 (3f5d9fa) @@ -3155,17 +3155,28 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs) { grn_obj *x, *y; unsigned int x_boolean, y_boolean; - int result; + grn_obj *result; POP2ALLOC1(x, y, res); GRN_TRUEP(ctx, x, x_boolean); - GRN_TRUEP(ctx, y, y_boolean); - if (x_boolean || y_boolean) { - result = 1; + if (x_boolean) { + result = x; } else { - result = 0; + GRN_TRUEP(ctx, y, y_boolean); + if (y_boolean) { + result = y; + } else { + result = NULL; + } + } + if (result) { + if (res != result) { + grn_obj_reinit(ctx, res, result->header.domain, 0); + grn_obj_cast(ctx, result, res, GRN_FALSE); + } + } else { + grn_obj_reinit(ctx, res, GRN_DB_BOOL, 0); + GRN_BOOL_SET(ctx, res, GRN_FALSE); } - grn_obj_reinit(ctx, res, GRN_DB_INT32, 0); - GRN_INT32_SET(ctx, res, result); } code++; break; Added: test/command/suite/select/filter/logical_operation/or.expected (+11 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/logical_operation/or.expected 2014-01-26 21:56:15 +0900 (55ffa98) @@ -0,0 +1,11 @@ +table_create Users TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Users name COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +load --table Users +[ +{"name": "Alice"} +] +[[0,0.0,0.0],1] +select Users --output_columns '_id, null || name || "unknown"' --command_version 2 +[[0,0.0,0.0],[[[1],[["_id","UInt32"],["","null"]],[1,"Alice"]]]] Added: test/command/suite/select/filter/logical_operation/or.test (+11 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/logical_operation/or.test 2014-01-26 21:56:15 +0900 (6a8756a) @@ -0,0 +1,11 @@ +table_create Users TABLE_NO_KEY +column_create Users name COLUMN_SCALAR ShortText + +load --table Users +[ +{"name": "Alice"} +] + +select Users \ + --output_columns '_id, null || name || "unknown"' \ + --command_version 2 -------------- next part -------------- HTML����������������������������...Descargar