[Groonga-commit] groonga/groonga at 7e3dc34 [master] logical_range_filter: fix a bug that :order => "descending" doesn't work

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 17 14:57:34 JST 2015


Kouhei Sutou	2015-04-17 14:57:34 +0900 (Fri, 17 Apr 2015)

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

  Message:
    logical_range_filter: fix a bug that :order => "descending" doesn't work

  Added files:
    test/command/suite/sharding/logical_range_filter/order/descending.expected
    test/command/suite/sharding/logical_range_filter/order/descending.test
  Modified files:
    plugins/sharding/logical_enumerator.rb
    plugins/sharding/logical_range_filter.rb

  Modified: plugins/sharding/logical_enumerator.rb (+11 -2)
===================================================================
--- plugins/sharding/logical_enumerator.rb    2015-04-17 13:13:50 +0900 (90948ae)
+++ plugins/sharding/logical_enumerator.rb    2015-04-17 14:57:34 +0900 (1aeafef)
@@ -10,12 +10,21 @@ module Groonga
         initialize_parameters
       end
 
-      def each
+      def each(&block)
+        each_internal(:ascending, &block)
+      end
+
+      def reverse_each(&block)
+        each_internal(:descending, &block)
+      end
+
+      private
+      def each_internal(order)
         prefix = "#{@logical_table}_"
         context = Context.instance
         context.database.each_table(:prefix => prefix,
                                     :order_by => :key,
-                                    :order => :ascending) do |table|
+                                    :order => order) do |table|
           shard_range_raw = table.name[prefix.size..-1]
 
           next unless /\A(\d{4})(\d{2})(\d{2})\z/ =~ shard_range_raw

  Modified: plugins/sharding/logical_range_filter.rb (+7 -1)
===================================================================
--- plugins/sharding/logical_range_filter.rb    2015-04-17 13:13:50 +0900 (2986365)
+++ plugins/sharding/logical_range_filter.rb    2015-04-17 14:57:34 +0900 (24488bc)
@@ -125,7 +125,12 @@ module Groonga
         def execute
           first_table = nil
           enumerator =****@conte*****
-          enumerator.each do |table, shard_key, shard_range|
+          if****@conte***** == :descending
+            each_method = :reverse_each
+          else
+            each_method = :each
+          end
+          enumerator.send(each_method) do |table, shard_key, shard_range|
             first_table ||= table
             next if table.empty?
 
@@ -367,6 +372,7 @@ module Groonga
 
         def build_range_search_flags(min_border, max_border)
           flags = TableCursorFlags::BY_KEY
