[Groonga-commit] groonga/fluent-plugin-droonga at f06f5c4 [master] adapter_select: add "select" command for adapter

Back to archive index

Kosuke Asami null+****@clear*****
Tue Jul 23 13:51:05 JST 2013


Kosuke Asami	2013-07-23 13:51:05 +0900 (Tue, 23 Jul 2013)

  New Revision: f06f5c474683a4a22053732642800b24182c5188
  https://github.com/groonga/fluent-plugin-droonga/commit/f06f5c474683a4a22053732642800b24182c5188

  Message:
    adapter_select: add "select" command for adapter
    
    This "select" command only supports very basic patterns so far.
    
    TODO:
    Convert request from select_request to search_request

  Added files:
    lib/droonga/plugin/adapter_groonga.rb
    test/plugin/adapter/groonga/test_select.rb

  Added: lib/droonga/plugin/adapter_groonga.rb (+57 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/plugin/adapter_groonga.rb    2013-07-23 13:51:05 +0900 (48c16bc)
@@ -0,0 +1,57 @@
+# Copyright (C) 2013 droonga project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# 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"
+
+require "droonga/adapter"
+
+module Droonga
+  class GroongaAdapter < Droonga::Adapter
+    command :select
+
+    def select(select_request)
+      search_request = select_request
+      post(search_request) do |search_response|
+        select_convert_response(search_response)
+      end
+      :selected
+    end
+
+    def select_convert_response(search_response)
+      select_responses = search_response.collect do |key, value|
+        status_code = 0
+
+        start_time = value["startTime"]
+        start_time_in_unix_time = Time.parse(start_time).to_f
+        elapsed_time = value["elapsedTime"]
+        count = value["count"]
+
+        attributes = value["attributes"]
+        converted_attributes = attributes.collect do |attribute|
+          name = attribute["name"]
+          type = attribute["type"]
+          [name, type]
+        end
+
+        header = [status_code, start_time_in_unix_time, elapsed_time]
+        results = [[count], converted_attributes]
+        body = [results]
+
+        [header, body]
+      end
+      select_responses.first
+    end
+  end
+end

  Added: test/plugin/adapter/groonga/test_select.rb (+56 -0) 100644
===================================================================
--- /dev/null
+++ test/plugin/adapter/groonga/test_select.rb    2013-07-23 13:51:05 +0900 (44a5a85)
@@ -0,0 +1,56 @@
+# Copyright (C) 2013 droonga project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# 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 "droonga/plugin/adapter_groonga"
+
+class AdapterGroongaSelectTest < Test::Unit::TestCase
+  def setup
+    @proxy = Object.new
+    @groonga_adapter = Droonga::GroongaAdapter.new(@proxy)
+  end
+
+  class ResponseTest < self
+    def test_empty
+      start_time = "2001-08-02T10:45:23.5+09:00"
+      elapsed_time = 0
+      count = 0
+
+      search_response = {
+        "EmptyTable" => {
+          "startTime"   => start_time,
+          "elapsedTime" => elapsed_time,
+          "count"       => count,
+          "attributes"  => [
+            {"name" => "_id", "type" => "UInt32", "vector" => false},
+          ],
+          "records"     => [],
+        },
+      }
+
+      status_code = 0
+      start_time_in_unix_time = Time.parse(start_time).to_f
+      headers = [["_id","UInt32"]]
+      expected_select_response = [[status_code, start_time_in_unix_time, elapsed_time],
+                                  [[[count], headers]]]
+
+      assert_equal(expected_select_response, convert(search_response))
+    end
+
+    private
+    def convert(search_response)
+      @groonga_adapter.select_convert_response(search_response)
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Télécharger 



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