[Groonga-commit] groonga/groonga-query-log [master] extractor: implement #extract from bin/groonga-query-log-extract

アーカイブの一覧に戻る

Haruka Yoshihara null+****@clear*****
Mon Dec 17 13:15:05 JST 2012


Haruka Yoshihara	2012-12-17 13:15:05 +0900 (Mon, 17 Dec 2012)

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

  Log:
    extractor: implement #extract from bin/groonga-query-log-extract

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

  Modified: lib/groonga/query-log/extractor.rb (+17 -0)
===================================================================
--- lib/groonga/query-log/extractor.rb    2012-12-14 18:27:36 +0900 (72224aa)
+++ lib/groonga/query-log/extractor.rb    2012-12-17 13:15:05 +0900 (7ed9565)
@@ -111,6 +111,23 @@ module Groonga
           end
         end
       end
+
+      def extract(log, output)
+        parser = Groonga::QueryLog::Parser.new
+        parser.parse(log) do |statistic|
+          command = statistic.command
+          next unless target?(command)
+          command_text = nil
+          case****@optio*****_format
+          when "uri"
+            command_text = command.to_uri_format
+          when "command"
+            command_text = command.to_command_format
+          end
+          command_text ||= statistic.raw_command
+          output.puts(command_text)
+        end
+      end
     end
   end
 end

  Modified: test/test-extractor.rb (+46 -1)
===================================================================
--- test/test-extractor.rb    2012-12-14 18:27:36 +0900 (4cd0f3d)
+++ test/test-extractor.rb    2012-12-17 13:15:05 +0900 (965a2cc)
@@ -16,14 +16,59 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-require "groonga/query-log/extractor"
+require "stringio"
 require "groonga/command"
+require "groonga/query-log/extractor"
 
 class TestExtractor < Test::Unit::TestCase
   def setup
     @extractor = Groonga::QueryLog::Extractor.new
   end
 
+  class TestExtract < self
+    def setup
+      super
+      @log = <<-EOL
+2012-12-12 17:39:17.628846|0x7fff786aa2b0|>select --table Users --query follower:@groonga --output_columns _key,name
+2012-12-12 17:39:17.629676|0x7fff786aa2b0|:000000000842953 filter(2)
+2012-12-12 17:39:17.629709|0x7fff786aa2b0|:000000000870900 select(2)
+2012-12-12 17:39:17.629901|0x7fff786aa2b0|:000000001066752 output(2)
+2012-12-12 17:39:17.630052|0x7fff786aa2b0|<000000001217140 rc=0
+EOL
+    end
+
+    def test_command_format
+      @extractor.options.unify_format = "command"
+      expected_fommated_command = "select --output_columns \"_key,name\""+
+                                    " --query \"follower:@groonga\"" +
+                                    " --table \"Users\"\n"
+      assert_equal(expected_fommated_command, extract)
+    end
+
+    def test_uri_format
+      @extractor.options.unify_format = "uri"
+      expected_fommated_command = "/d/select?output_columns=_key%2Cname" +
+                                    "&query=follower%3A%40groonga" +
+                                    "&table=Users\n"
+      assert_equal(expected_fommated_command, extract)
+    end
+
+    def test_not_unify
+      @extractor.options.unify_format = nil
+      expected_fommated_command = "select --table Users" +
+                                  " --query follower:@groonga" +
+                                  " --output_columns _key,name\n"
+      assert_equal(expected_fommated_command, extract)
+    end
+
+    private
+    def extract
+      output = StringIO.new
+      @extractor.send(:extract, @log, output)
+      output.string
+    end
+  end
+
   class TestTarget < self
     def test_include
       @extractor.options.commands = ["register"]
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る