Class: GroongaDelta::Mapping::GroongaTable
- Inherits:
-
Object
- Object
- GroongaDelta::Mapping::GroongaTable
- Defined in:
- lib/groonga-delta/mapping.rb
Instance Attribute Summary collapse
-
#groonga_columns ⇒ Object
readonly
Returns the value of attribute groonga_columns.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #generate_record(source_record) ⇒ Object
- #generate_record_batch(source_records) ⇒ Object
-
#initialize(name, groonga_columns) ⇒ GroongaTable
constructor
A new instance of GroongaTable.
Constructor Details
#initialize(name, groonga_columns) ⇒ GroongaTable
Returns a new instance of GroongaTable.
137 138 139 140 |
# File 'lib/groonga-delta/mapping.rb', line 137 def initialize(name, groonga_columns) @name = name @groonga_columns = groonga_columns end |
Instance Attribute Details
#groonga_columns ⇒ Object (readonly)
Returns the value of attribute groonga_columns.
136 137 138 |
# File 'lib/groonga-delta/mapping.rb', line 136 def groonga_columns @groonga_columns end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
135 136 137 |
# File 'lib/groonga-delta/mapping.rb', line 135 def name @name end |
Instance Method Details
#generate_record(source_record) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/groonga-delta/mapping.rb', line 142 def generate_record(source_record) record = {} @groonga_columns.each do |groonga_column| begin value = groonga_column.generate_value(source_record) record[groonga_column.name.to_sym] = value rescue => error raise GenerationError.new(source_record, groonga_column, error) end end record end |
#generate_record_batch(source_records) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/groonga-delta/mapping.rb', line 155 def generate_record_batch(source_records) fields = @groonga_columns.collect do |groonga_column| { name: groonga_column.name, data_type: groonga_column.arrow_type, } end builder = Arrow::RecordBatchBuilder.new(fields) groonga_records = Enumerator.new do |yielder| source_records.each do |source_record| yielder << generate_record(source_record) end end builder.append_records(groonga_records) builder.flush end |