class Trinamo::S3Converter

Public Instance Methods

convert() click to toggle source
# File lib/trinamo/converter/s3_converter.rb, line 5
    def convert
      ddl_body = @ddl[:tables].map do |h|
        if h[:s3_location]
          fields = ([h[:hash_key]] + [h[:range_key]] + [h[:attributes]]).flatten.compact
          partitioned_by = h[:s3_partition] ? "PARTITIONED BY (#{h[:s3_partition].map { |attr| "#{attr[:name]} #{attr[:type].upcase}" }.join(',')})" : ''
          <<-DDL.unindent
            -- #{h[:name]}_s3
            CREATE EXTERNAL TABLE #{Trinamo::Converter.remove_head_underscore(h[:name])}_s3 (
              #{fields.map { |attr| "#{attr[:name]} #{attr[:type].upcase}" }.join(',')}
            ) #{partitioned_by}
            ROW FORMAT DELIMITED FIELDS TERMINATED BY '\\t' LINES TERMINATED BY '\\n'
            LOCATION '#{h[:s3_location]}';
          DDL
        else
          STDERR.puts "[ERROR] The location of #{Trinamo::Converter.remove_head_underscore(h[:name])}_s3 is not found"
          nil
        end
      end

      ddl_body.compact.join("\n")
    end