Sha256: 50dbe1d818a94e616fb429ec2623222552e6fd3cf8244ba7b95929821cb9a357

Contents?: true

Size: 1.73 KB

Versions: 26

Compression:

Stored size: 1.73 KB

Contents

module Embulk

  org.embulk.spi.util.dynamic.AbstractDynamicColumnSetter.module_eval do
    alias_method(:set, :setRubyObject)
  end

  class PageBuilder
    def initialize(schema, java_page_output)
      # TODO get task as an argument
      task = Java::SPI::Exec.newConfigSource.load_config(Java::DynamicPageBuilder::BuilderTask.java_class)
      @page_builder = Java::DynamicPageBuilder.new(task, Java::Injected::BufferAllocator, schema.to_java, java_page_output)
      @schema = schema
    end

    def add(record)
      i = 0
      m = record.size
      while i < m
        @page_builder.column(i).set(record[i])
        i += 1
      end
      @page_builder.addRecord
      nil
    end

    def [](index_or_column)
      case index_or_column
      when Integer
        @page_builder.column_or_null(index_or_column)
      when Column
        @page_builder.column_or_null(index_or_column.index)
      else
        @page_builder.column_or_null(index_or_column)
      end
    end

    def column(index_or_column)
      case index_or_column
      when Integer
        @page_builder.column(index_or_column)
      when Column
        @page_builder.column(index_or_column.index)
      else
        @page_builder.lookupColumn(index_or_column)
      end
    end

    def column_or_skip(index_or_column)
      case index_or_column
      when Integer
        @page_builder.column_or_skip(index_or_column)
      when Column
        @page_builder.column_or_skip(index_or_column.index)
      else
        @page_builder.column_or_skip(index_or_column)
      end
    end

    def add!
      @page_builder.add_record
    end

    def flush
      @page_builder.flush
    end

    def finish
      @page_builder.finish
    end

    def close
      @page_builder.close
    end
  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
embulk-0.7.11 lib/embulk/page_builder.rb
embulk-0.7.11-java lib/embulk/page_builder.rb
embulk-0.8.0 lib/embulk/page_builder.rb
embulk-0.8.0-java lib/embulk/page_builder.rb
embulk-0.7.10 lib/embulk/page_builder.rb
embulk-0.7.10-java lib/embulk/page_builder.rb
embulk-0.7.9 lib/embulk/page_builder.rb
embulk-0.7.9-java lib/embulk/page_builder.rb
embulk-0.7.8 lib/embulk/page_builder.rb
embulk-0.7.8-java lib/embulk/page_builder.rb
embulk-0.7.7 lib/embulk/page_builder.rb
embulk-0.7.7-java lib/embulk/page_builder.rb
embulk-0.7.6 lib/embulk/page_builder.rb
embulk-0.7.6-java lib/embulk/page_builder.rb
embulk-0.7.5 lib/embulk/page_builder.rb
embulk-0.7.5-java lib/embulk/page_builder.rb
embulk-0.7.4 lib/embulk/page_builder.rb
embulk-0.7.4-java lib/embulk/page_builder.rb
embulk-0.7.3 lib/embulk/page_builder.rb
embulk-0.7.3-java lib/embulk/page_builder.rb