lib/impala/cursor.rb in impala-0.1.3 vs lib/impala/cursor.rb in impala-0.1.4

- old
+ new

@@ -6,11 +6,10 @@ include Enumerable def initialize(handle, service, buffer_length=1024) @handle = handle @service = service - @metadata = @service.get_results_metadata(@handle) @buffer_length = buffer_length @row_buffer = [] @done = false @@ -69,10 +68,14 @@ !@done || !@row_buffer.empty? end private + def metadata + @metadata ||= @service.get_results_metadata(@handle) + end + def fetch_more return if @done begin res = @service.fetch(@handle, false, @buffer_length) @@ -86,13 +89,13 @@ @done = true unless res.has_more end def parse_row(raw) row = {} - fields = raw.split(@metadata.delim) + fields = raw.split(metadata.delim) - fields.zip(@metadata.schema.fieldSchemas).each do |raw_value, schema| + fields.zip(metadata.schema.fieldSchemas).each do |raw_value, schema| value = convert_raw_value(raw_value, schema) row[schema.name.to_sym] = value end row @@ -112,13 +115,15 @@ else raise ParsingError.new("Invalid value for boolean: #{value}") end when 'tinyint', 'int', 'bigint' value.to_i - when 'double' + when 'double', 'float' value.to_f + when "timestamp" + Time.parse(value) else raise ParsingError.new("Unknown type: #{schema.type}") end end end -end \ No newline at end of file +end