[Groonga-commit] groonga/groonga at d081d46 [master] select: add --load_table, --load_columns and --load_values

アーカイブの一覧に戻る
Kouhei Sutou null+****@clear*****
Fri Mar 15 22:22:42 JST 2019


Kouhei Sutou	2019-03-15 22:22:42 +0900 (Fri, 15 Mar 2019)

  Revision: d081d4614bf005bc92d8cc2623349ee2d13fb924
  https://github.com/groonga/groonga/commit/d081d4614bf005bc92d8cc2623349ee2d13fb924

  Message:
    select: add --load_table, --load_columns and --load_values

  Added files:
    test/command/suite/select/load_table/invalid/missing_key.expected
    test/command/suite/select/load_table/invalid/missing_key.test
    test/command/suite/select/load_table/invalid/multiple_keys.expected
    test/command/suite/select/load_table/invalid/multiple_keys.test
    test/command/suite/select/load_table/invalid/too_few_columns.expected
    test/command/suite/select/load_table/invalid/too_few_columns.test
    test/command/suite/select/load_table/invalid/too_much_columns.expected
    test/command/suite/select/load_table/invalid/too_much_columns.test
    test/command/suite/select/load_table/key.expected
    test/command/suite/select/load_table/key.test
    test/command/suite/select/load_table/no_key.expected
    test/command/suite/select/load_table/no_key.test
  Modified files:
    lib/output_columns.c
    lib/proc/proc_select.c

  Modified: lib/output_columns.c (+5 -1)
===================================================================
--- lib/output_columns.c    2019-03-14 11:10:24 +0900 (9d05a4aaa)
+++ lib/output_columns.c    2019-03-15 22:22:42 +0900 (fed5850a5)
@@ -1,7 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2009-2018 Brazil
-  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
+  Copyright(C) 2018-2019 Kouhei Sutou <kou****@clear*****>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -41,6 +41,10 @@ grn_output_columns_parse(grn_ctx *ctx,
                    GRN_OP_MATCH,
                    GRN_OP_AND,
                    GRN_EXPR_SYNTAX_OUTPUT_COLUMNS);
+    if (ctx->rc != GRN_SUCCESS) {
+      grn_obj_close(ctx, output_columns);
+      output_columns = NULL;
+    }
   }
 
   GRN_API_RETURN(output_columns);

  Modified: lib/proc/proc_select.c (+125 -2)
===================================================================
--- lib/proc/proc_select.c    2019-03-14 11:10:24 +0900 (d2cde577c)
+++ lib/proc/proc_select.c    2019-03-15 22:22:42 +0900 (3f25004e2)
@@ -1,7 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2009-2018 Brazil
-  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
+  Copyright(C) 2018-2019 Kouhei Sutou <kou****@clear*****>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -134,6 +134,11 @@ typedef struct {
     int n_elements;
     grn_select_output_formatter *formatter;
   } output;
