Navigation Menu

Skip to content

Commit

Permalink
schema: support column sources
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 20, 2015
1 parent 1a896e3 commit 3efd389
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 15 deletions.
65 changes: 64 additions & 1 deletion lib/proc.c
Expand Up @@ -7885,6 +7885,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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down
Expand Up @@ -202,7 +202,9 @@ schema
"compress": "lz4",
"section": false,
"weight": false,
"position": false
"position": false,
"sources": {
}
}
}
}
Expand Down
Expand Up @@ -202,7 +202,9 @@ schema
"compress": "zlib",
"section": false,
"weight": false,
"position": false
"position": false,
"sources": {
}
}
}
}
Expand Down
37 changes: 29 additions & 8 deletions test/command/suite/schema/tables/columns/type/index.expected
Expand Up @@ -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
[
Expand Down Expand Up @@ -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",
Expand All @@ -212,7 +212,9 @@ schema
"compress": null,
"section": false,
"weight": false,
"position": false
"position": false,
"sources": {
}
},
"title": {
"name": "title",
Expand All @@ -226,7 +228,9 @@ schema
"compress": null,
"section": false,
"weight": false,
"position": false
"position": false,
"sources": {
}
}
}
},
Expand Down Expand Up @@ -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"
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/command/suite/schema/tables/columns/type/index.test
@@ -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
Expand Up @@ -202,7 +202,9 @@ schema
"compress": null,
"section": false,
"weight": false,
"position": false
"position": false,
"sources": {
}
}
}
}
Expand Down
Expand Up @@ -208,7 +208,9 @@ schema
"compress": null,
"section": false,
"weight": false,
"position": false
"position": false,
"sources": {
}
}
}
},
Expand Down

0 comments on commit 3efd389

Please sign in to comment.