Kouhei Sutou
null+****@clear*****
Wed Nov 5 18:36:08 JST 2014
Kouhei Sutou 2014-11-05 18:36:08 +0900 (Wed, 05 Nov 2014) New Revision: d0c2a292da987a306209c1cafd6921676df7a761 https://github.com/groonga/fluent-plugin-groonga/commit/d0c2a292da987a306209c1cafd6921676df7a761 Message: out: fix a bug needless WITH_SECTION is added It counts the number of characters instead of the number of source columns. :< Added files: test/output/test_table_index_definition.rb Modified files: lib/fluent/plugin/out_groonga.rb Modified: lib/fluent/plugin/out_groonga.rb (+25 -19) =================================================================== --- lib/fluent/plugin/out_groonga.rb 2014-11-05 18:14:39 +0900 (df13e01) +++ lib/fluent/plugin/out_groonga.rb 2014-11-05 18:36:08 +0900 (258a019) @@ -122,7 +122,28 @@ module Fluent end end + module DefinitionParseMethods + private + def parse_flags(flags) + if flags.is_a?(Array) + flags + else + flags.strip.split(/\s*\|\s*/) + end + end + + def parse_items(items) + if items.is_a?(Array) + items + else + items.strip.split(/\s*,\s*/) + end + end + end + class TableDefinition + include DefinitionParseMethods + def initialize(raw) @raw = raw end @@ -192,24 +213,9 @@ module Fluent arguments end - private - def parse_flags(flags) - if flags.is_a?(Array) - flags - else - flags.strip.split(/\s*\|\s*/) - end - end - - def parse_items(items) - if items.is_a?(Array) - items - else - items.strip.split(/\s*,\s*/) - end - end - class IndexDefinition + include DefinitionParseMethods + def initialize(table, raw) @table = table @raw = raw @@ -224,7 +230,7 @@ module Fluent end def source_columns - @raw[:source_columns] + parse_items(@raw[:source_columns]) end def flags @@ -240,7 +246,7 @@ module Fluent "name" => name, "flags" => flags.join("|"), "type" => source_table, - "source" => source_columns, + "source" => source_columns.join(","), } end end Added: test/output/test_table_index_definition.rb (+95 -0) 100644 =================================================================== --- /dev/null +++ test/output/test_table_index_definition.rb 2014-11-05 18:36:08 +0900 (22d4653) @@ -0,0 +1,95 @@ +# Copyright (C) 2014 Kouhei Sutou <kou �� clear-code.com> +# +# 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 "fluent/plugin/out_groonga" + +class OutputTypeTableIndexDefinitionTest < Test::Unit::TestCase + def table_definition + raw = { + :name => "Terms", + :default_tokenizer => "TokenBigram", + } + Fluent::GroongaOutput::TableDefinition.new(raw) + end + + def definition(raw={}) + default_raw = { + :source_columns => "title", + } + raw = default_raw.merge(raw) + Fluent::GroongaOutput::TableDefinition::IndexDefinition.new(table_definition, + raw) + end + + sub_test_case "readers" do + sub_test_case "\#name" do + test "specified" do + assert_equal("logs_index", definition(:name => "logs_index").name) + end + end + + sub_test_case "\#flags" do + test "default" do + assert_equal(["COLUMN_INDEX", "WITH_POSITION"], + definition.flags) + end + + test "multiple source columns" do + assert_equal(["COLUMN_INDEX", "WITH_POSITION", "WITH_SECTION"], + definition(:source_columns => "title,content").flags) + end + end + + sub_test_case "\#source_table" do + test "specified" do + assert_equal("Logs", + definition(:source_table => "Logs").source_table) + end + end + + sub_test_case "\#source_columns" do + test "one" do + assert_equal(["title"], + definition(:source_columns => "title").source_columns) + end + + test "multiple" do + raw = { + :source_columns => "title,content", + } + assert_equal(["title", "content"], + definition(raw).source_columns) + end + end + end + + sub_test_case "\#to_create_arguments" do + test "full" do + raw = { + :name => "logs_index", + :source_table => "Logs", + :source_columns => "title, content", + } + assert_equal({ + "table" => "Terms", + "name" => "logs_index", + "flags" => "COLUMN_INDEX|WITH_POSITION|WITH_SECTION", + "type" => "Logs", + "source" => "title,content", + }, + definition(raw).to_create_arguments) + end + end +end -------------- next part -------------- HTML����������������������������...Download