[Groonga-commit] groonga/fluent-plugin-droonga at d62fa1e [master] Enable create_table flags options

アーカイブの一覧に戻る

Kosuke Asami null+****@clear*****
Tue Jul 9 17:25:06 JST 2013


Kosuke Asami	2013-07-09 17:25:06 +0900 (Tue, 09 Jul 2013)

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

  Message:
    Enable create_table flags options

  Modified files:
    lib/droonga/plugin/groonga/table_create.rb
    test/plugin/groonga/test_table_create.rb

  Modified: lib/droonga/plugin/groonga/table_create.rb (+27 -1)
===================================================================
--- lib/droonga/plugin/groonga/table_create.rb    2013-07-09 17:22:56 +0900 (4fda4a0)
+++ lib/droonga/plugin/groonga/table_create.rb    2013-07-09 17:25:06 +0900 (8d3a1b8)
@@ -26,11 +26,37 @@ module Droonga
 
       def execute(request)
         name = request["name"]
+        options = parse_request(request)
         Groonga::Schema.define(:context => @context) do |schema|
-          schema.create_table(name)
+          schema.create_table(name, options)
         end
         [true]
       end
+
+      private
+      def parse_request(request)
+        options = {:type => :hash}
+        if request["flags"]
+          request["flags"].split(/\|/).each do |flag|
+            case flag
+            when "TABLE_NO_KEY"
+              options[:type] = :array
+            when "TABLE_HASH_KEY"
+              options[:type] = :hash
+            when "TABLE_PAT_KEY"
+              options[:type] = :patricia_trie
+            when "TABLE_DAT_KEY"
+              options[:type] = :double_array_trie
+            when "KEY_WITH_SIS"
+              options[:key_with_sis] = true
+            end
+          end
+          if options[:key_with_sis]
+            options[:key_with_sis] = false unless options[:type] == :patricia_trie
+          end
+        end
+        options
+      end
     end
   end
 end

  Modified: test/plugin/groonga/test_table_create.rb (+69 -1)
===================================================================
--- test/plugin/groonga/test_table_create.rb    2013-07-09 17:22:56 +0900 (3507d39)
+++ test/plugin/groonga/test_table_create.rb    2013-07-09 17:25:06 +0900 (c6a3e88)
@@ -22,7 +22,75 @@ class TableCreateTest < GroongaHandlerTest
   def test_name
     @handler.table_create({"name" => "Books"})
     assert_equal(<<-SCHEMA, dump)
-table_create Books TABLE_NO_KEY
+table_create Books TABLE_HASH_KEY --key_type ShortText
     SCHEMA
   end
+
+  class FlagsTest < self
+    def test_table_no_key
+      request = {
+        "name"  => "Books",
+        "flags" => "TABLE_NO_KEY",
+      }
+      @handler.table_create(request)
+      assert_equal(<<-SCHEMA, dump)
+table_create Books TABLE_NO_KEY
+      SCHEMA
+    end
+
+    def test_table_hash_key
+      request = {
+        "name"  => "Books",
+        "flags" => "TABLE_HASH_KEY",
+      }
+      @handler.table_create(request)
+      assert_equal(<<-SCHEMA, dump)
+table_create Books TABLE_HASH_KEY --key_type ShortText
+      SCHEMA
+    end
+
+    def test_table_pat_key
+      request = {
+        "name"  => "Books",
+        "flags" => "TABLE_PAT_KEY",
+      }
+      @handler.table_create(request)
+      assert_equal(<<-SCHEMA, dump)
+table_create Books TABLE_PAT_KEY --key_type ShortText
+      SCHEMA
+    end
+
+    def test_table_dat_key
+      request = {
+        "name"  => "Books",
+        "flags" => "TABLE_DAT_KEY",
+      }
+      @handler.table_create(request)
+      assert_equal(<<-SCHEMA, dump)
+table_create Books TABLE_DAT_KEY --key_type ShortText
+      SCHEMA
+    end
+
+    def test_key_with_sis_with_pat_key
+      request = {
+        "name"  => "Books",
+        "flags" => "KEY_WITH_SIS|TABLE_PAT_KEY",
+      }
+      @handler.table_create(request)
+      assert_equal(<<-SCHEMA, dump)
+table_create Books TABLE_PAT_KEY|KEY_WITH_SIS --key_type ShortText
+      SCHEMA
+    end
+
+    def test_key_with_sis_without_pat_key
+      request = {
+        "name"  => "Books",
+        "flags" => "TABLE_NO_KEY|KEY_WITH_SIS",
+      }
+      @handler.table_create(request)
+      assert_equal(<<-SCHEMA, dump)
+table_create Books TABLE_NO_KEY
+      SCHEMA
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
ダウンロード 



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