[Groonga-commit] groonga/groonga-query-log at e16f2d6 [master] response-comparer: support drilldown

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jun 13 10:12:15 JST 2018


Kouhei Sutou	2018-06-13 10:12:15 +0900 (Wed, 13 Jun 2018)

  New Revision: e16f2d611f89b4d59d3fe5524829fb0068c7bddf
  https://github.com/groonga/groonga-query-log/commit/e16f2d611f89b4d59d3fe5524829fb0068c7bddf

  Message:
    response-comparer: support drilldown

  Modified files:
    lib/groonga-query-log/response-comparer.rb
    test/test-response-comparer.rb

  Modified: lib/groonga-query-log/response-comparer.rb (+27 -9)
===================================================================
--- lib/groonga-query-log/response-comparer.rb    2018-06-13 09:50:06 +0900 (3792281)
+++ lib/groonga-query-log/response-comparer.rb    2018-06-13 10:12:15 +0900 (62a7bda)
@@ -61,12 +61,13 @@ module GroongaQueryLog
     def same_select_response?
       if care_order?
         if all_output_columns?
-          same_records_all_output_columns?
+          return false unless same_records_all_output_columns?
         elsif have_unary_minus_output_column?
-          same_records_unary_minus_output_column?
+          return false unless same_records_unary_minus_output_column?
         else
-          same_records?
+          return false unless same_records?
         end
+        same_drilldowns?
       else
         same_size_response?
       end
@@ -212,16 +213,21 @@ module GroongaQueryLog
       records_result2 =****@respo*****[0] || []
       return false if records_result1.size != records_result2.size
 
-      n_hits1 = records_result1[0]
-      n_hits2 = records_result2[0]
+      same_record_set(records_result1,
+                      records_result2)
+    end
+
+    def same_record_set?(record_set1, record_set2)
+      n_hits1 = record_set1[0]
+      n_hits2 = record_set2[0]
       return false if n_hits1 != n_hits2
 
-      columns1 = records_result1[1]
-      columns2 = records_result2[1]
+      columns1 = record_set1[1]
+      columns2 = record_set2[1]
       return false if columns1 != columns2
 
-      records1 = records_result1[2..-1]
-      records2 = records_result2[2..-1]
+      records1 = record_set1[2..-1]
+      records2 = record_set2[2..-1]
       records1.each_with_index do |record1, record_index|
         record2 = records2[record_index]
         columns1.each_with_index do |column1, column_index|
@@ -244,6 +250,18 @@ module GroongaQueryLog
       map
     end
 
+    def same_drilldowns?
+      drilldowns1 =****@respo*****[1..-1] || []
+      drilldowns2 =****@respo*****[1..-1] || []
+      return false if drilldowns1.size != drilldowns2.size
+
+      drilldowns1.each_with_index do |drilldown1, drilldown_index|
+        drilldown2 = drilldowns2[drilldown_index]
+        return false unless same_record_set?(drilldown1, drilldown2)
+      end
+      true
+    end
+
     def normalize_value(value, column)
       type = column[1]
       case type

  Modified: test/test-response-comparer.rb (+32 -0)
===================================================================
--- test/test-response-comparer.rb    2018-06-13 09:50:06 +0900 (742701d)
+++ test/test-response-comparer.rb    2018-06-13 10:12:15 +0900 (6516dd9)
@@ -363,6 +363,38 @@ class ResponseComparerTest < Test::Unit::TestCase
       end
     end
 
+    class DrilldownTest < self
+      def create_response(drilldown)
+        [
+          [
+            [10],
+            [["_id", "UInt32"]],
+          ],
+          [
+            [drilldown.size * 2],
+            [["_key", "ShortText"], ["_nsubrecs", "Int32"]],
+            *drilldown,
+          ]
+        ]
+      end
+
+      def test_same
+        response1 = create_response([["A", 10], ["B", 2]])
+        response2 = create_response([["A", 10], ["B", 2]])
+        assert do
+          same?(response1, response2)
+        end
+      end
+
+      def test_not_same
+        response1 = create_response([["A", 11], ["B", 2]])
+        response2 = create_response([["A", 10], ["B", 2]])
+        assert do
+          not same?(response1, response2)
+        end
+      end
+    end
+
     class ErrorTest < self
       def test_with_location
         response1_header = [
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180613/65f068ca/attachment-0001.htm 



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