Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Created March 15, 2015 04:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frsyuki/9c4128cd888cf12551b8 to your computer and use it in GitHub Desktop.
Save frsyuki/9c4128cd888cf12551b8 to your computer and use it in GitHub Desktop.
module Embulk
module Parser
class XxxParserPlugin < ParserPlugin
Plugin.register_parser("xxx", self)
def self.transaction(config, &control)
parser_task = config.load_config(Java::LineDecoder::DecoderTask)
# configuration code:
task = {
"decoder_task" => DataSource.from_java(parser_task.dump)
}
columns = [
# ...
]
yield(task, columns)
end
def init
@decoder_task = task.prop("decoder_task", :hash).load_task(Java::LineDecoder::DecoderTask)
end
def run(file_input)
decoder = Java::LineDecoder.new(file_input, @decoder_task)
while decoder.nextFile
while line = decoder.poll
# TODO record = parse(line)
record = ["col1", 2, 3.0]
page_builder.add(record)
end
end
page_builder.finish
end
end
end
end
@muziyoshiz
Copy link

こちらのコードを私の環境(Embulk 0.5.2)で試してみたところ、22行目で以下のエラーが出て動きませんでした。

undefined method `prop' for {"decoder_task"=>{"Charset"=>"UTF-8", "Newline"=>"LF"}}:Embulk::DataSource

ここは、Embulk::DataSourceの定義を確認して、propをparamに直しました。

    @decoder_task = task.param("decoder_task", :hash).load_task(Java::LineDecoder::DecoderTask)

また、28行目でcannot convert instance of class org.jruby.RubyObject to booleanというエラーが出ましたが、これは @hiroysatoapache_log_ruby.rbを参考に

    decoder = Java::LineDecoder.new(file_input.instance_eval { @java_file_input }, decoder_task)

と書き換えたところ動作しました。ありがとうございます!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment