[Groonga-commit] groonga/groonga at 4768c70 [master] schema: support types

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Oct 19 14:46:23 JST 2015


Kouhei Sutou	2015-10-19 14:46:23 +0900 (Mon, 19 Oct 2015)

  New Revision: 4768c700811c4ef252fbc37c95791f1f8746d171
  https://github.com/groonga/groonga/commit/4768c700811c4ef252fbc37c95791f1f8746d171

  Message:
    schema: support types

  Modified files:
    lib/proc.c
    test/command/suite/schema/plugins.expected
  Renamed files:
    test/command/suite/schema/plugins.test
      (from test/command/suite/schema/plugins.grn)

  Modified: lib/proc.c (+48 -3)
===================================================================
--- lib/proc.c    2015-10-19 14:31:14 +0900 (b67c49e)
+++ lib/proc.c    2015-10-19 14:46:23 +0900 (4e4a661)
@@ -7305,26 +7305,71 @@ proc_schema_plugins(grn_ctx *ctx)
   GRN_OUTPUT_CSTR("plugins");
 
   n = grn_vector_size(ctx, &plugin_names);
-  GRN_OUTPUT_MAP_OPEN("plugin", n);
+  GRN_OUTPUT_ARRAY_OPEN("plugins", n);
   for (i = 0; i < n; i++) {
     const char *name;
     unsigned int name_size;
 
+    GRN_OUTPUT_MAP_OPEN("plugin", 1);
     name_size = grn_vector_get_element(ctx, &plugin_names, i, &name, NULL, NULL);
     GRN_OUTPUT_CSTR("name");
     GRN_OUTPUT_STR(name, name_size);
+    GRN_OUTPUT_MAP_CLOSE();
   }
-  GRN_OUTPUT_MAP_CLOSE();
+  GRN_OUTPUT_ARRAY_CLOSE();
 
   GRN_OBJ_FIN(ctx, &plugin_names);
 }
 
+static void
+proc_schema_types(grn_ctx *ctx)
+{
+  grn_obj types;
+  unsigned int i, n;
+
+  GRN_PTR_INIT(&types, GRN_OBJ_VECTOR, GRN_DB_OBJECT);
+
+  grn_ctx_get_all_types(ctx, &types);
+
+  GRN_OUTPUT_CSTR("types");
+
+  n = GRN_BULK_VSIZE(&types) / sizeof(grn_obj *);
+  GRN_OUTPUT_ARRAY_OPEN("types", n - 1);
+  for (i = 0; i < n; i++) {
+    grn_obj *type;
+
+    type = GRN_PTR_VALUE_AT(&types, i);
+
+    GRN_OUTPUT_MAP_OPEN("type", 3);
+    {
+      char name[GRN_TABLE_MAX_KEY_SIZE];
+      unsigned int name_size;
+      name_size = grn_obj_name(ctx, type, name, GRN_TABLE_MAX_KEY_SIZE);
+      GRN_OUTPUT_CSTR("name");
+      GRN_OUTPUT_STR(name, name_size);
+    }
+    {
+      GRN_OUTPUT_CSTR("size");
+      GRN_OUTPUT_INT64(GRN_TYPE_SIZE(DB_OBJ(type)));
+    }
+    {
+      GRN_OUTPUT_CSTR("can_be_key_type");
+      GRN_OUTPUT_BOOL(GRN_TYPE_SIZE(DB_OBJ(type)) <= GRN_TABLE_MAX_KEY_SIZE);
+    }
+    GRN_OUTPUT_MAP_CLOSE();
+  }
+  GRN_OUTPUT_ARRAY_CLOSE();
+
+  GRN_OBJ_FIN(ctx, &types);
+}
+
 static grn_obj *
 proc_schema(grn_ctx *ctx, int nargs, grn_obj **args,
             grn_user_data *user_data)
 {
-  GRN_OUTPUT_MAP_OPEN("schema", 1);
+  GRN_OUTPUT_MAP_OPEN("schema", 2);
   proc_schema_plugins(ctx);
+  proc_schema_types(ctx);
   GRN_OUTPUT_MAP_CLOSE();
 
   return NULL;

  Modified: test/command/suite/schema/plugins.expected (+101 -1)
===================================================================
--- test/command/suite/schema/plugins.expected    2015-10-19 14:31:14 +0900 (0b2c73d)
+++ test/command/suite/schema/plugins.expected    2015-10-19 14:46:23 +0900 (51b5c48)
@@ -1,4 +1,104 @@
 plugin_register query_expanders/tsv
 [[0,0.0,0.0],true]
 schema
-[[0,0.0,0.0],{"plugins":{"name":"query_expanders/tsv"}}]
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  {
+    "plugins": [
+      {
+        "name": "query_expanders/tsv"
+      }
+    ],
+    "types": [
+      {
+        "name": "Bool",
+        "size": 1,
+        "can_be_key_type": true
+      },
+      {
+        "name": "Float",
+        "size": 8,
+        "can_be_key_type": true
+      },
+      {
+        "name": "Int16",
+        "size": 2,
+        "can_be_key_type": true
+      },
+      {
+        "name": "Int32",
+        "size": 4,
+        "can_be_key_type": true
+      },
+      {
+        "name": "Int64",
+        "size": 8,
+        "can_be_key_type": true
+      },
+      {
+        "name": "Int8",
+        "size": 1,
+        "can_be_key_type": true
+      },
+      {
+        "name": "LongText",
+        "size": 2147483648,
+        "can_be_key_type": false
+      },
+      {
+        "name": "Object",
+        "size": 8,
+        "can_be_key_type": true
+      },
+      {
+        "name": "ShortText",
+        "size": 4096,
+        "can_be_key_type": true
+      },
+      {
+        "name": "Text",
+        "size": 65536,
+        "can_be_key_type": false
+      },
+      {
+        "name": "Time",
+        "size": 8,
+        "can_be_key_type": true
+      },
+      {
+        "name": "TokyoGeoPoint",
+        "size": 8,
+        "can_be_key_type": true
+      },
+      {
+        "name": "UInt16",
+        "size": 2,
+        "can_be_key_type": true
+      },
+      {
+        "name": "UInt32",
+        "size": 4,
+        "can_be_key_type": true
+      },
+      {
+        "name": "UInt64",
+        "size": 8,
+        "can_be_key_type": true
+      },
+      {
+        "name": "UInt8",
+        "size": 1,
+        "can_be_key_type": true
+      },
+      {
+        "name": "WGS84GeoPoint",
+        "size": 8,
+        "can_be_key_type": true
+      }
+    ]
+  }
+]

  Renamed: test/command/suite/schema/plugins.test (+0 -0) 100%
===================================================================
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index