[Groonga-commit] groonga/groonga at a7bc94d [master] logical_select: support sortby partially

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jul 6 23:15:17 JST 2015


Kouhei Sutou	2015-07-06 23:15:17 +0900 (Mon, 06 Jul 2015)

  New Revision: a7bc94d96da39b9108529822aba4a98e757f3305
  https://github.com/groonga/groonga/commit/a7bc94d96da39b9108529822aba4a98e757f3305

  Message:
    logical_select: support sortby partially
    
    Sorting by shard key ascending is only supported.

  Added files:
    test/command/suite/sharding/logical_select/sortby/shard_key/ascending.expected
    test/command/suite/sharding/logical_select/sortby/shard_key/ascending.test
  Modified files:
    plugins/sharding/logical_select.rb

  Modified: plugins/sharding/logical_select.rb (+21 -2)
===================================================================
--- plugins/sharding/logical_select.rb    2015-07-06 22:56:49 +0900 (b4f0139)
+++ plugins/sharding/logical_select.rb    2015-07-06 23:15:17 +0900 (31ee612)
@@ -177,6 +177,7 @@ module Groonga
         attr_reader :sort_keys
         attr_reader :output_columns
         attr_reader :result_sets
+        attr_reader :unsorted_result_sets
         attr_reader :plain_drilldown
         attr_reader :labeled_drilldowns
         def initialize(input)
@@ -189,6 +190,7 @@ module Groonga
           @output_columns = @input[:output_columns] || "_key, *"
 
           @result_sets = []
+          @unsorted_result_sets = []
 
           @plain_drilldown = PlainDrilldownExecuteContext.new(@input)
           @labeled_drilldowns = LabeledDrilldowns.parse(@input)
@@ -198,6 +200,9 @@ module Groonga
           @result_sets.each do |result_set|
             result_set.close if result_set.temporary?
           end
+          @unsorted_result_sets.each do |result_set|
+            result_set.close if result_set.temporary?
+          end
 
           @plain_drilldown.close
           @labeled_drilldowns.close
@@ -512,7 +517,9 @@ module Groonga
           @shard_range = shard_range
 
           @filter =****@conte*****
+          @sort_keys =****@conte*****_keys
           @result_sets =****@conte*****_sets
+          @unsorted_result_sets =****@conte*****_result_sets
 
           @target_range =****@conte*****_range
 
@@ -547,7 +554,7 @@ module Groonga
         private
         def filter_shard_all
           if****@filte*****?
-            @result_sets << @table
+            add_result_set(@table)
           else
             filter_table do |expression|
               @expression_builder.build_all(expression)
@@ -567,7 +574,19 @@ module Groonga
         def filter_table
           create_expression(@table) do |expression|
             yield(expression)