+  struct {
+    grn_raw_string table;
+    grn_raw_string columns;
+    grn_raw_string values;
+  } load;
 } grn_select_data;
 
 typedef void grn_select_output_slices_label_func(grn_ctx *ctx,
@@ -1916,6 +1921,102 @@ grn_select_sort(grn_ctx *ctx,
 }
 
 static grn_bool
+grn_select_load(grn_ctx *ctx,
+                grn_select_data *data)
+{
+  grn_obj *table;
+  grn_obj columns;
+  grn_obj *output_columns = NULL;
+
+  if (data->load.table.length == 0) {
+    return GRN_TRUE;
+  }
+  if (data->load.columns.length == 0) {
+    return GRN_TRUE;
+  }
+  if (data->load.values.length == 0) {
+    return GRN_TRUE;
+  }
+
+  table = grn_ctx_get(ctx,
+                      data->load.table.value,
+                      data->load.table.length);
+  if (!table) {
+    GRN_PLUGIN_ERROR(ctx,
+                     ctx->rc,
+                     "[select][load] "
+                     "nonexistent load table: <%.*s>",
+                     (int)(data->load.table.length),
+                     data->load.table.value);
+    return GRN_FALSE;
+  }
+
+  GRN_PTR_INIT(&columns, GRN_OBJ_VECTOR, GRN_ID_NIL);
+  grn_obj_columns(ctx,
+                  table,
+                  data->load.columns.value,
+                  data->load.columns.length,
+                  &columns);
+  if (ctx->rc != GRN_SUCCESS) {
+    GRN_PLUGIN_ERROR(ctx,
+                     ctx->rc,
+                     "[select][load] "
+                     "failed to parse columns: <%.*s>: %s",
+                     (int)(data->load.columns.length),
+                     data->load.columns.value,
+                     ctx->errbuf);
+    goto exit;
+  }
+
+  output_columns = grn_output_columns_parse(ctx,
+                                            data->tables.result,
+                                            data->load.values.value,
+                                            data->load.values.length);
+  if (!output_columns) {
+    GRN_PLUGIN_ERROR(ctx,
+                     ctx->rc,
+                     "[select][load] "
+                     "failed to parse values: <%.*s>: %s",
+                     (int)(data->load.values.length),
+                     data->load.values.value,
+                     ctx->errbuf);
+    goto exit;
+  }
+
+  grn_output_columns_apply(ctx, output_columns, &columns);
+  if (ctx->rc != GRN_SUCCESS) {
+    GRN_PLUGIN_ERROR(ctx,
+                     ctx->rc,
+                     "[select][load] "
+                     "failed to load: <%.*s>: %s",
+                     (int)(data->load.values.length),
+                     data->load.values.value,
+                     ctx->errbuf);
+  }
+
+  GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE,
+                ":", "load(%d)", grn_table_size(ctx, data->tables.result));
+
+exit :
+  if (output_columns) {
+    grn_obj_close(ctx, output_columns);
+  }
+  {
+    size_t i;
+    size_t n_columns = GRN_BULK_VSIZE(&columns) / sizeof(grn_obj *);
+    for (i = 0; i < n_columns; i++) {
+      grn_obj *column = GRN_PTR_VALUE_AT(&columns, i);
+      if (grn_obj_is_accessor(ctx, column)) {
+        grn_obj_close(ctx, column);
+      }
+    }
+    GRN_OBJ_FIN(ctx, &columns);
+  }
+
+  return ctx->rc == GRN_SUCCESS;
+}
+
+static grn_bool
 grn_select_apply_output_columns(grn_ctx *ctx,
                                 grn_select_data *data)
 {
@@ -3176,6 +3277,9 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
     PUT_CACHE_KEY(data->filter.query_flags);
     PUT_CACHE_KEY(data->adjuster);
     PUT_CACHE_KEY(data->match_escalation);
+    PUT_CACHE_KEY(data->load.table);
+    PUT_CACHE_KEY(data->load.columns);
+    PUT_CACHE_KEY(data->load.values);
     grn_memcpy(cp, &output_type, sizeof(grn_content_type));
     cp += sizeof(grn_content_type);
     grn_memcpy(cp, &(data->offset), sizeof(int));
@@ -3308,6 +3412,10 @@ grn_select(grn_ctx *ctx, grn_select_data *data)
         goto exit;
       }
 
+      if (!grn_select_load(ctx, data)) {
+        goto exit;
+      }
+
       if (!grn_select_apply_output_columns(ctx, data)) {
         goto exit;
       }
