Kouhei Sutou
null+****@clear*****
Tue Oct 20 14:52:19 JST 2015
Kouhei Sutou 2015-10-20 14:52:19 +0900 (Tue, 20 Oct 2015) New Revision: 3efd3892e6fc337a8ef7cec3d51d26f40c5a64ed https://github.com/groonga/groonga/commit/3efd3892e6fc337a8ef7cec3d51d26f40c5a64ed Message: schema: support column sources Modified files: lib/proc.c test/command/suite/schema/tables/columns/compress/lz4.expected test/command/suite/schema/tables/columns/compress/zlib.expected test/command/suite/schema/tables/columns/type/index.expected test/command/suite/schema/tables/columns/type/index.test test/command/suite/schema/tables/columns/type/scalar.expected test/command/suite/schema/tables/columns/type/vector.expected Modified: lib/proc.c (+64 -1) =================================================================== --- lib/proc.c 2015-10-20 14:38:19 +0900 (cc1a5b8) +++ lib/proc.c 2015-10-20 14:52:19 +0900 (8d6c1a4) @@ -7886,6 +7886,66 @@ proc_schema_column_output_compress(grn_ctx *ctx, grn_obj *column) } static void +proc_schema_column_output_sources(grn_ctx *ctx, grn_obj *column) +{ + grn_obj *source_table; + grn_obj source_ids; + unsigned int i, n_ids; + + source_table = grn_ctx_at(ctx, grn_obj_get_range(ctx, column)); + + GRN_RECORD_INIT(&source_ids, GRN_OBJ_VECTOR, GRN_ID_NIL); + + if (column->header.type == GRN_COLUMN_INDEX) { + grn_obj_get_info(ctx, column, GRN_INFO_SOURCE, &source_ids); + } + + n_ids = GRN_BULK_VSIZE(&source_ids) / sizeof(grn_id); + GRN_OUTPUT_MAP_OPEN("sources", n_ids); + for (i = 0; i < n_ids; i++) { + grn_id source_id; + grn_obj *source; + + source_id = GRN_RECORD_VALUE_AT(&source_ids, i); + source = grn_ctx_at(ctx, source_id); + + if (grn_obj_is_table(ctx, source)) { + GRN_OUTPUT_CSTR("_key"); + } else { + proc_schema_output_column_name(ctx, source); + } + + GRN_OUTPUT_MAP_OPEN("source", 3); + + GRN_OUTPUT_CSTR("name"); + if (grn_obj_is_table(ctx, source)) { + GRN_OUTPUT_CSTR("_key"); + } else { + proc_schema_output_column_name(ctx, source); + } + + GRN_OUTPUT_CSTR("table"); + proc_schema_output_name(ctx, source_table); + + GRN_OUTPUT_CSTR("full_name"); + if (grn_obj_is_table(ctx, source)) { + char name[GRN_TABLE_MAX_KEY_SIZE]; + unsigned int name_size; + name_size = grn_obj_name(ctx, source, name, GRN_TABLE_MAX_KEY_SIZE); + grn_strcat(name, GRN_TABLE_MAX_KEY_SIZE, "._key"); + GRN_OUTPUT_CSTR(name); + } else { + proc_schema_output_name(ctx, source); + } + + GRN_OUTPUT_MAP_CLOSE(); + } + GRN_OUTPUT_MAP_CLOSE(); + + GRN_OBJ_FIN(ctx, &source_ids); +} + +static void proc_schema_column_output(grn_ctx *ctx, grn_obj *table, grn_obj *column) { if (!column) { @@ -7894,7 +7954,7 @@ proc_schema_column_output(grn_ctx *ctx, grn_obj *table, grn_obj *column) proc_schema_output_column_name(ctx, column); - GRN_OUTPUT_MAP_OPEN("column", 10); + GRN_OUTPUT_MAP_OPEN("column", 11); GRN_OUTPUT_CSTR("name"); proc_schema_output_column_name(ctx, column); @@ -7923,6 +7983,9 @@ proc_schema_column_output(grn_ctx *ctx, grn_obj *table, grn_obj *column) GRN_OUTPUT_CSTR("position"); GRN_OUTPUT_BOOL((column->header.flags & GRN_OBJ_WITH_POSITION) != 0); + GRN_OUTPUT_CSTR("sources"); + proc_schema_column_output_sources(ctx, column); + GRN_OUTPUT_MAP_CLOSE(); } Modified: test/command/suite/schema/tables/columns/compress/lz4.expected (+3 -1) =================================================================== --- test/command/suite/schema/tables/columns/compress/lz4.expected 2015-10-20 14:38:19 +0900 (cf707e0) +++ test/command/suite/schema/tables/columns/compress/lz4.expected 2015-10-20 14:52:19 +0900 (80ccba8) @@ -202,7 +202,9 @@ schema "compress": "lz4", "section": false, "weight": false, - "position": false + "position": false, + "sources": { + } } } } Modified: test/command/suite/schema/tables/columns/compress/zlib.expected (+3 -1) =================================================================== --- test/command/suite/schema/tables/columns/compress/zlib.expected 2015-10-20 14:38:19 +0900 (0890130) +++ test/command/suite/schema/tables/columns/compress/zlib.expected 2015-10-20 14:52:19 +0900 (f0fdddc) @@ -202,7 +202,9 @@ schema "compress": "zlib", "section": false, "weight": false, - "position": false + "position": false, + "sources": { + } } } } Modified: test/command/suite/schema/tables/columns/type/index.expected (+29 -8) =================================================================== --- test/command/suite/schema/tables/columns/type/index.expected 2015-10-20 14:38:19 +0900 (c4fdea7) +++ test/command/suite/schema/tables/columns/type/index.expected 2015-10-20 14:52:19 +0900 (8617ce9) @@ -2,11 +2,11 @@ table_create Posts TABLE_HASH_KEY ShortText [[0,0.0,0.0],true] column_create Posts title COLUMN_SCALAR ShortText [[0,0.0,0.0],true] -column_create Posts text COLUMN_SCALAR Text +column_create Posts content COLUMN_SCALAR Text [[0,0.0,0.0],true] table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto [[0,0.0,0.0],true] -column_create Terms index COLUMN_INDEX|WITH_SECTION|WITH_WEIGHT|WITH_POSITION Posts title,text +column_create Terms index COLUMN_INDEX|WITH_SECTION|WITH_WEIGHT|WITH_POSITION Posts _key,title,content [[0,0.0,0.0],true] schema [ @@ -200,10 +200,10 @@ schema "command_line": "table_create --name Posts --flags TABLE_HASH_KEY --key_type ShortText" }, "columns": { - "text": { - "name": "text", + "content": { + "name": "content", "table": "Posts", - "full_name": "Posts.text", + "full_name": "Posts.content", "type": "scalar", "value_type": { "name": "Text", @@ -212,7 +212,9 @@ schema "compress": null, "section": false, "weight": false, - "position": false + "position": false, + "sources": { + } }, "title": { "name": "title", @@ -226,7 +228,9 @@ schema "compress": null, "section": false, "weight": false, - "position": false + "position": false, + "sources": { + } } } }, @@ -271,7 +275,24 @@ schema "compress": null, "section": true, "weight": true, - "position": true + "position": true, + "sources": { + "_key": { + "name": "_key", + "table": "Posts", + "full_name": "Posts._key" + }, + "title": { + "name": "title", + "table": "Posts", + "full_name": "Posts.title" + }, + "content": { + "name": "content", + "table": "Posts", + "full_name": "Posts.content" + } + } } } } Modified: test/command/suite/schema/tables/columns/type/index.test (+2 -2) =================================================================== --- test/command/suite/schema/tables/columns/type/index.test 2015-10-20 14:38:19 +0900 (b7faaf3) +++ test/command/suite/schema/tables/columns/type/index.test 2015-10-20 14:52:19 +0900 (86aa0d7) @@ -1,11 +1,11 @@ table_create Posts TABLE_HASH_KEY ShortText column_create Posts title COLUMN_SCALAR ShortText -column_create Posts text COLUMN_SCALAR Text +column_create Posts content COLUMN_SCALAR Text table_create Terms TABLE_PAT_KEY ShortText \ --default_tokenizer TokenBigram \ --normalizer NormalizerAuto column_create Terms index COLUMN_INDEX|WITH_SECTION|WITH_WEIGHT|WITH_POSITION \ - Posts title,text + Posts _key,title,content schema Modified: test/command/suite/schema/tables/columns/type/scalar.expected (+3 -1) =================================================================== --- test/command/suite/schema/tables/columns/type/scalar.expected 2015-10-20 14:38:19 +0900 (98a7e5d) +++ test/command/suite/schema/tables/columns/type/scalar.expected 2015-10-20 14:52:19 +0900 (bec22c4) @@ -202,7 +202,9 @@ schema "compress": null, "section": false, "weight": false, - "position": false + "position": false, + "sources": { + } } } } Modified: test/command/suite/schema/tables/columns/type/vector.expected (+3 -1) =================================================================== --- test/command/suite/schema/tables/columns/type/vector.expected 2015-10-20 14:38:19 +0900 (0e6051e) +++ test/command/suite/schema/tables/columns/type/vector.expected 2015-10-20 14:52:19 +0900 (10ca084) @@ -208,7 +208,9 @@ schema "compress": null, "section": false, "weight": false, - "position": false + "position": false, + "sources": { + } } } }, -------------- next part -------------- HTML����������������������������...Download