[Groonga-commit] groonga/groonga at c641bc3 [master] logical_select: add support for loading result to table

Back to archive index
Kouhei Sutou null+****@clear*****
Tue Dec 25 17:03:47 JST 2018


Kouhei Sutou	2018-12-25 17:03:47 +0900 (Tue, 25 Dec 2018)

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

  Message:
    logical_select: add support for loading result to table
    
    New options:
    
      * load_table
      * load_columns
      * load_values
    
    TODO:
    
      * More tests
      * Dynamic _key generation from source table column

  Added files:
    test/command/suite/sharding/logical_select/load_table/no_key.expected
    test/command/suite/sharding/logical_select/load_table/no_key.test
  Modified files:
    plugins/sharding/logical_select.rb

  Modified: plugins/sharding/logical_select.rb (+42 -1)
===================================================================
--- plugins/sharding/logical_select.rb    2018-12-25 17:01:50 +0900 (e990fc239)
+++ plugins/sharding/logical_select.rb    2018-12-25 17:03:47 +0900 (d47e6f1f6)
@@ -28,7 +28,9 @@ module Groonga
                  "match_columns",
                  "query",
                  "drilldown_filter",
-                 "post_filter",
+                 "load_table",
+                 "load_columns",
+                 "load_values",
                ])
 
       def run_body(input)
@@ -89,6 +91,9 @@ module Groonga
         key << "#{input[:drilldown_calc_target]}\0"
         key << "#{input[:drilldown_filter]}\0"
         key << "#{input[:post_filter]}\0"
+        key << "#{input[:load_table]}\0"
+        key << "#{input[:load_columns]}\0"
+        key << "#{input[:load_values]}\0"
         labeled_drilldowns = LabeledDrilldowns.parse(input).sort_by(&:label)
         labeled_drilldowns.each do |drilldown|
           key << "#{drilldown.label}\0"
@@ -275,6 +280,9 @@ module Groonga
         attr_reader :sort_keys
         attr_reader :output_columns
         attr_reader :post_filter
+        attr_reader :load_table
+        attr_reader :load_columns
+        attr_reader :load_values
         attr_reader :dynamic_columns
         attr_reader :result_sets
         attr_reader :plain_drilldown
@@ -292,6 +300,9 @@ module Groonga
           @sort_keys = parse_keys(@input[:sort_keys] || @input[:sortby])
           @output_columns = @input[:output_columns] || "_id, _key, *"
           @post_filter = @input[:post_filter]
+          @load_table = @input[:load_table]
+          @load_columns = @input[:load_columns]
+          @load_values = @input[:load_values]
 
           @dynamic_columns = DynamicColumns.parse(@input)
 
@@ -531,6 +542,7 @@ module Groonga
 
         def execute
           execute_search
+          execute_load_table
           if****@conte*****_drilldown.have_keys?
             execute_plain_drilldown
           elsif****@conte*****_drilldowns.have_keys?
@@ -568,6 +580,35 @@ module Groonga
           end
         end
 
+        def execute_load_table
+          load_table =****@conte*****_table
+          load_columns =****@conte*****_columns
+          load_values =****@conte*****_values
+          return if load_table.nil?
+          return if load_columns.nil?
+          return if load_values.nil?
+
+          to = Context.instance[load_table]
+          to_columns = []
+          begin
+            load_columns.split(/\s*,\s*/).each do |name|
+              to_columns << to.find_column(name)
+            end
+            @context.result_sets.each do |result_set|
+              output_columns = result_set.parse_output_columns(load_values)
+              begin
+                output_columns.apply(to_columns)
+              ensure
+                output_columns.close
+              end
+            end
+          ensure
+            to_columns.each do |column|
+              column.close if column.is_a?(Accessor)
+            end
+          end
+        end
+
         def execute_plain_drilldown
           drilldown =****@conte*****_drilldown
           group_result = TableGroupResult.new

  Added: test/command/suite/sharding/logical_select/load_table/no_key.expected (+114 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/load_table/no_key.expected    2018-12-25 17:03:47 +0900 (8fd2eec2b)
@@ -0,0 +1,114 @@
+plugin_register sharding
+[[0,0.0,0.0],true]
+table_create Logs_20150203 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create Logs_20150204 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20150204 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create Logs TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs original_id COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create Logs timestamp_text COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Logs_20150203
+[
+{
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "timestamp": "2015-02-03 12:49:00"
+}
+]
+[[0,0.0,0.0],2]
+load --table Logs_20150204
+[
+{
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+[[0,0.0,0.0],1]
+logical_select   --logical_table Logs   --shard_key timestamp   --load_table Logs   --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
+      ],
+      [
+        1,
+        1422975600.0
+      ]
+    ]
+  ]
+]
+select --table Logs
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "original_id",
+          "UInt32"
+        ],
+        [
+          "timestamp_text",
+          "ShortText"
+        ]
+      ],
+      [
+        1,
+        1,
+        "1422928140000000"
+      ],
+      [
+        2,
+        2,
+        "1422935340000000"
+      ],
+      [
+        3,
+        1,
+        "1422975600000000"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/sharding/logical_select/load_table/no_key.test (+39 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/load_table/no_key.test    2018-12-25 17:03:47 +0900 (cc89c90db)
@@ -0,0 +1,39 @@
+#@on-error omit
+plugin_register sharding
+#@on-error default
+
+table_create Logs_20150203 TABLE_NO_KEY
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+
+table_create Logs_20150204 TABLE_NO_KEY
+column_create Logs_20150204 timestamp COLUMN_SCALAR Time
+
+table_create Logs TABLE_NO_KEY
+column_create Logs original_id COLUMN_SCALAR UInt32
+column_create Logs timestamp_text COLUMN_SCALAR ShortText
+
+load --table Logs_20150203
+[
+{
+  "timestamp": "2015-02-03 10:49:00"
+},
+{
+  "timestamp": "2015-02-03 12:49:00"
+}
+]
+
+load --table Logs_20150204
+[
+{
+  "timestamp": "2015-02-04 00:00:00"
+}
+]
+
+logical_select \
+  --logical_table Logs \
+  --shard_key timestamp \
+  --load_table Logs \
+  --load_columns "original_id, timestamp_text" \
+  --load_values "_id, timestamp"
+
+select --table Logs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181225/4cb208a0/attachment-0001.html>


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