@@ -3801,6 +3909,18 @@ command_select(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data
     grn_plugin_proc_get_var_string(ctx, user_data,
                                    "match_escalation", -1,
                                    &(data.match_escalation.length));
+  data.load.table.value =
+    grn_plugin_proc_get_var_string(ctx, user_data,
+                                   "load_table", -1,
+                                   &(data.load.table.length));
+  data.load.columns.value =
+    grn_plugin_proc_get_var_string(ctx, user_data,
+                                   "load_columns", -1,
+                                   &(data.load.columns.length));
+  data.load.values.value =
+    grn_plugin_proc_get_var_string(ctx, user_data,
+                                   "load_values", -1,
+                                   &(data.load.values.length));
 
   if (!grn_select_data_fill_slices(ctx, user_data, &data)) {
     goto exit;
@@ -3870,7 +3990,7 @@ exit :
   return NULL;
 }
 
-#define N_VARS 28
+#define N_VARS 31
 #define DEFINE_VARS grn_expr_var vars[N_VARS]
 
 static void
@@ -3907,6 +4027,9 @@ init_vars(grn_ctx *ctx, grn_expr_var *vars)
   grn_plugin_expr_var_init(ctx, &(vars[25]), "drilldown_sort_keys", -1);
   grn_plugin_expr_var_init(ctx, &(vars[26]), "drilldown_adjuster", -1);
   grn_plugin_expr_var_init(ctx, &(vars[27]), "match_escalation", -1);
+  grn_plugin_expr_var_init(ctx, &(vars[28]), "load_table", -1);
+  grn_plugin_expr_var_init(ctx, &(vars[29]), "load_columns", -1);
+  grn_plugin_expr_var_init(ctx, &(vars[30]), "load_values", -1);
 }
 
 void

  Added: test/command/suite/select/load_table/invalid/missing_key.expected (+72 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/invalid/missing_key.expected    2019-03-15 22:22:42 +0900 (be22f1ff4)
@@ -0,0 +1,72 @@
+table_create Logs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Logs timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+[[0,0.0,0.0],3]
+select   Logs   --load_table LoadedLogs   --load_columns "original_id, timestamp_text"   --load_values "_id, timestamp"
+[
+  [
+    [
+      -22,
+      0.0,
+      0.0
+    ],
+    "[select][load] failed to load: <_id, timestamp>: [output-columns][apply] _key must be specified: [<LoadedLogs.original_id>, <Lo"
+  ]
+]
+#|e| [output-columns][apply] _key must be specified: [<LoadedLogs.original_id>, <LoadedLogs.timestamp_text>]
+#|e| [select][load] failed to load: <_id, timestamp>: [output-columns][apply] _key must be specified: [<LoadedLogs.original_id>, <LoadedLogs.timestamp_text>]
+select --table LoadedLogs
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        0
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "original_id",
+          "UInt32"
+        ],
+        [
+          "timestamp_text",
+          "ShortText"
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/load_table/invalid/missing_key.test (+30 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/invalid/missing_key.test    2019-03-15 22:22:42 +0900 (da0fb0e75)
@@ -0,0 +1,30 @@
+table_create Logs TABLE_HASH_KEY ShortText
+column_create Logs timestamp COLUMN_SCALAR Time
+
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+
+select \
+  Logs \
+  --load_table LoadedLogs \
+  --load_columns "original_id, timestamp_text" \
+  --load_values "_id, timestamp"
+
+select --table LoadedLogs

  Added: test/command/suite/select/load_table/invalid/multiple_keys.expected (+72 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/invalid/multiple_keys.expected    2019-03-15 22:22:42 +0900 (1916baaca)
@@ -0,0 +1,72 @@
+table_create Logs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Logs timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+[[0,0.0,0.0],3]
+select   Logs   --load_table LoadedLogs   --load_columns "original_id, _key, timestamp_text, _key"   --load_values "_id, _id, timestamp, _id"
+[
+  [
+    [
+      -22,
+      0.0,
+      0.0
+    ],
+    "[select][load] failed to load: <_id, _id, timestamp, _id>: [output-columns][apply] _key is specified multiple times: [<LoadedLo"
+  ]
+]
+#|e| [output-columns][apply] _key is specified multiple times: [<LoadedLogs.original_id>, #<accessor _key(LoadedLogs)>, <LoadedLogs.timestamp_text>, #<accessor _key(LoadedLogs)>]
+#|e| [select][load] failed to load: <_id, _id, timestamp, _id>: [output-columns][apply] _key is specified multiple times: [<LoadedLogs.original_id>, #<accessor _key(LoadedLogs)>, <LoadedLogs.
+select --table LoadedLogs
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        0
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "original_id",
+          "UInt32"
+        ],
+        [
+          "timestamp_text",
+          "ShortText"
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/load_table/invalid/multiple_keys.test (+30 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/invalid/multiple_keys.test    2019-03-15 22:22:42 +0900 (061e16c1a)
@@ -0,0 +1,30 @@
+table_create Logs TABLE_HASH_KEY ShortText
+column_create Logs timestamp COLUMN_SCALAR Time
+
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+
+select \
+  Logs \
+  --load_table LoadedLogs \
+  --load_columns "original_id, _key, timestamp_text, _key" \
+  --load_values "_id, _id, timestamp, _id"
+
+select --table LoadedLogs

  Added: test/command/suite/select/load_table/invalid/too_few_columns.expected (+72 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/invalid/too_few_columns.expected    2019-03-15 22:22:42 +0900 (806579b2a)
@@ -0,0 +1,72 @@
+table_create Logs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Logs timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+[[0,0.0,0.0],3]
+select   Logs   --load_table LoadedLogs   --load_columns "_key"   --load_values "_id, timestamp"
+[
+  [
+    [
+      -22,
+      0.0,
+      0.0
+    ],
+    "[select][load] failed to load: <_id, timestamp>: [output-columns][apply] the number of columns (1) must be 2: [#<accessor _key("
+  ]
+]
+#|e| [output-columns][apply] the number of columns (1) must be 2: [#<accessor _key(LoadedLogs)>]
+#|e| [select][load] failed to load: <_id, timestamp>: [output-columns][apply] the number of columns (1) must be 2: [#<accessor _key(LoadedLogs)>]
+select --table LoadedLogs
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        0
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "original_id",
+          "UInt32"
+        ],
+        [
+          "timestamp_text",
+          "ShortText"
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/load_table/invalid/too_few_columns.test (+30 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/invalid/too_few_columns.test    2019-03-15 22:22:42 +0900 (4f8d87609)
@@ -0,0 +1,30 @@
+table_create Logs TABLE_HASH_KEY ShortText
+column_create Logs timestamp COLUMN_SCALAR Time
+
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+
+select \
+  Logs \
+  --load_table LoadedLogs \
+  --load_columns "_key" \
+  --load_values "_id, timestamp"
+
+select --table LoadedLogs

  Added: test/command/suite/select/load_table/invalid/too_much_columns.expected (+72 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/invalid/too_much_columns.expected    2019-03-15 22:22:42 +0900 (f9622a691)
@@ -0,0 +1,72 @@
+table_create Logs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Logs timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+[[0,0.0,0.0],3]
+select   Logs   --load_table LoadedLogs   --load_columns "original_id, timestamp_text, _key"   --load_values "_id, timestamp"
+[
+  [
+    [
+      -22,
+      0.0,
+      0.0
+    ],
+    "[select][load] failed to load: <_id, timestamp>: [output-columns][apply] the number of columns (3) must be 2: [<LoadedLogs.orig"
+  ]
+]
+#|e| [output-columns][apply] the number of columns (3) must be 2: [<LoadedLogs.original_id>, <LoadedLogs.timestamp_text>, #<accessor _key(LoadedLogs)>]
+#|e| [select][load] failed to load: <_id, timestamp>: [output-columns][apply] the number of columns (3) must be 2: [<LoadedLogs.original_id>, <LoadedLogs.timestamp_text>, #<accessor
+select --table LoadedLogs
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        0
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "original_id",
+          "UInt32"
+        ],
+        [
+          "timestamp_text",
+          "ShortText"
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/load_table/invalid/too_much_columns.test (+30 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/invalid/too_much_columns.test    2019-03-15 22:22:42 +0900 (583444797)
@@ -0,0 +1,30 @@
+table_create Logs TABLE_HASH_KEY ShortText
+column_create Logs timestamp COLUMN_SCALAR Time
+
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+
+select \
+  Logs \
+  --load_table LoadedLogs \
+  --load_columns "original_id, timestamp_text, _key" \
+  --load_values "_id, timestamp"
+
+select --table LoadedLogs

  Added: test/command/suite/select/load_table/key.expected (+126 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/key.expected    2019-03-15 22:22:42 +0900 (09b993d2e)
@@ -0,0 +1,126 @@
+table_create Logs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Logs timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+[[0,0.0,0.0],3]
+select   Logs   --load_table LoadedLogs   --load_columns "_key, original_id, timestamp_text"   --load_values "cast_loose(ShortText, timestamp, '') + ':' + _id, _id, timestamp"
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "timestamp",
+          "Time"
+        ]
+      ],
+      [
+        1,
+        "2015-02-03:1",
+        1422928140.0
+      ],
+      [
+        2,
+        "2015-02-03:2",
+        1422935340.0
+      ],
+      [
+        3,
+        "2015-02-04:1",
+        1422975600.0
+      ]
+    ]
+  ]
+]
+#>select --load_columns "_key, original_id, timestamp_text" --load_table "LoadedLogs" --load_values "cast_loose(ShortText, timestamp, '') + ':' + _id, _id, timestamp" --table "Logs"
+#:000000000000000 select(3)
+#:000000000000000 load(3)
+#:000000000000000 output(3)
+#<000000000000000 rc=0
+select --table LoadedLogs
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "original_id",
+          "UInt32"
+        ],
+        [
+          "timestamp_text",
+          "ShortText"
+        ]
+      ],
+      [
+        1,
+        "1422928140000000:1",
+        1,
+        "1422928140000000"
+      ],
+      [
+        2,
+        "1422935340000000:2",
+        2,
+        "1422935340000000"
+      ],
+      [
+        3,
+        "1422975600000000:3",
+        3,
+        "1422975600000000"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/load_table/key.test (+32 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/key.test    2019-03-15 22:22:42 +0900 (fdaeb6010)
@@ -0,0 +1,32 @@
+table_create Logs TABLE_HASH_KEY ShortText
+column_create Logs timestamp COLUMN_SCALAR Time
+
+table_create LoadedLogs TABLE_HASH_KEY ShortText
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+
+load --table Logs
+[
+{
+  "_key": "2015-02-03:1",
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "_key": "2015-02-03:2",
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "_key": "2015-02-04:1",
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+
+#@collect-query-log true
+select \
+  Logs \
+  --load_table LoadedLogs \
+  --load_columns "_key, original_id, timestamp_text" \
+  --load_values "cast_loose(ShortText, timestamp, '') + ':' + _id, _id, timestamp"
+#@collect-query-log false
+
+select --table LoadedLogs

  Added: test/command/suite/select/load_table/no_key.expected (+104 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/no_key.expected    2019-03-15 22:22:42 +0900 (08e993290)
@@ -0,0 +1,104 @@
+table_create Logs TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create LoadedLogs TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Logs
+[
+{
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+[[0,0.0,0.0],3]
+select   Logs   --load_table LoadedLogs   --load_columns "original_id, timestamp_text"   --load_values "_id, timestamp"
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "timestamp",
+          "Time"
+        ]
+      ],
+      [
+        1,
+        1422928140.0
+      ],
+      [
+        2,
+        1422935340.0
+      ],
+      [
+        3,
+        1422975600.0
+      ]
+    ]
+  ]
+]
+select --table LoadedLogs
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "original_id",
+          "UInt32"
+        ],
+        [
+          "timestamp_text",
+          "ShortText"
+        ]
+      ],
+      [
+        1,
+        1,
+        "1422928140000000"
+      ],
+      [
+        2,
+        2,
+        "1422935340000000"
+      ],
+      [
+        3,
+        3,
+        "1422975600000000"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/load_table/no_key.test (+27 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/load_table/no_key.test    2019-03-15 22:22:42 +0900 (a64ff5927)
@@ -0,0 +1,27 @@
+table_create Logs TABLE_NO_KEY
+column_create Logs timestamp COLUMN_SCALAR Time
+
+table_create LoadedLogs TABLE_NO_KEY
+column_create LoadedLogs original_id COLUMN_SCALAR UInt32
+column_create LoadedLogs timestamp_text COLUMN_SCALAR ShortText
+
+load --table Logs
+[
+{
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "timestamp": "2015-02-03 12:49:00"
+},
+{
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+
+select \
+  Logs \
+  --load_table LoadedLogs \
+  --load_columns "original_id, timestamp_text" \
+  --load_values "_id, timestamp"
+
+select --table LoadedLogs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190315/dd49a798/attachment-0001.html>


More information about the Groonga-commit mailing list
アーカイブの一覧に戻る