Class: Embulk::PageBuilder

Inherits:
Object
  • Object
show all
Defined in:
embulk-core/src/main/ruby/embulk/page_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema, java_page_output = nil, java_dynamic_page_builder: nil) ⇒ PageBuilder

Returns a new instance of PageBuilder



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'embulk-core/src/main/ruby/embulk/page_builder.rb', line 27

def initialize(schema, java_page_output=nil, java_dynamic_page_builder: nil)
  if java_page_output.nil? && java_dynamic_page_builder.nil?
    raise ArgumentError, 'PageBuilder.new must take either of java_page_output or java_dynamic_page_builder'
  end
  if java_page_output && java_dynamic_page_builder
    raise ArgumentError, 'PageBuilder.new must not take both java_page_output and java_dynamic_page_builder'
  end

  require 'msgpack'  # used at DynamicPageBuilder.set(Value)

  if 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.createWithTimestampMetadataFromBuilderTask(
        task, Java::Injected::BufferAllocator, schema.to_java, java_page_output)
  else
    @page_builder = java_dynamic_page_builder
  end

  @schema = schema
end

Instance Method Details

#[](index_or_column) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'embulk-core/src/main/ruby/embulk/page_builder.rb', line 60

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



49
50
51
52
53
54
55
56
57
58
# File 'embulk-core/src/main/ruby/embulk/page_builder.rb', line 49

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



93
94
95
# File 'embulk-core/src/main/ruby/embulk/page_builder.rb', line 93

def add!
  @page_builder.add_record
end

#closeObject



105
106
107
# File 'embulk-core/src/main/ruby/embulk/page_builder.rb', line 105

def close
  @page_builder.close
end

#column(index_or_column) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'embulk-core/src/main/ruby/embulk/page_builder.rb', line 71

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



82
83
84
85
86
87
88
89
90
91
# File 'embulk-core/src/main/ruby/embulk/page_builder.rb', line 82

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



101
102
103
# File 'embulk-core/src/main/ruby/embulk/page_builder.rb', line 101

def finish
  @page_builder.finish
end

#flushObject



97
98
99
# File 'embulk-core/src/main/ruby/embulk/page_builder.rb', line 97

def flush
  @page_builder.flush
end