Kouhei Sutou
null+****@clear*****
Tue Oct 20 14:10:15 JST 2015
Kouhei Sutou 2015-10-20 14:10:15 +0900 (Tue, 20 Oct 2015) New Revision: e3655486a2fc0baaa994c975944e6a29276b1a31 https://github.com/groonga/groonga/commit/e3655486a2fc0baaa994c975944e6a29276b1a31 Message: schema: start supporting column Added files: test/command/suite/schema/tables/columns/type/scalar.test test/command/suite/schema/tables/columns/type/vector.test Copied files: test/command/suite/schema/tables/columns/type/scalar.expected (from test/command/suite/schema/tables/type/array.expected) test/command/suite/schema/tables/columns/type/vector.expected (from test/command/suite/schema/tables/value_type/reference.expected) Modified files: lib/proc.c test/command/suite/schema/tables/normalizer.expected test/command/suite/schema/tables/token_filters.expected test/command/suite/schema/tables/tokenizer.expected test/command/suite/schema/tables/type/array.expected test/command/suite/schema/tables/type/hash_table.expected test/command/suite/schema/tables/value_type/reference.expected test/command/suite/schema/tables/value_type/type.expected Modified: lib/proc.c (+81 -1) =================================================================== --- lib/proc.c 2015-10-20 12:41:51 +0900 (eacf16d) +++ lib/proc.c 2015-10-20 14:10:15 +0900 (3070e41) @@ -7306,6 +7306,15 @@ proc_schema_output_name(grn_ctx *ctx, grn_obj *obj) } static void +proc_schema_output_column_name(grn_ctx *ctx, grn_obj *column) +{ + char name[GRN_TABLE_MAX_KEY_SIZE]; + unsigned int name_size; + name_size = grn_column_name(ctx, column, name, GRN_TABLE_MAX_KEY_SIZE); + GRN_OUTPUT_STR(name, name_size); +} + +static void proc_schema_output_plugins(grn_ctx *ctx) { grn_obj plugin_names; @@ -7826,6 +7835,74 @@ proc_schema_table_output_command(grn_ctx *ctx, grn_obj *table) } static void +proc_schema_column_output(grn_ctx *ctx, grn_obj *table, grn_obj *column) +{ + if (!column) { + return; + } + + proc_schema_output_column_name(ctx, column); + + GRN_OUTPUT_MAP_OPEN("column", 4); + + GRN_OUTPUT_CSTR("name"); + proc_schema_output_column_name(ctx, column); + + GRN_OUTPUT_CSTR("table"); + proc_schema_output_name(ctx, table); + + GRN_OUTPUT_CSTR("full_name"); + proc_schema_output_name(ctx, column); + + GRN_OUTPUT_CSTR("type"); + switch (column->header.type) { + case GRN_COLUMN_FIX_SIZE : + case GRN_COLUMN_VAR_SIZE : + switch (column->header.flags & GRN_OBJ_COLUMN_TYPE_MASK) { + case GRN_OBJ_COLUMN_SCALAR : + GRN_OUTPUT_CSTR("scalar"); + break; + case GRN_OBJ_COLUMN_VECTOR : + GRN_OUTPUT_CSTR("vector"); + break; + } + break; + case GRN_COLUMN_INDEX : + GRN_OUTPUT_CSTR("index"); + break; + } + + GRN_OUTPUT_MAP_CLOSE(); +} + +static void +proc_schema_table_output_columns(grn_ctx *ctx, grn_obj *table) +{ + grn_hash *columns; + + columns = grn_hash_create(ctx, NULL, sizeof(grn_id), 0, + GRN_OBJ_TABLE_HASH_KEY | GRN_HASH_TINY); + if (!columns) { + GRN_OUTPUT_MAP_OPEN("columns", 0); + GRN_OUTPUT_MAP_CLOSE(); + return; + } + + grn_table_columns(ctx, table, "", 0, (grn_obj *)columns); + GRN_OUTPUT_MAP_OPEN("columns", GRN_HASH_SIZE(columns)); + { + grn_id *key; + GRN_HASH_EACH(ctx, columns, id, &key, NULL, NULL, { + grn_obj *column; + column = grn_ctx_at(ctx, *key); + proc_schema_column_output(ctx, table, column); + }); + } + GRN_OUTPUT_MAP_CLOSE(); + grn_hash_close(ctx, columns); +} + +static void proc_schema_output_tables(grn_ctx *ctx) { grn_obj tables; @@ -7846,7 +7923,7 @@ proc_schema_output_tables(grn_ctx *ctx) proc_schema_output_name(ctx, table); - GRN_OUTPUT_MAP_OPEN("table", 8); + GRN_OUTPUT_MAP_OPEN("table", 9); GRN_OUTPUT_CSTR("name"); proc_schema_output_name(ctx, table); @@ -7872,6 +7949,9 @@ proc_schema_output_tables(grn_ctx *ctx) GRN_OUTPUT_CSTR("command"); proc_schema_table_output_command(ctx, table); + GRN_OUTPUT_CSTR("columns"); + proc_schema_table_output_columns(ctx, table); + GRN_OUTPUT_MAP_CLOSE(); } GRN_OUTPUT_MAP_CLOSE(); Copied: test/command/suite/schema/tables/columns/type/scalar.expected (+10 -0) 94% =================================================================== --- test/command/suite/schema/tables/type/array.expected 2015-10-20 12:41:51 +0900 (dc79219) +++ test/command/suite/schema/tables/columns/type/scalar.expected 2015-10-20 14:10:15 +0900 (b7af666) @@ -1,5 +1,7 @@ table_create Logs TABLE_NO_KEY [[0,0.0,0.0],true] +column_create Logs message COLUMN_SCALAR Text +[[0,0.0,0.0],true] schema [ [ @@ -186,6 +188,14 @@ schema "flags": "TABLE_NO_KEY" }, "command_line": "table_create --name Logs --flags TABLE_NO_KEY" + }, + "columns": { + "message": { + "name": "message", + "table": "Logs", + "full_name": "Logs.message", + "type": "scalar" + } } } } Added: test/command/suite/schema/tables/columns/type/scalar.test (+4 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/schema/tables/columns/type/scalar.test 2015-10-20 14:10:15 +0900 (7f5fd74) @@ -0,0 +1,4 @@ +table_create Logs TABLE_NO_KEY +column_create Logs message COLUMN_SCALAR Text + +schema Copied: test/command/suite/schema/tables/columns/type/vector.expected (+36 -21) 81% =================================================================== --- test/command/suite/schema/tables/value_type/reference.expected 2015-10-20 12:41:51 +0900 (a3142ff) +++ test/command/suite/schema/tables/columns/type/vector.expected 2015-10-20 14:10:15 +0900 (0d1569f) @@ -1,6 +1,8 @@ -table_create Users TABLE_HASH_KEY ShortText +table_create Tags TABLE_DAT_KEY ShortText --normalizer NormalizerAuto [[0,0.0,0.0],true] -table_create Logs TABLE_NO_KEY --value_type Users +table_create Posts TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Posts tags COLUMN_VECTOR Tags [[0,0.0,0.0],true] schema [ @@ -171,14 +173,14 @@ schema "token_filters": { }, "tables": { - "Logs": { - "name": "Logs", - "type": "array", - "key_type": null, - "value_type": { - "name": "Users", - "type": "reference" + "Posts": { + "name": "Posts", + "type": "hash table", + "key_type": { + "name": "ShortText", + "type": "type" }, + "value_type": null, "tokenizer": null, "normalizer": null, "token_filters": [ @@ -187,34 +189,47 @@ schema "command": { "name": "table_create", "arguments": { - "name": "Logs", - "flags": "TABLE_NO_KEY", - "value_type": "Users" + "name": "Posts", + "flags": "TABLE_HASH_KEY", + "key_type": "ShortText" }, - "command_line": "table_create --name Logs --flags TABLE_NO_KEY --value_type Users" + "command_line": "table_create --name Posts --flags TABLE_HASH_KEY --key_type ShortText" + }, + "columns": { + "tags": { + "name": "tags", + "table": "Posts", + "full_name": "Posts.tags", + "type": "vector" + } } }, - "Users": { - "name": "Users", - "type": "hash table", + "Tags": { + "name": "Tags", + "type": "double array trie", "key_type": { "name": "ShortText", "type": "type" }, "value_type": null, "tokenizer": null, - "normalizer": null, + "normalizer": { + "name": "NormalizerAuto" + }, "token_filters": [ ], "command": { "name": "table_create", "arguments": { - "name": "Users", - "flags": "TABLE_HASH_KEY", - "key_type": "ShortText" + "name": "Tags", + "flags": "TABLE_DAT_KEY", + "key_type": "ShortText", + "normalizer": "NormalizerAuto" }, - "command_line": "table_create --name Users --flags TABLE_HASH_KEY --key_type ShortText" + "command_line": "table_create --name Tags --flags TABLE_DAT_KEY --key_type ShortText --normalizer NormalizerAuto" + }, + "columns": { } } } Added: test/command/suite/schema/tables/columns/type/vector.test (+6 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/schema/tables/columns/type/vector.test 2015-10-20 14:10:15 +0900 (88bce84) @@ -0,0 +1,6 @@ +table_create Tags TABLE_DAT_KEY ShortText --normalizer NormalizerAuto + +table_create Posts TABLE_HASH_KEY ShortText +column_create Posts tags COLUMN_VECTOR Tags + +schema Modified: test/command/suite/schema/tables/normalizer.expected (+2 -0) =================================================================== --- test/command/suite/schema/tables/normalizer.expected 2015-10-20 12:41:51 +0900 (91216d0) +++ test/command/suite/schema/tables/normalizer.expected 2015-10-20 14:10:15 +0900 (cd72767) @@ -193,6 +193,8 @@ schema "normalizer": "NormalizerAuto" }, "command_line": "table_create --name Tags --flags TABLE_PAT_KEY --key_type ShortText --normalizer NormalizerAuto" + }, + "columns": { } } } Modified: test/command/suite/schema/tables/token_filters.expected (+2 -0) =================================================================== --- test/command/suite/schema/tables/token_filters.expected 2015-10-20 12:41:51 +0900 (8d78dcf) +++ test/command/suite/schema/tables/token_filters.expected 2015-10-20 14:10:15 +0900 (aa514dd) @@ -204,6 +204,8 @@ schema "token_filters": "TokenFilterStopWord" }, "command_line": "table_create --name Terms --flags TABLE_PAT_KEY --key_type ShortText --default_tokenizer TokenBigram --token_filters TokenFilterStopWord" + }, + "columns": { } } } Modified: test/command/suite/schema/tables/tokenizer.expected (+2 -0) =================================================================== --- test/command/suite/schema/tables/tokenizer.expected 2015-10-20 12:41:51 +0900 (06de651) +++ test/command/suite/schema/tables/tokenizer.expected 2015-10-20 14:10:15 +0900 (02b846d) @@ -193,6 +193,8 @@ schema "default_tokenizer": "TokenBigram" }, "command_line": "table_create --name Terms --flags TABLE_PAT_KEY --key_type ShortText --default_tokenizer TokenBigram" + }, + "columns": { } } } Modified: test/command/suite/schema/tables/type/array.expected (+2 -0) =================================================================== --- test/command/suite/schema/tables/type/array.expected 2015-10-20 12:41:51 +0900 (dc79219) +++ test/command/suite/schema/tables/type/array.expected 2015-10-20 14:10:15 +0900 (7b06048) @@ -186,6 +186,8 @@ schema "flags": "TABLE_NO_KEY" }, "command_line": "table_create --name Logs --flags TABLE_NO_KEY" + }, + "columns": { } } } Modified: test/command/suite/schema/tables/type/hash_table.expected (+2 -0) =================================================================== --- test/command/suite/schema/tables/type/hash_table.expected 2015-10-20 12:41:51 +0900 (b735266) +++ test/command/suite/schema/tables/type/hash_table.expected 2015-10-20 14:10:15 +0900 (65612ac) @@ -190,6 +190,8 @@ schema "key_type": "ShortText" }, "command_line": "table_create --name Users --flags TABLE_HASH_KEY --key_type ShortText" + }, + "columns": { } } } Modified: test/command/suite/schema/tables/value_type/reference.expected (+4 -0) =================================================================== --- test/command/suite/schema/tables/value_type/reference.expected 2015-10-20 12:41:51 +0900 (a3142ff) +++ test/command/suite/schema/tables/value_type/reference.expected 2015-10-20 14:10:15 +0900 (d257144) @@ -192,6 +192,8 @@ schema "value_type": "Users" }, "command_line": "table_create --name Logs --flags TABLE_NO_KEY --value_type Users" + }, + "columns": { } }, "Users": { @@ -215,6 +217,8 @@ schema "key_type": "ShortText" }, "command_line": "table_create --name Users --flags TABLE_HASH_KEY --key_type ShortText" + }, + "columns": { } } } Modified: test/command/suite/schema/tables/value_type/type.expected (+2 -0) =================================================================== --- test/command/suite/schema/tables/value_type/type.expected 2015-10-20 12:41:51 +0900 (1cf0463) +++ test/command/suite/schema/tables/value_type/type.expected 2015-10-20 14:10:15 +0900 (75e4a4d) @@ -190,6 +190,8 @@ schema "value_type": "Int32" }, "command_line": "table_create --name Logs --flags TABLE_NO_KEY --value_type Int32" + }, + "columns": { } } } -------------- next part -------------- HTML����������������������������...Download