Navigation Menu

Skip to content

Commit

Permalink
schema: start supporting column
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 20, 2015
1 parent 72747a3 commit e365548
Show file tree
Hide file tree
Showing 12 changed files with 547 additions and 1 deletion.
82 changes: 81 additions & 1 deletion lib/proc.c
Expand Up @@ -7305,6 +7305,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)
{
Expand Down Expand Up @@ -7825,6 +7834,74 @@ proc_schema_table_output_command(grn_ctx *ctx, grn_obj *table)
GRN_OBJ_FIN(ctx, &arguments);
}

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)
{
Expand All @@ -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);
Expand All @@ -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();
Expand Down
203 changes: 203 additions & 0 deletions test/command/suite/schema/tables/columns/type/scalar.expected
@@ -0,0 +1,203 @@
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
[
[
0,
0.0,
0.0
],
{
"plugins": {
},
"types": {
"Bool": {
"name": "Bool",
"size": 1,
"can_be_key_type": true,
"can_be_value_type": true
},
"Float": {
"name": "Float",
"size": 8,
"can_be_key_type": true,
"can_be_value_type": true
},
"Int16": {
"name": "Int16",
"size": 2,
"can_be_key_type": true,
"can_be_value_type": true
},
"Int32": {
"name": "Int32",
"size": 4,
"can_be_key_type": true,
"can_be_value_type": true
},
"Int64": {
"name": "Int64",
"size": 8,
"can_be_key_type": true,
"can_be_value_type": true
},
"Int8": {
"name": "Int8",
"size": 1,
"can_be_key_type": true,
"can_be_value_type": true
},
"LongText": {
"name": "LongText",
"size": 2147483648,
"can_be_key_type": false,
"can_be_value_type": false
},
"Object": {
"name": "Object",
"size": 8,
"can_be_key_type": true,
"can_be_value_type": true
},
"ShortText": {
"name": "ShortText",
"size": 4096,
"can_be_key_type": true,
"can_be_value_type": false
},
"Text": {
"name": "Text",
"size": 65536,
"can_be_key_type": false,
"can_be_value_type": false
},
"Time": {
"name": "Time",
"size": 8,
"can_be_key_type": true,
"can_be_value_type": true
},
"TokyoGeoPoint": {
"name": "TokyoGeoPoint",
"size": 8,
"can_be_key_type": true,
"can_be_value_type": true
},
"UInt16": {
"name": "UInt16",
"size": 2,
"can_be_key_type": true,
"can_be_value_type": true
},
"UInt32": {
"name": "UInt32",
"size": 4,
"can_be_key_type": true,
"can_be_value_type": true
},
"UInt64": {
"name": "UInt64",
"size": 8,
"can_be_key_type": true,
"can_be_value_type": true
},
"UInt8": {
"name": "UInt8",
"size": 1,
"can_be_key_type": true,
"can_be_value_type": true
},
"WGS84GeoPoint": {
"name": "WGS84GeoPoint",
"size": 8,
"can_be_key_type": true,
"can_be_value_type": true
}
},
"tokenizers": {
"TokenBigram": {
"name": "TokenBigram"
},
"TokenBigramIgnoreBlank": {
"name": "TokenBigramIgnoreBlank"
},
"TokenBigramIgnoreBlankSplitSymbol": {
"name": "TokenBigramIgnoreBlankSplitSymbol"
},
"TokenBigramIgnoreBlankSplitSymbolAlpha": {
"name": "TokenBigramIgnoreBlankSplitSymbolAlpha"
},
"TokenBigramIgnoreBlankSplitSymbolAlphaDigit": {
"name": "TokenBigramIgnoreBlankSplitSymbolAlphaDigit"
},
"TokenBigramSplitSymbol": {
"name": "TokenBigramSplitSymbol"
},
"TokenBigramSplitSymbolAlpha": {
"name": "TokenBigramSplitSymbolAlpha"
},
"TokenBigramSplitSymbolAlphaDigit": {
"name": "TokenBigramSplitSymbolAlphaDigit"
},
"TokenDelimit": {
"name": "TokenDelimit"
},
"TokenDelimitNull": {
"name": "TokenDelimitNull"
},
"TokenMecab": {
"name": "TokenMecab"
},
"TokenRegexp": {
"name": "TokenRegexp"
},
"TokenTrigram": {
"name": "TokenTrigram"
},
"TokenUnigram": {
"name": "TokenUnigram"
}
},
"normalizers": {
"NormalizerAuto": {
"name": "NormalizerAuto"
},
"NormalizerNFKC51": {
"name": "NormalizerNFKC51"
}
},
"token_filters": {
},
"tables": {
"Logs": {
"name": "Logs",
"type": "array",
"key_type": null,
"value_type": null,
"tokenizer": null,
"normalizer": null,
"token_filters": [

],
"command": {
"name": "table_create",
"arguments": {
"name": "Logs",
"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"
}
}
}
}
}
]
4 changes: 4 additions & 0 deletions test/command/suite/schema/tables/columns/type/scalar.test
@@ -0,0 +1,4 @@
table_create Logs TABLE_NO_KEY
column_create Logs message COLUMN_SCALAR Text

schema

0 comments on commit e365548

Please sign in to comment.