class Daru::IO::Importers::Avro

Avro Importer Class, that extends `read_avro` method to `Daru::DataFrame`

Public Class Methods

new() click to toggle source

Checks for required gem dependencies of Avro Importer

@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.
# File lib/daru/io/importers/avro.rb, line 14
def initialize
  optional_gem 'avro'
  optional_gem 'snappy'
end

Public Instance Methods

call() click to toggle source

Imports a `Daru::DataFrame` from an Avro Importer instance

@return [Daru::DataFrame]

@example Importing from an Avro file

df = instance.call

#=> #<Daru::DataFrame(3x3)>
#        name points winner
#    0   Dany    100   true
#    1    Jon    100   true
#    2 Tyrion    100   true
# File lib/daru/io/importers/avro.rb, line 48
def call
  Daru::DataFrame.new(@data)
end
read(path) click to toggle source

Reads data from an avro file

@!method self.read(path)

@param path [String] Path to Avro file, where the dataframe is to be imported from.

@return [Daru::IO::Importers::Avro]

@example Reading from avro file

instance = Daru::IO::Importers::Avro.read("azorahai.avro")
# 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