Sha256: d886347da82d166f423b86addf8746d62341f3d222bc668150c0a11107e17951

Contents?: true

Size: 810 Bytes

Versions: 17

Compression:

Stored size: 810 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_seperated_output(",", out_file)
    end
    
    def to_tsv(out_file=nil)
      to_seperated_output("\t", out_file)
    end
    
    def as_arrays
      @as_arrays ||= self.map{ |r| @schema.coerce_row_to_array(r) }
    end
    
    private
    
    def to_seperated_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

17 entries across 17 versions & 2 rubygems

Version Path
rbhive-1.0.3.pre lib/rbhive/result_set.rb
rbhive-vidma-1.0.2.pre1.pre.thrift0.9.1 lib/rbhive/result_set.rb
rbhive-vidma-1.0.2.pre.pre.thrift0.9.1 lib/rbhive/result_set.rb
rbhive-1.0.2.pre lib/rbhive/result_set.rb
rbhive-1.0.1.pre lib/rbhive/result_set.rb
rbhive-1.0.0.pre lib/rbhive/result_set.rb
rbhive-0.6.0 lib/rbhive/result_set.rb
rbhive-0.5.3 lib/rbhive/result_set.rb
rbhive-0.5.2 lib/rbhive/result_set.rb
rbhive-0.5.1 lib/rbhive/result_set.rb
rbhive-0.5.0 lib/rbhive/result_set.rb
rbhive-0.2.95 lib/rbhive/result_set.rb
rbhive-0.2.94 lib/rbhive/result_set.rb
rbhive-0.2.93 lib/rbhive/result_set.rb
rbhive-0.2.92 lib/rbhive/result_set.rb
rbhive-0.2.91 lib/rbhive/result_set.rb
rbhive-0.2.9 lib/rbhive/result_set.rb