Class: Altertable::Lakehouse::QueryResult

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/altertable/lakehouse/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum) ⇒ QueryResult

Returns a new instance of QueryResult.



256
257
258
259
260
# File 'lib/altertable/lakehouse/client.rb', line 256

def initialize(enum)
  @enum = enum
  @metadata = nil
  @columns = nil
end

Instance Attribute Details

#columnsObject (readonly)

metadata: the stream header object (first NDJSON line) columns: array of column name strings (second NDJSON line)



254
255
256
# File 'lib/altertable/lakehouse/client.rb', line 254

def columns
  @columns
end

#metadataObject (readonly)

metadata: the stream header object (first NDJSON line) columns: array of column name strings (second NDJSON line)



254
255
256
# File 'lib/altertable/lakehouse/client.rb', line 254

def 
  @metadata
end

Instance Method Details

#each(&block) ⇒ Object



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/altertable/lakehouse/client.rb', line 262

def each(&block)
  # The real mock streams:
  #   line 1: { "statement":…, "session_id":…, … }   (header object)
  #   line 2: ["col1", "col2", …]                     (column names array)
  #   line 3+: [val1, val2, …]                        (row value arrays)
  # We zip each row array with the column names to produce a Hash.
  line_index = 0

  @enum.each do |item|
    case line_index
    when 0
      @metadata = item
    when 1
      @columns = item
    else
      if @columns.is_a?(Array) && item.is_a?(Array)
        block.call(@columns.zip(item).to_h)
      else
        block.call(item)
      end
    end
    line_index += 1
  end
end