Class: Daru::IO::Importers::Avro
- Defined in:
- lib/daru/io/importers/avro.rb
Overview
Avro Importer Class, that extends read_avro
method to Daru::DataFrame
Class Method Summary collapse
-
.read(path) ⇒ Daru::IO::Importers::Avro
Reads data from an avro file.
Instance Method Summary collapse
-
#call ⇒ Daru::DataFrame
Imports a
Daru::DataFrame
from an Avro Importer instance. -
#initialize ⇒ Avro
constructor
Checks for required gem dependencies of Avro Importer.
-
#read(path) ⇒ Daru::IO::Importers::Avro
Reads data from an avro file.
Methods inherited from Base
Constructor Details
#initialize ⇒ Avro
Note:
The 'snappy' gem handles compressions and is used within Avro gem. Yet, it isn't specified as a dependency in Avro gem. Hence, it has been added separately.
Checks for required gem dependencies of Avro Importer
14 15 16 17 |
# File 'lib/daru/io/importers/avro.rb', line 14 def initialize optional_gem 'avro' optional_gem 'snappy' end |
Class Method Details
.read(path) ⇒ Daru::IO::Importers::Avro
Reads data from an avro file
29 30 31 32 33 34 |
# File 'lib/daru/io/importers/avro.rb', line 29 def read(path) @path = path @buffer = StringIO.new(File.read(@path)) @data = ::Avro::DataFile::Reader.new(@buffer, ::Avro::IO::DatumReader.new).to_a self end |
Instance Method Details
#call ⇒ Daru::DataFrame
Imports a Daru::DataFrame
from an Avro Importer instance
48 49 50 |
# File 'lib/daru/io/importers/avro.rb', line 48 def call Daru::DataFrame.new(@data) end |
#read(path) ⇒ Daru::IO::Importers::Avro
Reads data from an avro file
29 30 31 32 33 34 |
# File 'lib/daru/io/importers/avro.rb', line 29 def read(path) @path = path @buffer = StringIO.new(File.read(@path)) @data = ::Avro::DataFile::Reader.new(@buffer, ::Avro::IO::DatumReader.new).to_a self end |