Class: Trinamo::DynamodbConverter

Inherits:
BaseConverter show all
Defined in:
lib/trinamo/converter/dynamodb_converter.rb

Instance Attribute Summary

Attributes inherited from BaseConverter

#ddl, #ddl_yaml_path

Instance Method Summary collapse

Methods inherited from BaseConverter

#initialize

Constructor Details

This class inherits a constructor from Trinamo::BaseConverter

Instance Method Details

#convertObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/trinamo/converter/dynamodb_converter.rb', line 5

def convert
  ddl_body = @ddl[:tables].map do |h|
    fields = ([h[:hash_key]] + [h[:range_key]] + [h[:attributes]]).flatten.compact
    <<-DDL.unindent
      -- #{h[:name]}_ddb
      CREATE EXTERNAL TABLE #{h[:name]}_ddb (
        #{fields.map { |attr| "#{attr[:name]} #{attr[:type].upcase}" }.join(',')}
      )
      STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler'
      TBLPROPERTIES (
        'dynamodb.table.name' = '#{h[:name]}',
        'dynamodb.column.mapping' = '#{fields.map { |attr| "#{attr[:name]}:#{attr[:name]}" }.join(',') }'
      );
    DDL
  end

  ddl_body.join("\n")
end