[Groonga-commit] droonga/fluent-plugin-droonga at 6b32149 [master] schema: Implement Schema#to_commands

Back to archive index

Yoji Shidara null+****@clear*****
Tue Feb 18 15:31:09 JST 2014


Yoji Shidara	2014-02-18 15:31:09 +0900 (Tue, 18 Feb 2014)

  New Revision: 6b321494e181701b959f0a3533e862125615fa9f
  https://github.com/droonga/fluent-plugin-droonga/commit/6b321494e181701b959f0a3533e862125615fa9f

  Message:
    schema: Implement Schema#to_commands

  Modified files:
    lib/droonga/catalog/schema.rb
    test/unit/catalog/test_schema.rb

  Modified: lib/droonga/catalog/schema.rb (+46 -0)
===================================================================
--- lib/droonga/catalog/schema.rb    2014-02-18 15:03:35 +0900 (d4a5935)
+++ lib/droonga/catalog/schema.rb    2014-02-18 15:31:09 +0900 (963c97e)
@@ -99,6 +99,39 @@ module Droonga
           @data["normalizer"]
         end
 
+        def flags
+          case type
+          when "Array"
+            "TABLE_NO_KEY"
+          when "Hash"
+            "TABLE_HASH_KEY"
+          when "PatriciaTrie"
+            "TABLE_PAT_KEY"
+          when "DoubleArrayTrie"
+            "TABLE_DAT_KEY"
+          else
+            # TODO raise appropriate error
+          end
+        end
+
+        def to_table_create_body
+          body = {
+            "name"     => name,
+            "key_type" => key_type,
+            "flags"    => flags
+          }
+
+          if tokenizer
+            body["default_tokenizer"] = tokenizer
+          end
+
+          if normalizer
+            body["normalizer"] = normalizer
+          end
+
+          body
+        end
+
         private
         def columns_data
           @data["columns"] || []
@@ -113,6 +146,19 @@ module Droonga
         end
       end
 
+      def to_commands
+        commands = tables.map do |table|
+          {
+            "type" => "table_create",
+            "body" => table.to_table_create_body
+          }
+        end
+
+        # TODO append topologically sorted column_create commands
+
+        commands
+      end
+
       def ==(other)
         self.class == other.class and
           tables == other.tables

  Modified: test/unit/catalog/test_schema.rb (+39 -8)
===================================================================
--- test/unit/catalog/test_schema.rb    2014-02-18 15:03:35 +0900 (76a49a6)
+++ test/unit/catalog/test_schema.rb    2014-02-18 15:31:09 +0900 (305f2b3)
@@ -24,20 +24,51 @@ class CatalogSchemaTest < Test::Unit::TestCase
   class SchemaTest < self
     def test_schema_not_specified
       assert_equal([],
-                   create_schema(nil).tables)
+                   create_schema(nil).to_commands)
     end
 
     def test_no_table
       assert_equal([],
-                   create_schema({}).tables)
+                   create_schema({}).to_commands)
     end
 
-    def test_tables
-      assert_equal(
-        [Droonga::Catalog::Schema::Table.new('table1', {})],
-        create_schema(
-          "table1" => {
-        }).tables
+    def test_hash_table
+      assert_equal([
+                     "type" => "table_create",
+                     "body" => {
+                       "name"     => "table_name",
+                       "key_type" => "ShortText",
+                       "flags"    => "TABLE_HASH_KEY"
+                     }
+                   ],
+                   create_schema(
+                     "table_name" => {
+                       "type"    => "Hash",
+                       "keyType" => "ShortText"
+                     }
+                   ).to_commands
+      )
+    end
+
+    def test_patricia_trie_table
+      assert_equal([
+                     "type" => "table_create",
+                     "body" => {
+                       "name"              => "table_name",
+                       "key_type"          => "ShortText",
+                       "flags"             => "TABLE_PAT_KEY",
+                       "normalizer"        => "NormalizerAuto",
+                       "default_tokenizer" => "TokenBigram"
+                     }
+                   ],
+                   create_schema(
+                     "table_name" => {
+                       "type"       => "PatriciaTrie",
+                       "keyType"    => "ShortText",
+                       "normalizer" => "NormalizerAuto",
+                       "tokenizer"  => "TokenBigram"
+                     }
+                   ).to_commands
       )
     end
 
-------------- next part --------------
HTML����������������������������...
Download 



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