Sha256: eba934d89e1c61d93fd7cb5ccbfaaa6fdf613a59d9fc25d9f2b7c0a3f96e6305

Contents?: true

Size: 1.73 KB

Versions: 15

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::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

15 entries across 15 versions & 1 rubygems

Version Path
embulk-0.6.27 lib/embulk/page_builder.rb
embulk-0.6.26 lib/embulk/page_builder.rb
embulk-0.6.25 lib/embulk/page_builder.rb
embulk-0.6.24 lib/embulk/page_builder.rb
embulk-0.6.23 lib/embulk/page_builder.rb
embulk-0.6.22 lib/embulk/page_builder.rb
embulk-0.6.21 lib/embulk/page_builder.rb
embulk-0.6.20 lib/embulk/page_builder.rb
embulk-0.6.19 lib/embulk/page_builder.rb
embulk-0.6.18 lib/embulk/page_builder.rb
embulk-0.6.17 lib/embulk/page_builder.rb
embulk-0.6.16 lib/embulk/page_builder.rb
embulk-0.6.15 lib/embulk/page_builder.rb
embulk-0.6.14 lib/embulk/page_builder.rb
embulk-0.6.13 lib/embulk/page_builder.rb