+          p****@conte*****
           case****@conte*****
           when :ascending
             flags |= TableCursorFlags::ASCENDING

  Added: test/command/suite/sharding/logical_range_filter/order/descending.expected (+65 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_range_filter/order/descending.expected    2015-04-17 14:57:34 +0900 (d82eabf)
@@ -0,0 +1,65 @@
+load --table Logs_20150203
+[
+{"timestamp": "2015-02-03 23:59:58", "memo": "2015-02-03 23:59:58", "message": "Start"},
+{"timestamp": "2015-02-03 23:59:58", "memo": "2015-02-03 23:59:58", "message": "Shutdown"},
+{"timestamp": "2015-02-03 23:59:59", "memo": "2015-02-03 23:59:59", "message": "Start"},
+{"timestamp": "2015-02-03 23:59:59", "memo": "2015-02-03 23:59:59", "message": "Shutdown"}
+]
+[[0,0.0,0.0],4]
+load --table Logs_20150204
+[
+{"timestamp": "2015-02-04 00:00:00", "memo": "2015-02-04 00:00:00", "message": "Start"},
+{"timestamp": "2015-02-04 00:00:00", "memo": "2015-02-04 00:00:00", "message": "Shutdown"},
+{"timestamp": "2015-02-04 00:00:01", "memo": "2015-02-04 00:00:01", "message": "Start"},
+{"timestamp": "2015-02-04 00:00:01", "memo": "2015-02-04 00:00:01", "message": "Shutdown"},
+{"timestamp": "2015-02-04 23:59:59", "memo": "2015-02-04 23:59:59", "message": "Start"},
+{"timestamp": "2015-02-04 23:59:59", "memo": "2015-02-04 23:59:59", "message": "Shutdown"}
+]
+[[0,0.0,0.0],6]
+load --table Logs_20150205
+[
+{"timestamp": "2015-02-05 00:00:00", "memo": "2015-02-05 00:00:00", "message": "Start"},
+{"timestamp": "2015-02-05 00:00:00", "memo": "2015-02-05 00:00:00", "message": "Shutdown"},
+{"timestamp": "2015-02-05 00:00:01", "memo": "2015-02-05 00:00:01", "message": "Start"},
+{"timestamp": "2015-02-05 00:00:01", "memo": "2015-02-05 00:00:01", "message": "Shutdown"}
+]
+[[0,0.0,0.0],4]
+logical_range_filter Logs timestamp   --filter 'message == "Shutdown"'   --min "2015-02-04 00:00:00"   --min_border "exclude"   --max "2015-02-05 00:00:00"   --max_border "include"   --order "descending"
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        "memo",
+        "ShortText"
+      ],
+      [
+        "message",
+        "Text"
+      ],
+      [
+        "timestamp",
+        "Time"
+      ]
+    ],
+    [
+      "2015-02-05 00:00:00",
+      "Shutdown",
+      1423062000.0
+    ],
+    [
+      "2015-02-04 23:59:59",
+      "Shutdown",
+      1423061999.0
+    ],
+    [
+      "2015-02-04 00:00:01",
+      "Shutdown",
+      1422975601.0
+    ]
+  ]
+]

  Added: test/command/suite/sharding/logical_range_filter/order/descending.test (+35 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_range_filter/order/descending.test    2015-04-17 14:57:34 +0900 (a210a66)
@@ -0,0 +1,35 @@
+#@include fixture/sharding/logical_range_filter/index/schema.grn
+
+load --table Logs_20150203
+[
+{"timestamp": "2015-02-03 23:59:58", "memo": "2015-02-03 23:59:58", "message": "Start"},
+{"timestamp": "2015-02-03 23:59:58", "memo": "2015-02-03 23:59:58", "message": "Shutdown"},
+{"timestamp": "2015-02-03 23:59:59", "memo": "2015-02-03 23:59:59", "message": "Start"},
+{"timestamp": "2015-02-03 23:59:59", "memo": "2015-02-03 23:59:59", "message": "Shutdown"}
+]
+
+load --table Logs_20150204
+[
+{"timestamp": "2015-02-04 00:00:00", "memo": "2015-02-04 00:00:00", "message": "Start"},
+{"timestamp": "2015-02-04 00:00:00", "memo": "2015-02-04 00:00:00", "message": "Shutdown"},
+{"timestamp": "2015-02-04 00:00:01", "memo": "2015-02-04 00:00:01", "message": "Start"},
+{"timestamp": "2015-02-04 00:00:01", "memo": "2015-02-04 00:00:01", "message": "Shutdown"},
+{"timestamp": "2015-02-04 23:59:59", "memo": "2015-02-04 23:59:59", "message": "Start"},
+{"timestamp": "2015-02-04 23:59:59", "memo": "2015-02-04 23:59:59", "message": "Shutdown"}
+]
+
+load --table Logs_20150205
+[
+{"timestamp": "2015-02-05 00:00:00", "memo": "2015-02-05 00:00:00", "message": "Start"},
+{"timestamp": "2015-02-05 00:00:00", "memo": "2015-02-05 00:00:00", "message": "Shutdown"},
+{"timestamp": "2015-02-05 00:00:01", "memo": "2015-02-05 00:00:01", "message": "Start"},
+{"timestamp": "2015-02-05 00:00:01", "memo": "2015-02-05 00:00:01", "message": "Shutdown"}
+]
+
+logical_range_filter Logs timestamp \
+  --filter 'message == "Shutdown"' \
+  --min "2015-02-04 00:00:00" \
+  --min_border "exclude" \
+  --max "2015-02-05 00:00:00" \
+  --max_border "include" \
+  --order "descending"
-------------- next part --------------
HTML����������������������������...
다운로드 



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