Class: Embulk::PageBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/embulk/page_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema, java_page_output) ⇒ PageBuilder

Returns a new instance of PageBuilder.



8
9
10
11
12
13
14
# File 'lib/embulk/page_builder.rb', line 8

def initialize(schema, java_page_output)
  require 'msgpack'  # used at DynamicPageBuilder.set(Value)
  # 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

Instance Method Details

#[](index_or_column) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/embulk/page_builder.rb', line 27

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

#add(record) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/embulk/page_builder.rb', line 16

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

#add!Object



60
61
62
# File 'lib/embulk/page_builder.rb', line 60

def add!
  @page_builder.add_record
end

#closeObject



72
73
74
# File 'lib/embulk/page_builder.rb', line 72

def close
  @page_builder.close
end

#column(index_or_column) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/embulk/page_builder.rb', line 38

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

#column_or_skip(index_or_column) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/embulk/page_builder.rb', line 49

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

#finishObject



68
69
70
# File 'lib/embulk/page_builder.rb', line 68

def finish
  @page_builder.finish
end

#flushObject



64
65
66
# File 'lib/embulk/page_builder.rb', line 64

def flush
  @page_builder.flush
end