[Groonga-commit] groonga/groonga at 89ee3b9 [master] mrb: add missing nil initialization

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Feb 3 16:07:58 JST 2015


Kouhei Sutou	2015-02-03 16:07:58 +0900 (Tue, 03 Feb 2015)

  New Revision: 89ee3b968ba602472862f9fc71722351ed9301a7
  https://github.com/groonga/groonga/commit/89ee3b968ba602472862f9fc71722351ed9301a7

  Message:
    mrb: add missing nil initialization

  Added files:
    test/command/suite/sharding/logical_count/condition/filter/no_range.expected
    test/command/suite/sharding/logical_count/condition/filter/no_range.test
  Modified files:
    plugins/sharding/search.rb

  Modified: plugins/sharding/search.rb (+20 -1)
===================================================================
--- plugins/sharding/search.rb    2015-02-03 16:07:31 +0900 (ae353d6)
+++ plugins/sharding/search.rb    2015-02-03 16:07:58 +0900 (3a894fd)
@@ -18,12 +18,31 @@ module Groonga
           raise InvalidArgument, "[logical_count] logical_table is missing"
         end
 
+        filter = input[:filter]
+
         total = 0
         context.database.each_table(:prefix => "#{logical_table}_") do |table|
-          total += table.size
+          total += count_n_records(table, filter)
         end
         output(total)
       end
+
+      private
+      def count_n_records(table, filter)
+        return table.size if filter.nil?
+
+        expression = nil
+        filtered_table = nil
+        begin
+          expression = Expression.create(table)
+          expression.parse(filter)
+          filtered_table = table.select(expression)
+          filtered_table.size
+        ensure
+          filtered_table.close if filtered_table
+          expression.close if expression
+        end
+      end
     end
   end
 end

  Added: test/command/suite/sharding/logical_count/condition/filter/no_range.expected (+40 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_count/condition/filter/no_range.expected    2015-02-03 16:07:58 +0900 (2144950)
@@ -0,0 +1,40 @@
+register sharding/search
+[[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 message COLUMN_SCALAR Text
+[[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 message COLUMN_SCALAR Text
+[[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 message COLUMN_SCALAR Text
+[[0,0.0,0.0],true]
+load --table Logs_20150203
+[
+{"timestamp": "2015-02-03 12:49:00", "message": "Start"}
+]
+[[0,0.0,0.0],1]
+load --table Logs_20150204
+[
+{"timestamp": "2015-02-04 13:49:00", "message": "Start"},
+{"timestamp": "2015-02-04 13:50:00", "message": "Shutdown"}
+]
+[[0,0.0,0.0],2]
+load --table Logs_20150205
+[
+{"timestamp": "2015-02-05 13:49:00", "message": "Start"},
+{"timestamp": "2015-02-05 13:50:00", "message": "Running"},
+{"timestamp": "2015-02-05 13:51:00", "message": "Shutdown"}
+]
+[[0,0.0,0.0],3]
+logical_count Logs --filter 'message == "Shutdown"'
+[[0,0.0,0.0],2]

  Added: test/command/suite/sharding/logical_count/condition/filter/no_range.test (+35 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_count/condition/filter/no_range.test    2015-02-03 16:07:58 +0900 (f147e9e)
@@ -0,0 +1,35 @@
+#@on-error omit
+register sharding/search
+#@on-error default
+
+table_create Logs_20150203 TABLE_NO_KEY
+column_create Logs_20150203 timestamp COLUMN_SCALAR Time
+column_create Logs_20150203 message COLUMN_SCALAR Text
+
+table_create Logs_20150204 TABLE_NO_KEY
+column_create Logs_20150204 timestamp COLUMN_SCALAR Time
+column_create Logs_20150204 message COLUMN_SCALAR Text
+
+table_create Logs_20150205 TABLE_NO_KEY
+column_create Logs_20150205 timestamp COLUMN_SCALAR Time
+column_create Logs_20150205 message COLUMN_SCALAR Text
+
+load --table Logs_20150203
+[
+{"timestamp": "2015-02-03 12:49:00", "message": "Start"}
+]
+
+load --table Logs_20150204
+[
+{"timestamp": "2015-02-04 13:49:00", "message": "Start"},
+{"timestamp": "2015-02-04 13:50:00", "message": "Shutdown"}
+]
+
+load --table Logs_20150205
+[
+{"timestamp": "2015-02-05 13:49:00", "message": "Start"},
+{"timestamp": "2015-02-05 13:50:00", "message": "Running"},
+{"timestamp": "2015-02-05 13:51:00", "message": "Shutdown"}
+]
+
+logical_count Logs --filter 'message == "Shutdown"'
-------------- next part --------------
HTML����������������������������...
Download 



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