-            @result_sets << @table.select(expression)
+            add_result_set(@table.select(expression))
+          end
+        end
+
+        def add_result_set(result_set)
+          return if result_set.empty?
+
+          if @sort_keys
+            @unsorted_result_sets << result_set
+            sorted_result_set = result_set.sort(@sort_keys)
+            @result_sets << sorted_result_set
+          else
+            @result_sets << result_set
           end
         end
       end

  Added: test/command/suite/sharding/logical_select/sortby/shard_key/ascending.expected (+129 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/sortby/shard_key/ascending.expected    2015-07-06 23:15:17 +0900 (9e48299)
@@ -0,0 +1,129 @@
+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]
+column_create Logs_20150203 memo COLUMN_SCALAR ShortText
+[[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]
+column_create Logs_20150204 memo COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+table_create Logs_20150205 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20150205 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20150205 memo COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Logs_20150203
+[
+{
+  "timestamp": "2015-02-03 23:59:59",
+  "memo":      "2015-02-03 23:59:59"
+},
+{
+  "timestamp": "2015-02-03 12:49:00",
+  "memo":      "2015-02-03 12:49:00"
+}
+]
+[[0,0.0,0.0],2]
+load --table Logs_20150204
+[
+{
+  "timestamp": "2015-02-04 00:00:00",
+  "memo":      "2015-02-04 00:00:00"
+},
+{
+  "timestamp": "2015-02-04 13:50:00",
+  "memo":      "2015-02-04 13:50:00"
+},
+{
+  "timestamp": "2015-02-04 13:49:00",
+  "memo":      "2015-02-04 13:49:00"
+}
+]
+[[0,0.0,0.0],3]
+load --table Logs_20150205
+[
+{
+  "timestamp": "2015-02-05 13:52:00",
+  "memo":      "2015-02-05 13:52:00"
+},
+{
+  "timestamp": "2015-02-05 13:51:00",
+  "memo":      "2015-02-05 13:51:00"
+},
+{
+  "timestamp": "2015-02-05 13:50:00",
+  "memo":      "2015-02-05 13:50:00"
+},
+{
+  "timestamp": "2015-02-05 13:49:00",
+  "memo":      "2015-02-05 13:49:00"
+}
+]
+[[0,0.0,0.0],4]
+logical_select Logs timestamp   --sortby timestamp
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "memo",
+          "ShortText"
+        ],
+        [
+          "timestamp",
+          "Time"
+        ]
+      ],
+      [
+        "2015-02-03 12:49:00",
+        1422935340.0
+      ],
+      [
+        "2015-02-03 23:59:59",
+        1422975599.0
+      ],
+      [
+        "2015-02-04 00:00:00",
+        1422975600.0
+      ],
+      [
+        "2015-02-04 13:49:00",
+        1423025340.0
+      ],
+      [
+        "2015-02-04 13:50:00",
+        1423025400.0
+      ],
+      [
+        "2015-02-05 13:49:00",
+        1423111740.0
+      ],
+      [
+        "2015-02-05 13:50:00",
+        1423111800.0
+      ],
+      [
+        "2015-02-05 13:51:00",
+        1423111860.0
+      ],
+      [
+        "2015-02-05 13:52:00",
+        1423111920.0
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/sharding/logical_select/sortby/shard_key/ascending.test (+66 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/sortby/shard_key/ascending.test    2015-07-06 23:15:17 +0900 (210b391)
@@ -0,0 +1,66 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Logs_20150203 TABLE_NO_KEY
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+column_create Logs_20150203 memo COLUMN_SCALAR ShortText
+
+table_create Logs_20150204 TABLE_NO_KEY
+column_create Logs_20150204 timestamp COLUMN_SCALAR Time
+column_create Logs_20150204 memo COLUMN_SCALAR ShortText
+
+table_create Logs_20150205 TABLE_NO_KEY
+column_create Logs_20150205 timestamp COLUMN_SCALAR Time
+column_create Logs_20150205 memo COLUMN_SCALAR ShortText
+
+load --table Logs_20150203
+[
+{
+  "timestamp": "2015-02-03 23:59:59",
+  "memo":      "2015-02-03 23:59:59"
+},
+{
+  "timestamp": "2015-02-03 12:49:00",
+  "memo":      "2015-02-03 12:49:00"
+}
+]
+
+load --table Logs_20150204
+[
+{
+  "timestamp": "2015-02-04 00:00:00",
+  "memo":      "2015-02-04 00:00:00"
+},
+{
+  "timestamp": "2015-02-04 13:50:00",
+  "memo":      "2015-02-04 13:50:00"
+},
+{
+  "timestamp": "2015-02-04 13:49:00",
+  "memo":      "2015-02-04 13:49:00"
+}
+]
+
+load --table Logs_20150205
+[
+{
+  "timestamp": "2015-02-05 13:52:00",
+  "memo":      "2015-02-05 13:52:00"
+},
+{
+  "timestamp": "2015-02-05 13:51:00",
+  "memo":      "2015-02-05 13:51:00"
+},
+{
+  "timestamp": "2015-02-05 13:50:00",
+  "memo":      "2015-02-05 13:50:00"
+},
+{
+  "timestamp": "2015-02-05 13:49:00",
+  "memo":      "2015-02-05 13:49:00"
+}
+]
+
+logical_select Logs timestamp \
+  --sortby timestamp
-------------- next part --------------
HTML����������������������������...
Descargar 



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