Kouhei Sutou
null+****@clear*****
Thu Feb 7 19:23:13 JST 2013
Kouhei Sutou 2013-02-07 19:23:13 +0900 (Thu, 07 Feb 2013) New Revision: 06fe432ad0c7eccec43f4824467e4c30e7026c7f https://github.com/groonga/groonga/commit/06fe432ad0c7eccec43f4824467e4c30e7026c7f Log: load: reset set value error for each column This was done for scalar column but vector column wasn't cared. :< Added files: test/command/suite/load/invalid/in_mid_brace/vector.expected test/command/suite/load/invalid/in_mid_brace/vector.test test/command/suite/load/invalid/in_mid_bracket/vector.expected test/command/suite/load/invalid/in_mid_bracket/vector.test Modified files: lib/db.c Modified: lib/db.c (+21 -21) =================================================================== --- lib/db.c 2013-02-07 19:11:03 +0900 (7173ad7) +++ lib/db.c 2013-02-07 19:23:13 +0900 (8cf7e26) @@ -8578,6 +8578,7 @@ bracket_close(grn_ctx *ctx, grn_loader *loader) if (id) { int i = 0; while (ndata--) { + grn_obj *column; if ((loader->table->header.type == GRN_TABLE_HASH_KEY || loader->table->header.type == GRN_TABLE_PAT_KEY || loader->table->header.type == GRN_TABLE_DAT_KEY) && @@ -8587,24 +8588,24 @@ bracket_close(grn_ctx *ctx, grn_loader *loader) i++; continue; } + + column = *cols; if (value->header.domain == OPEN_BRACKET) { - set_vector(ctx, *cols, id, value); + set_vector(ctx, column, id, value); } else if (value->header.domain == OPEN_BRACE) { /* todo */ } else { - grn_rc rc; - grn_obj *column = *cols; - rc = grn_obj_set_value(ctx, column, id, value, GRN_OBJ_SET); - if (rc != GRN_SUCCESS) { - char column_name[GRN_TABLE_MAX_KEY_SIZE]; - unsigned int column_name_size; - column_name_size = grn_obj_name(ctx, column, column_name, - GRN_TABLE_MAX_KEY_SIZE); - report_set_column_value_failure(ctx, key_value, - column_name, column_name_size, - value); - ERRCLR(ctx); - } + grn_obj_set_value(ctx, column, id, value, GRN_OBJ_SET); + } + if (ctx->rc != GRN_SUCCESS) { + char column_name[GRN_TABLE_MAX_KEY_SIZE]; + unsigned int column_name_size; + column_name_size = grn_obj_name(ctx, column, column_name, + GRN_TABLE_MAX_KEY_SIZE); + report_set_column_value_failure(ctx, key_value, + column_name, column_name_size, + value); + ERRCLR(ctx); } value = values_next(ctx, value); cols++; @@ -8702,13 +8703,12 @@ brace_close(grn_ctx *ctx, grn_loader *loader) } else if (value->header.domain == OPEN_BRACE) { /* todo */ } else { - grn_rc rc; - rc = grn_obj_set_value(ctx, col, id, value, GRN_OBJ_SET); - if (rc != GRN_SUCCESS) { - report_set_column_value_failure(ctx, key_value, - name, name_size, value); - ERRCLR(ctx); - } + grn_obj_set_value(ctx, col, id, value, GRN_OBJ_SET); + } + if (ctx->rc != GRN_SUCCESS) { + report_set_column_value_failure(ctx, key_value, + name, name_size, value); + ERRCLR(ctx); } grn_obj_unlink(ctx, col); } else { Added: test/command/suite/load/invalid/in_mid_brace/vector.expected (+69 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/load/invalid/in_mid_brace/vector.expected 2013-02-07 19:23:13 +0900 (853c845) @@ -0,0 +1,69 @@ +table_create Tags TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +table_create Users TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Users name COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Users cards COLUMN_VECTOR UInt8 +[[0,0.0,0.0],true] +column_create Users tags COLUMN_VECTOR Tags +[[0,0.0,0.0],true] +column_create Tags usrs_tags COLUMN_INDEX Users tags +[[0,0.0,0.0],true] +load --table Users +[ +{"_key": "alice", "name": "Alice", "cards": [1, "GARBAGE", 3], "tags": ["girl", "wonder"]} +] +[[0,0.0,0.0],1] +#|e| <Users.cards>: failed to cast to <UInt8>: <"GARBAGE"> +#|e| [table][load] failed to set column value: <Users.cards>: failed to cast to <UInt8>: <"GARBAGE">: key: <"alice">, column: <cards>, value: <3> +select Users +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "cards", + "UInt8" + ], + [ + "name", + "ShortText" + ], + [ + "tags", + "Tags" + ] + ], + [ + 1, + "alice", + [ + 1, + 3 + ], + "Alice", + [ + "girl", + "wonder" + ] + ] + ] + ] +] Added: test/command/suite/load/invalid/in_mid_brace/vector.test (+15 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/load/invalid/in_mid_brace/vector.test 2013-02-07 19:23:13 +0900 (bcb624f) @@ -0,0 +1,15 @@ +table_create Tags TABLE_HASH_KEY ShortText + +table_create Users TABLE_HASH_KEY ShortText +column_create Users name COLUMN_SCALAR ShortText +column_create Users cards COLUMN_VECTOR UInt8 +column_create Users tags COLUMN_VECTOR Tags + +column_create Tags usrs_tags COLUMN_INDEX Users tags + +load --table Users +[ +{"_key": "alice", "name": "Alice", "cards": [1, "GARBAGE", 3], "tags": ["girl", "wonder"]} +] + +select Users Added: test/command/suite/load/invalid/in_mid_bracket/vector.expected (+70 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/load/invalid/in_mid_bracket/vector.expected 2013-02-07 19:23:13 +0900 (7df5b98) @@ -0,0 +1,70 @@ +table_create Tags TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +table_create Users TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Users name COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Users cards COLUMN_VECTOR UInt8 +[[0,0.0,0.0],true] +column_create Users tags COLUMN_VECTOR Tags +[[0,0.0,0.0],true] +column_create Tags usrs_tags COLUMN_INDEX Users tags +[[0,0.0,0.0],true] +load --table Users +[ +["_key", "name", "cards", "tags"], +["alice", "Alice", [1, "GARBAGE", 3], ["girl", "wonder"]] +] +[[0,0.0,0.0],1] +#|e| <Users.cards>: failed to cast to <UInt8>: <"GARBAGE"> +#|e| [table][load] failed to set column value: <Users.cards>: failed to cast to <UInt8>: <"GARBAGE">: key: <"alice">, column: <Users.cards>, value: <3> +select Users +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "cards", + "UInt8" + ], + [ + "name", + "ShortText" + ], + [ + "tags", + "Tags" + ] + ], + [ + 1, + "alice", + [ + 1, + 3 + ], + "Alice", + [ + "girl", + "wonder" + ] + ] + ] + ] +] Added: test/command/suite/load/invalid/in_mid_bracket/vector.test (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/load/invalid/in_mid_bracket/vector.test 2013-02-07 19:23:13 +0900 (6839a79) @@ -0,0 +1,16 @@ +table_create Tags TABLE_HASH_KEY ShortText + +table_create Users TABLE_HASH_KEY ShortText +column_create Users name COLUMN_SCALAR ShortText +column_create Users cards COLUMN_VECTOR UInt8 +column_create Users tags COLUMN_VECTOR Tags + +column_create Tags usrs_tags COLUMN_INDEX Users tags + +load --table Users +[ +["_key", "name", "cards", "tags"], +["alice", "Alice", [1, "GARBAGE", 3], ["girl", "wonder"]] +] + +select Users -------------- next part -------------- HTML����������������������������...ダウンロード