Skip to content

Commit

Permalink
out: supporting creating index for existing column
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Nov 20, 2014
1 parent 8075106 commit a5030ea
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions lib/fluent/plugin/out_groonga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ def ensure_columns
column_list = @client.execute("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

Expand All @@ -365,24 +365,38 @@ def create_column(name, sample_values)
"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 = @mappings.find do |_mapping|
_mapping.name == name
end
return if mapping.nil?

mapping.indexes.each do |index|
table = @tables[index[:table]]
if table
column_list = @client.execute("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
Expand Down

0 comments on commit a5030ea

Please sign in to comment.