Class: Pinot::ResultTable
- Inherits:
-
Object
- Object
- Pinot::ResultTable
- Defined in:
- lib/pinot/response.rb
Instance Attribute Summary collapse
-
#data_schema ⇒ Object
readonly
Returns the value of attribute data_schema.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #column_count ⇒ Object
- #column_data_type(i) ⇒ Object
- #column_name(i) ⇒ Object
- #get(row, col) ⇒ Object
- #get_double(row, col) ⇒ Object
- #get_float(row, col) ⇒ Object
- #get_int(row, col) ⇒ Object
- #get_long(row, col) ⇒ Object
- #get_string(row, col) ⇒ Object
-
#initialize(hash) ⇒ ResultTable
constructor
A new instance of ResultTable.
- #row_count ⇒ Object
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_schema ⇒ Object (readonly)
Returns the value of attribute data_schema.
69 70 71 |
# File 'lib/pinot/response.rb', line 69 def data_schema @data_schema end |
#rows ⇒ Object (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_count ⇒ Object
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
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/pinot/response.rb', line 167 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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/pinot/response.rb', line 151 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 |
# 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) return 0 if bd.infinite? || bd.nan? rescue return 0 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
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/pinot/response.rb', line 128 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) return 0 if bd.infinite? || bd.nan? rescue return 0 int_val = bd.to_i return 0 unless bd == BigDecimal(int_val.to_s) return 0 if int_val > INT64_MAX || int_val < INT64_MIN int_val else int_val = Integer(raw) return 0 if int_val > INT64_MAX || int_val < INT64_MIN int_val end 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_count ⇒ Object
79 80 81 |
# File 'lib/pinot/response.rb', line 79 def row_count @rows.length end |