[Groonga-commit] groonga/fluent-plugin-groonga at a5030ea [master] out: supporting creating index for existing column

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Nov 20 16:51:20 JST 2014


Kouhei Sutou	2014-11-20 16:51:20 +0900 (Thu, 20 Nov 2014)

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

  Message:
    out: supporting creating index for existing column

  Modified files:
    lib/fluent/plugin/out_groonga.rb

  Modified: lib/fluent/plugin/out_groonga.rb (+31 -17)
===================================================================
--- lib/fluent/plugin/out_groonga.rb    2014-11-20 16:41:46 +0900 (67b00d8)
+++ lib/fluent/plugin/out_groonga.rb    2014-11-20 16:51:20 +0900 (db5341f)
@@ -338,10 +338,10 @@ module Fluent
         column_list =****@clien*****("column_list", "table" => @table_name)
         @columns = {}
         column_list.each do |column|
+          name = column.name
           vector_p = column.flags.split("|").include?("COLUMN_VECTOR")
-          @columns[column.name] = Column.new(column.name,
-                                             column.range,
-                                             vector_p)
+          @columns[name] = Column.new(name, column.range, vector_p)
+          ensure_column_indexes(name)
         end
       end
 
@@ -365,24 +365,38 @@ module Fluent
                         "name" => name,
                         "flags" => flags,
                         "type" => value_type)
-        if mapping
-          mapping.indexes.each do |index|
-            index_flags = ["COLUMN_INDEX"]
-            table = @tables[index[:table]]
-            index_flags << "WITH_POSITION" if table and table.default_tokenizer
-            index_flags << index[:flags] if index[:flags]
-            @client.execute("column_create",
-                            "table" => index[:table],
-                            "name" => index[:name],
-                            "flags" => index_flags.join("|"),
-                            "type" => @table_name,
-                            "source" => name)
-          end
-        end
+        ensure_column_indexes(name)
 
         Column.new(name, value_type, vector_p)
       end
 
+      def ensure_column_indexes(name)
+        mapping =****@mappi***** do |_mapping|
+          _mapping.name == name
+        end
+        return if mapping.nil?
+
+        mapping.indexes.each do |index|
+          table = @tables[index[:table]]
+          if table
+            column_list =****@clien*****("column_list", "table" => table.name)
+            exist = column_list.any? {|column| column.name == index[:name]}
+            next if exist
+          end
+
+          index_flags = ["COLUMN_INDEX"]
+          index_flags << "WITH_POSITION" if table and table.default_tokenizer
+          index_flags << index[:flags] if index[:flags]
+
+          @client.execute("column_create",
+                          "table" => index[:table],
+                          "name" => index[:name],
+                          "flags" => index_flags.join("|"),
+                          "type" => @table_name,
+                          "source" => name)
+        end
+      end
+
       class TypeGuesser
         def initialize(sample_values)
           @sample_values = sample_values
-------------- next part --------------
HTML����������������������������...
Download 



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