[Groonga-commit] groonga/groonga at 7e2b7cf [master] Added feature that sort the results of `logical_select` in descending order.

Back to archive index

HorimotoYasuhiro null+****@clear*****
Wed Oct 25 19:42:06 JST 2017


HorimotoYasuhiro	2017-10-25 19:42:06 +0900 (Wed, 25 Oct 2017)

  New Revision: 7e2b7cf711b7532280a8a8c2b52f4b42f660c0b7
  https://github.com/groonga/groonga/commit/7e2b7cf711b7532280a8a8c2b52f4b42f660c0b7

  Merged c53e0f9: Merge pull request #773 from komainu8/reverse-logical-select

  Message:
    Added feature that sort the results of `logical_select` in descending order.

  Added files:
    test/command/suite/sharding/logical_select/sort_keys/shard_key/descending.expected
    test/command/suite/sharding/logical_select/sort_keys/shard_key/descending.test
  Modified files:
    lib/mrb/scripts/table.rb
    plugins/sharding/logical_select.rb

  Modified: lib/mrb/scripts/table.rb (+1 -1)
===================================================================
--- lib/mrb/scripts/table.rb    2017-10-24 18:10:39 +0900 (75c918949)
+++ lib/mrb/scripts/table.rb    2017-10-25 19:42:06 +0900 (9caff6e53)
@@ -102,7 +102,7 @@ module Groonga
         order    = key[:order] || order
         offset   = key[:offset] || offset
       else
-        key_name = key
+        key_name = key.dup
       end
 
       case key_name

  Modified: plugins/sharding/logical_select.rb (+5 -0)
===================================================================
--- plugins/sharding/logical_select.rb    2017-10-24 18:10:39 +0900 (07ebf9e8e)
+++ plugins/sharding/logical_select.rb    2017-10-25 19:42:06 +0900 (cb77320c2)
@@ -152,6 +152,11 @@ module Groonga
             :offset => current_offset,
             :limit => current_limit,
           }
+          context.sort_keys.each do |sort_key|
+            if sort_key.match("-timestamp")
+              result_sets = result_sets.reverse
+            end
+          end
           result_sets.each do |result_set|
             if result_set.size > current_offset
               writer.write_table_records(result_set, output_columns, options)

  Added: test/command/suite/sharding/logical_select/sort_keys/shard_key/descending.expected (+142 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/sort_keys/shard_key/descending.expected    2017-10-25 19:42:06 +0900 (f119d7e0a)
@@ -0,0 +1,142 @@
+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]
+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 12:49:00",
+  "memo":      "2015-02-03 12:49:00"
+},
+{
+  "timestamp": "2015-02-03 23:59:59",
+  "memo":      "2015-02-03 23:59:59"
+}
+]
+[[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:49:00",
+  "memo":      "2015-02-04 13:49:00"
+},
+{
+  "timestamp": "2015-02-04 13:50:00",
+  "memo":      "2015-02-04 13:50:00"
+}
+]
+[[0,0.0,0.0],3]
+load --table Logs_20150205
+[
+{
+  "timestamp": "2015-02-05 13:49:00",
+  "memo":      "2015-02-05 13:49:00"
+},
+{
+  "timestamp": "2015-02-05 13:50:00",
+  "memo":      "2015-02-05 13:50:00"
+},
+{
+  "timestamp": "2015-02-05 13:51:00",
+  "memo":      "2015-02-05 13:51:00"
+},
+{
+  "timestamp": "2015-02-05 13:52:00",
+  "memo":      "2015-02-05 13:52:00"
+}
+]
+[[0,0.0,0.0],4]
+logical_select Logs timestamp   --sort_keys -timestamp
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "memo",
+          "ShortText"
+        ],
+        [
+          "timestamp",
+          "Time"
+        ]
+      ],
+      [
+        4,
+        "2015-02-05 13:52:00",
+        1423111920.0
+      ],
+      [
+        3,
+        "2015-02-05 13:51:00",
+        1423111860.0
+      ],
+      [
+        2,
+        "2015-02-05 13:50:00",
+        1423111800.0
+      ],
+      [
+        1,
+        "2015-02-05 13:49:00",
+        1423111740.0
+      ],
+      [
+        3,
+        "2015-02-04 13:50:00",
+        1423025400.0
+      ],
+      [
+        2,
+        "2015-02-04 13:49:00",
+        1423025340.0
+      ],
+      [
+        1,
+        "2015-02-04 00:00:00",
+        1422975600.0
+      ],
+      [
+        2,
+        "2015-02-03 23:59:59",
+        1422975599.0
+      ],
+      [
+        1,
+        "2015-02-03 12:49:00",
+        1422935340.0
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/sharding/logical_select/sort_keys/shard_key/descending.test (+66 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/sort_keys/shard_key/descending.test    2017-10-25 19:42:06 +0900 (b7c2eb40b)
@@ -0,0 +1,66 @@
+#@on-error omit
+plugin_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 12:49:00",
+  "memo":      "2015-02-03 12:49:00"
+},
+{
+  "timestamp": "2015-02-03 23:59:59",
+  "memo":      "2015-02-03 23:59:59"
+}
+]
+
+load --table Logs_20150204
+[
+{
+  "timestamp": "2015-02-04 00:00:00",
+  "memo":      "2015-02-04 00:00:00"
+},
+{
+  "timestamp": "2015-02-04 13:49:00",
+  "memo":      "2015-02-04 13:49:00"
+},
+{
+  "timestamp": "2015-02-04 13:50:00",
+  "memo":      "2015-02-04 13:50:00"
+}
+]
+
+load --table Logs_20150205
+[
+{
+  "timestamp": "2015-02-05 13:49:00",
+  "memo":      "2015-02-05 13:49:00"
+},
+{
+  "timestamp": "2015-02-05 13:50:00",
+  "memo":      "2015-02-05 13:50:00"
+},
+{
+  "timestamp": "2015-02-05 13:51:00",
+  "memo":      "2015-02-05 13:51:00"
+},
+{
+  "timestamp": "2015-02-05 13:52:00",
+  "memo":      "2015-02-05 13:52:00"
+}
+]
+
+logical_select Logs timestamp \
+  --sort_keys -timestamp
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171025/a89bb745/attachment-0001.htm 



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