class Aq::Schema

Public Class Methods

new() click to toggle source
# File lib/aq/schema.rb, line 7
def initialize
  @schema = []
end

Public Instance Methods

append_column(name, type, mode=nil) click to toggle source
# File lib/aq/schema.rb, line 11
def append_column(name, type, mode=nil)
  nullable = mode != 'required'
  column = {name: name, type: convert_type_from_bq_to_athena(type), nullable: nullable}
  @schema.push column
end
get_all() click to toggle source
# File lib/aq/schema.rb, line 17
def get_all
  @schema
end

Private Instance Methods

convert_type_from_bq_to_athena(type) click to toggle source
# File lib/aq/schema.rb, line 22
    def convert_type_from_bq_to_athena(type)
=begin
      Schema correspondence table
      ----------+----------
      BQ        | Athena
      ----------+----------
      STRING    | STRING
      BYTES     | ?
      INTEGER   | INT
      FLOAT     | DOUBLE
      BOOLEAN   | BOOLEAN
      RECORD    | ARRAY or MAP
      TIMESTAMP | TIMESTAMP
      DATE      | DATE
      TIME      | TIMESTAMP
      DATETIME  | TIMESTAMP
=end
      type.upcase!
      case type
      when 'BYTES'
        raise NotSupportedError.new '`BYTES` is not supported in Athena.'
      when 'INTEGER'
        'BIGINT'
      when 'FLOAT'
        'DOUBLE'
      when 'RECORD'
        raise NotImplementedError.new 'Sorry, `RECORD` is not supported yet in aq.'
      when 'TIME', 'DATETIME'
        'TIMESTAMP'
      else
        type
      end
    end