Navigation Menu

Skip to content

Commit

Permalink
object_inspect: start supporting column
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 6, 2017
1 parent 9a1ff15 commit dac6d10
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 1 deletion.
51 changes: 50 additions & 1 deletion lib/proc/proc_object_inspect.c
@@ -1,6 +1,6 @@
/* -*- c-basic-offset: 2 -*- */
/*
Copyright(C) 2016 Brazil
Copyright(C) 2016-2017 Brazil
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -173,6 +173,50 @@ command_object_inspect_table(grn_ctx *ctx, grn_obj *obj)
grn_ctx_output_map_close(ctx);
}

static void
command_object_inspect_column_name(grn_ctx *ctx, grn_obj *column)
{
char name[GRN_TABLE_MAX_KEY_SIZE];
int name_size;

name_size = grn_column_name(ctx, column, name, GRN_TABLE_MAX_KEY_SIZE);
name[name_size] = '\0';
grn_ctx_output_str(ctx, name, name_size);
}

static void
command_object_inspect_column_value(grn_ctx *ctx, grn_obj *column)
{
grn_ctx_output_map_open(ctx, "value", 1);
{
grn_id range_id = grn_obj_get_range(ctx, column);
grn_ctx_output_cstr(ctx, "type");
command_object_inspect_type(ctx, grn_ctx_at(ctx, range_id));
}
grn_ctx_output_map_close(ctx);
}

static void
command_object_inspect_column(grn_ctx *ctx, grn_obj *obj)
{
grn_ctx_output_map_open(ctx, "column", 5);
{
grn_ctx_output_cstr(ctx, "id");
grn_ctx_output_uint64(ctx, grn_obj_id(ctx, obj));
grn_ctx_output_cstr(ctx, "name");
command_object_inspect_column_name(ctx, obj);
grn_ctx_output_cstr(ctx, "table");
command_object_inspect_table(ctx, grn_ctx_at(ctx, obj->header.domain));
grn_ctx_output_cstr(ctx, "full_name");
command_object_inspect_obj_name(ctx, obj);
grn_ctx_output_cstr(ctx, "type");
command_object_inspect_obj_type(ctx, obj->header.type);
grn_ctx_output_cstr(ctx, "value");
command_object_inspect_column_value(ctx, obj);
}
grn_ctx_output_map_close(ctx);
}

static void
command_object_inspect_db(grn_ctx *ctx, grn_obj *obj)
{
Expand Down Expand Up @@ -201,6 +245,11 @@ command_object_inspect_dispatch(grn_ctx *ctx, grn_obj *obj)
case GRN_TABLE_NO_KEY :
command_object_inspect_table(ctx, obj);
break;
case GRN_COLUMN_FIX_SIZE :
case GRN_COLUMN_VAR_SIZE :
case GRN_COLUMN_INDEX :
command_object_inspect_column(ctx, obj);
break;
case GRN_DB :
command_object_inspect_db(ctx, obj);
break;
Expand Down
63 changes: 63 additions & 0 deletions test/command/suite/object_inspect/column/index.expected
@@ -0,0 +1,63 @@
table_create Memos TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Memos title COLUMN_SCALAR ShortText
[[0,0.0,0.0],true]
column_create Memos content COLUMN_SCALAR Text
[[0,0.0,0.0],true]
table_create Terms TABLE_PAT_KEY ShortText --normalizer NormalizerAuto --default_tokenizer TokenBigram
[[0,0.0,0.0],true]
column_create Terms memos_title_content COLUMN_INDEX|WITH_POSITION|WITH_SECTION Memos title,content
[[0,0.0,0.0],true]
object_inspect Terms.memos_title_content
[
[
0,
0.0,
0.0
],
{
"id": 260,
"name": "memos_title_content",
"table": {
"id": 259,
"name": "Terms",
"type": {
"id": 49,
"name": "table:pat_key"
},
"key": {
"type": {
"id": 14,
"name": "ShortText",
"type": {
"id": 32,
"name": "type"
},
"size": 4096
},
"total_size": 0,
"max_total_size": 4294967294
},
"value": {
"type": null
},
"n_records": 0
},
"full_name": "Terms.memos_title_content",
"type": {
"id": 72,
"name": "column:index"
},
"value": {
"type": {
"id": 256,
"name": "Memos",
"type": {
"id": 51,
"name": "table:no_key"
},
"size": 4
}
}
}
]
12 changes: 12 additions & 0 deletions test/command/suite/object_inspect/column/index.test
@@ -0,0 +1,12 @@
table_create Memos TABLE_NO_KEY
column_create Memos title COLUMN_SCALAR ShortText
column_create Memos content COLUMN_SCALAR Text

table_create Terms TABLE_PAT_KEY ShortText \
--normalizer NormalizerAuto \
--default_tokenizer TokenBigram
column_create Terms memos_title_content \
COLUMN_INDEX|WITH_POSITION|WITH_SECTION \
Memos title,content

object_inspect Terms.memos_title_content
57 changes: 57 additions & 0 deletions test/command/suite/object_inspect/column/scalar_fix.expected
@@ -0,0 +1,57 @@
table_create Users TABLE_HASH_KEY ShortText
[[0,0.0,0.0],true]
column_create Users age COLUMN_SCALAR UInt8
[[0,0.0,0.0],true]
object_inspect Users.age
[
[
0,
0.0,
0.0
],
{
"id": 257,
"name": "age",
"table": {
"id": 256,
"name": "Users",
"type": {
"id": 48,
"name": "table:hash_key"
},
"key": {
"type": {
"id": 14,
"name": "ShortText",
"type": {
"id": 32,
"name": "type"
},
"size": 4096
},
"total_size": 0,
"max_total_size": 4294967295
},
"value": {
"type": null
},
"n_records": 0
},
"full_name": "Users.age",
"type": {
"id": 64,
"name": "column:fix_size"
},
"value": {
"type": {
"id": 5,
"name": "UInt8",
"type": {
"id": 32,
"name": "type"
},
"size": 1
}
}
}
]
4 changes: 4 additions & 0 deletions test/command/suite/object_inspect/column/scalar_fix.test
@@ -0,0 +1,4 @@
table_create Users TABLE_HASH_KEY ShortText
column_create Users age COLUMN_SCALAR UInt8

object_inspect Users.age
45 changes: 45 additions & 0 deletions test/command/suite/object_inspect/column/scalar_var.expected
@@ -0,0 +1,45 @@
table_create Memos TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Memos title COLUMN_SCALAR ShortText
[[0,0.0,0.0],true]
object_inspect Memos.title
[
[
0,
0.0,
0.0
],
{
"id": 257,
"name": "title",
"table": {
"id": 256,
"name": "Memos",
"type": {
"id": 51,
"name": "table:no_key"
},
"key": null,
"value": {
"type": null
},
"n_records": 0
},
"full_name": "Memos.title",
"type": {
"id": 65,
"name": "column:var_size"
},
"value": {
"type": {
"id": 14,
"name": "ShortText",
"type": {
"id": 32,
"name": "type"
},
"size": 4096
}
}
}
]
4 changes: 4 additions & 0 deletions test/command/suite/object_inspect/column/scalar_var.test
@@ -0,0 +1,4 @@
table_create Memos TABLE_NO_KEY
column_create Memos title COLUMN_SCALAR ShortText

object_inspect Memos.title
45 changes: 45 additions & 0 deletions test/command/suite/object_inspect/column/vector.expected
@@ -0,0 +1,45 @@
table_create Memos TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Memos tags COLUMN_VECTOR ShortText
[[0,0.0,0.0],true]
object_inspect Memos.tags
[
[
0,
0.0,
0.0
],
{
"id": 257,
"name": "tags",
"table": {
"id": 256,
"name": "Memos",
"type": {
"id": 51,
"name": "table:no_key"
},
"key": null,
"value": {
"type": null
},
"n_records": 0
},
"full_name": "Memos.tags",
"type": {
"id": 65,
"name": "column:var_size"
},
"value": {
"type": {
"id": 14,
"name": "ShortText",
"type": {
"id": 32,
"name": "type"
},
"size": 4096
}
}
}
]
4 changes: 4 additions & 0 deletions test/command/suite/object_inspect/column/vector.test
@@ -0,0 +1,4 @@
table_create Memos TABLE_NO_KEY
column_create Memos tags COLUMN_VECTOR ShortText

object_inspect Memos.tags

0 comments on commit dac6d10

Please sign in to comment.