Class: Pinot::ResultTable

Inherits:
Object
  • Object
show all
Defined in:
lib/pinot/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ ResultTable

Returns a new instance of ResultTable.



71
72
73
74
75
76
77
# File 'lib/pinot/response.rb', line 71

def initialize(hash)
  @data_schema = RespSchema.new(hash["dataSchema"] || {})
  raw_rows = hash["rows"] || []
  @rows = raw_rows.map do |row|
    row.map { |cell| cell.is_a?(Numeric) ? JsonNumber.new(cell) : cell }
  end
end

Instance Attribute Details

#data_schemaObject (readonly)

Returns the value of attribute data_schema.



69
70
71
# File 'lib/pinot/response.rb', line 69

def data_schema
  @data_schema
end

#rowsObject (readonly)

Returns the value of attribute rows.



69
70
71
# File 'lib/pinot/response.rb', line 69

def rows
  @rows
end

Instance Method Details

#column_countObject



83
84
85
# File 'lib/pinot/response.rb', line 83

def column_count
  @data_schema.column_names.length
end

#column_data_type(i) ⇒ Object



91
92
93
# File 'lib/pinot/response.rb', line 91

def column_data_type(i)
  @data_schema.column_data_types[i]
end

#column_name(i) ⇒ Object



87
88
89
# File 'lib/pinot/response.rb', line 87

def column_name(i)
  @data_schema.column_names[i]
end

#get(row, col) ⇒ Object



95
96
97
# File 'lib/pinot/response.rb', line 95

def get(row, col)
  @rows[row][col]
end

#get_double(row, col) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/pinot/response.rb', line 180

def get_double(row, col)
  cell = @rows[row][col]
  return 0.0 unless cell.is_a?(JsonNumber)

  raw = cell.raw
  begin
    f = Float(raw)
    return 0.0 if f.infinite? || f.nan?

    f
  rescue ArgumentError, TypeError
    0.0
  end
end

#get_float(row, col) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/pinot/response.rb', line 162

def get_float(row, col)
  cell = @rows[row][col]
  return 0.0 unless cell.is_a?(JsonNumber)

  raw = cell.raw
  begin
    f = Float(raw)
    return 0.0 if f.infinite? || f.nan?

    f32 = f.to_f
    return 0.0 if f32.abs > FLOAT32_MAX

    f32
  rescue ArgumentError, TypeError
    0.0
  end
end

#get_int(row, col) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/pinot/response.rb', line 103

def get_int(row, col)
  cell = @rows[row][col]
  return 0 unless cell.is_a?(JsonNumber)

  raw = cell.raw
  begin
    # Try parsing as integer first
    if raw.include?(".") || raw.include?("e") || raw.include?("E")
      # Floating point string — check if it's a whole number
      bd = BigDecimal(raw)
      begin
        return 0 if bd.infinite? || bd.nan?
      rescue StandardError
        return 0
      end
      int_val = bd.to_i
      return 0 unless bd == BigDecimal(int_val.to_s)
      return 0 if int_val > INT32_MAX || int_val < INT32_MIN

      int_val.to_i
    else
      int_val = Integer(raw)
      return 0 if int_val > INT32_MAX || int_val < INT32_MIN

      int_val
    end
  rescue ArgumentError, TypeError
    0
  end
end

#get_long(row, col) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/pinot/response.rb', line 134

def get_long(row, col)
  cell = @rows[row][col]
  return 0 unless cell.is_a?(JsonNumber)

  raw = cell.raw
  begin
    if raw.include?(".") || raw.include?("e") || raw.include?("E")
      bd = BigDecimal(raw)
      begin
        return 0 if bd.infinite? || bd.nan?
      rescue StandardError
        return 0
      end
      int_val = bd.to_i
      return 0 unless bd == BigDecimal(int_val.to_s)

    else
      int_val = Integer(raw)

    end
    return 0 if int_val > INT64_MAX || int_val < INT64_MIN

    int_val
  rescue ArgumentError, TypeError
    0
  end
end

#get_string(row, col) ⇒ Object



99
100
101
# File 'lib/pinot/response.rb', line 99

def get_string(row, col)
  @rows[row][col].to_s
end

#row_countObject



79
80
81
# File 'lib/pinot/response.rb', line 79

def row_count
  @rows.length
end