Class: CSV2Avro

Inherits:
Object
  • Object
show all
Defined in:
lib/csv2avro.rb,
lib/csv2avro/schema.rb,
lib/csv2avro/version.rb,
lib/csv2avro/converter.rb,
lib/csv2avro/avro_writer.rb,
lib/csv2avro/datum_writer.rb,
lib/csv2avro/schema_validator.rb

Defined Under Namespace

Classes: AvroWriter, Converter, DatumWriter, Schema, SchemaValidationError, SchemaValidator

Constant Summary collapse

VERSION =
"1.3.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CSV2Avro

Returns a new instance of CSV2Avro.



17
18
19
20
21
22
23
24
# File 'lib/csv2avro.rb', line 17

def initialize(options)
  @input_path = ARGV.first
  @schema_path = options.delete(:schema)
  @bad_rows_path = options.delete(:bad_rows)
  @stdout_option = !input_path || options.delete(:stdout)

  @options = options
end

Instance Attribute Details

#bad_rows_pathObject (readonly)

Returns the value of attribute bad_rows_path.



7
8
9
# File 'lib/csv2avro.rb', line 7

def bad_rows_path
  @bad_rows_path
end

#input_pathObject (readonly)

Returns the value of attribute input_path.



7
8
9
# File 'lib/csv2avro.rb', line 7

def input_path
  @input_path
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/csv2avro.rb', line 7

def options
  @options
end

#schema_pathObject (readonly)

Returns the value of attribute schema_path.



7
8
9
# File 'lib/csv2avro.rb', line 7

def schema_path
  @schema_path
end

#stdout_optionObject (readonly)

Returns the value of attribute stdout_option.



7
8
9
# File 'lib/csv2avro.rb', line 7

def stdout_option
  @stdout_option
end

Class Method Details

.loggerObject



9
10
11
# File 'lib/csv2avro.rb', line 9

def self.logger
  @logger ||= Logr::Logger.new('csv2avro')
end

Instance Method Details

#convertObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/csv2avro.rb', line 26

def convert
  logger.event('started_converting', filename: input_filename)
        .monitored("Started converting #{input_filename}", "Started converting #{input_filename}")
        .info("Started converting #{input_filename}")

  lines = Converter.new(reader, writer, bad_rows_writer, input_filename, options, schema: schema).convert

  logger.event('finished_converting', filename: input_filename)
        .metric('lines_processed', lines)
        .monitored("Finished converting #{input_filename}", "Finished converting #{input_filename}, processed #{lines} lines in total.")
        .info("Finished converting #{input_filename}")
ensure
  writer.close if writer
  bad_rows_writer.close
end

#loggerObject



13
14
15
# File 'lib/csv2avro.rb', line 13

def logger
  self.class.logger
end