Sha256: 231ee36a167a5b8d0c8c35fd911968ae3d897ff39db436f8699f1e743a87379f

Contents?: true

Size: 783 Bytes

Versions: 7

Compression:

Stored size: 783 Bytes

Contents

module RBHive
  class ResultSet < Array
    def initialize(rows, schema)
      @schema = schema
      super(rows.map {|r| @schema.coerce_row(r) })
    end

    def column_names
      @schema.column_names
    end

    def column_type_map
      @schema.column_type_map
    end

    def to_csv(out_file=nil)
      to_separated_output(",", out_file)
    end

    def to_tsv(out_file=nil)
      to_separated_output("\t", out_file)
    end

    def as_arrays
      @as_arrays ||= self.map{ |r| @schema.coerce_row_to_array(r) }
    end

    private

    def to_separated_output(sep, out_file)
      rows = self.map { |r| @schema.coerce_row_to_array(r).join(sep) }
      sv = rows.join("\n")
      return sv if out_file.nil?
      File.open(out_file, 'w+') { |f| f << sv }
    end
  end
end

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
rbhive-u2i-1.0.2 lib/rbhive/result_set.rb
rbhive-u2i-1.0.1 lib/rbhive/result_set.rb
rbhive-1.0.0 lib/rbhive/result_set.rb
sequel_impala-1.1.0 lib/rbhive/result_set.rb
sequel-impala-1.1.0 lib/rbhive/result_set.rb
sequel-impala-1.0.1 lib/rbhive/result_set.rb
rbhive-u2i-1.0.0 lib/rbhive/result_set.rb