Kouhei Sutou
null+****@clear*****
Wed Mar 19 11:36:03 JST 2014
Kouhei Sutou 2014-03-19 11:36:03 +0900 (Wed, 19 Mar 2014) New Revision: 9bf036f9e4c244cc94009ebadec5da11c173c572 https://github.com/droonga/fluent-plugin-droonga/commit/9bf036f9e4c244cc94009ebadec5da11c173c572 Message: Support fact in catalog.json No "fact" case is still supported. If "fact" isn't specified, all tables act as fact table. We should remove the code when all catalog.json have "fact" parameter. (It will be the time that we validate catalog.json and reject catalog.json that doesn't have "fact" parameter.) Modified files: lib/droonga/catalog/dataset.rb lib/droonga/dispatcher.rb lib/droonga/handler_runner.rb lib/droonga/single_step.rb lib/droonga/step_runner.rb test/unit/catalog/test_dataset.rb Modified: lib/droonga/catalog/dataset.rb (+4 -0) =================================================================== --- lib/droonga/catalog/dataset.rb 2014-03-17 22:45:15 +0900 (b14b835) +++ lib/droonga/catalog/dataset.rb 2014-03-19 11:36:03 +0900 (c443a02) @@ -41,6 +41,10 @@ module Droonga def plugins @data["plugins"] || [] end + + def fact + @data["fact"] + end end end end Modified: lib/droonga/dispatcher.rb (+1 -1) =================================================================== --- lib/droonga/dispatcher.rb 2014-03-17 22:45:15 +0900 (dfa61e4) +++ lib/droonga/dispatcher.rb 2014-03-19 11:36:03 +0900 (dd54328) @@ -272,7 +272,7 @@ module Droonga def create_step_runners create_runners do |dataset| - StepRunner.new(dataset.plugins) + StepRunner.new(dataset, dataset.plugins) end end Modified: lib/droonga/handler_runner.rb (+1 -1) =================================================================== --- lib/droonga/handler_runner.rb 2014-03-17 22:45:15 +0900 (eb642fd) +++ lib/droonga/handler_runner.rb 2014-03-19 11:36:03 +0900 (741b703) @@ -80,7 +80,7 @@ module Droonga end logger.debug("#{self.class.name}: activating plugins for the dataset \"#{@dataset_name}\": " + "#{@options[:plugins].join(", ")}") - @step_runner = StepRunner.new(@options[:plugins] || []) + @step_runner = StepRunner.new(nil, @options[:plugins] || []) @forwarder = Forwarder.new(@loop) end Modified: lib/droonga/single_step.rb (+22 -7) =================================================================== --- lib/droonga/single_step.rb 2014-03-17 22:45:15 +0900 (638cf8d) +++ lib/droonga/single_step.rb 2014-03-19 11:36:03 +0900 (217b69a) @@ -18,7 +18,8 @@ require "droonga/collectors" module Droonga class SingleStep - def initialize(definition) + def initialize(dataset, definition) + @dataset = dataset @definition = definition end @@ -40,14 +41,28 @@ module Droonga reduce_key => collector_class.operator, } end - inputs =****@defin***** - if inputs.empty? - planner.send(:broadcast, message, options) - else - input = inputs.values.first - options[:key] = message["body"][input[:filter]]["key"] + + body = message["body"] + fact_input = find_fact_input(@definition.inputs, @dataset.fact, body) + if fact_input + options[:key] = body[fact_input[:filter]]["key"] planner.send(:scatter, message, options) + else + planner.send(:broadcast, message, options) + end + end + + def find_fact_input(inputs, fact, body) + inputs.each do |key, input| + if input[:type] == :table + # for backward compatibility. We can remove the following code + # when all our catalog.json specify "fact" parameter. + return input if fact.nil? + + return input if body[key] == fact + end end + nil end end end Modified: lib/droonga/step_runner.rb (+3 -2) =================================================================== --- lib/droonga/step_runner.rb 2014-03-17 22:45:15 +0900 (25ad39b) +++ lib/droonga/step_runner.rb 2014-03-19 11:36:03 +0900 (b0ae634) @@ -21,7 +21,8 @@ module Droonga class StepRunner include Loggable - def initialize(plugins) + def initialize(dataset, plugins) + @dataset = dataset @definitions = {} plugins.each do |name| plugin = Plugin.registry[name] @@ -43,7 +44,7 @@ module Droonga if definition.nil? raise UnsupportedMessageError.new(:planner, message) end - step = SingleStep.new(definition) + step = SingleStep.new(@dataset, definition) plan = step.plan(message) logger.trace("plan: done", :dataset => message["dataset"], Modified: test/unit/catalog/test_dataset.rb (+17 -0) =================================================================== --- test/unit/catalog/test_dataset.rb 2014-03-17 22:45:15 +0900 (5d6ef74) +++ test/unit/catalog/test_dataset.rb 2014-03-19 11:36:03 +0900 (7deea4c) @@ -59,4 +59,21 @@ class CatalogDatasetTest < Test::Unit::TestCase assert_equal(["groonga", "crud"], dataset.plugins) end end + + class FactTest < self + def test_nonexistent + data = { + } + dataset = create_dataset("dataset_name", data) + assert_nil(dataset.fact) + end + + def test_existent + data = { + "fact" => "Users", + } + dataset = create_dataset("dataset_name", data) + assert_equal("Users", dataset.fact) + end + end end -------------- next part -------------- HTML����������������������������...Download