OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChunkIter.cpp File Reference
#include "ChunkIter.h"
#include <cstdlib>
+ Include dependency graph for ChunkIter.cpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static DEVICE void decompress (const SQLTypeInfo &ti, int8_t *compressed, VarlenDatum *result, Datum *datum)
 
void ChunkIter_reset (ChunkIter *it)
 
DEVICE void ChunkIter_get_next (ChunkIter *it, bool uncompress, VarlenDatum *result, bool *is_end)
 
DEVICE void ChunkIter_get_nth (ChunkIter *it, int n, bool uncompress, VarlenDatum *result, bool *is_end)
 
DEVICE void ChunkIter_get_nth (ChunkIter *it, int n, ArrayDatum *result, bool *is_end)
 
DEVICE void ChunkIter_get_nth_varlen (ChunkIter *it, int n, ArrayDatum *result, bool *is_end)
 
DEVICE void ChunkIter_get_nth_varlen_notnull (ChunkIter *it, int n, ArrayDatum *result, bool *is_end)
 
DEVICE void ChunkIter_get_nth_point_coords (ChunkIter *it, int n, ArrayDatum *result, bool *is_end)
 

Function Documentation

DEVICE void ChunkIter_get_next ( ChunkIter it,
bool  uncompress,
VarlenDatum result,
bool *  is_end 
)

Definition at line 148 of file ChunkIter.cpp.

References ChunkIter::current_pos, ChunkIter::datum, decompress(), ChunkIter::end_pos, SQLTypeInfo::get_compression(), VarlenDatum::is_null, SQLTypeInfo::is_null(), kENCODING_NONE, VarlenDatum::length, VarlenDatum::pointer, ChunkIter::second_buf, ChunkIter::skip, ChunkIter::skip_size, and ChunkIter::type_info.

151  {
152  if (!it || it->current_pos >= it->end_pos) {
153  *is_end = true;
154  result->length = 0;
155  result->pointer = NULL;
156  result->is_null = true;
157  return;
158  }
159  *is_end = false;
160 
161  if (it->skip_size > 0) {
162  // for fixed-size
163  if (uncompress && (it->type_info.get_compression() != kENCODING_NONE)) {
164  decompress(it->type_info, it->current_pos, result, &it->datum);
165  } else {
166  result->length = static_cast<size_t>(it->skip_size);
167  result->pointer = it->current_pos;
168  result->is_null = it->type_info.is_null(result->pointer);
169  }
170  it->current_pos += it->skip * it->skip_size;
171  } else {
172  StringOffsetT offset = *(StringOffsetT*)it->current_pos;
173  result->length = static_cast<size_t>(*((StringOffsetT*)it->current_pos + 1) - offset);
174  result->pointer = it->second_buf + offset;
175  // @TODO(wei) treat zero length as null for now
176  result->is_null = (result->length == 0);
177  it->current_pos += it->skip * sizeof(StringOffsetT);
178  }
179 }
int8_t * current_pos
Definition: ChunkIter.h:33
SQLTypeInfo type_info
Definition: ChunkIter.h:31
static DEVICE void decompress(const SQLTypeInfo &ti, int8_t *compressed, VarlenDatum *result, Datum *datum)
Definition: ChunkIter.cpp:27
Datum datum
Definition: ChunkIter.h:39
bool is_null
Definition: Datum.h:59
int8_t * pointer
Definition: Datum.h:58
int32_t StringOffsetT
Definition: sqltypes.h:1495
int8_t * end_pos
Definition: ChunkIter.h:35
HOST DEVICE bool is_null(const Datum &d) const
Definition: sqltypes.h:868
int skip_size
Definition: ChunkIter.h:37
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
int8_t * second_buf
Definition: ChunkIter.h:32
int skip
Definition: ChunkIter.h:36
size_t length
Definition: Datum.h:57

+ Here is the call graph for this function:

DEVICE void ChunkIter_get_nth ( ChunkIter it,
int  n,
bool  uncompress,
VarlenDatum result,
bool *  is_end 
)

Definition at line 182 of file ChunkIter.cpp.

References ChunkIter::datum, decompress(), SQLTypeInfo::get_compression(), VarlenDatum::is_null, SQLTypeInfo::is_null(), FlatBufferManager::isFlatBuffer(), kENCODING_NONE, VarlenDatum::length, ChunkIter::num_elems, VarlenDatum::pointer, ChunkIter::second_buf, ChunkIter::skip_size, ChunkIter::start_pos, ChunkIter::type_info, and VarlenArray_get_nth().

Referenced by anonymous_namespace{ResultSetIteration.cpp}::lazy_fetch_chunk(), ResultSet::lazyReadInt(), ResultSet::makeVarlenTargetValue(), string_decode(), and anonymous_namespace{ExternalExecutor.cpp}::vt_column().

186  {
188  VarlenArray_get_nth(reinterpret_cast<int8_t*>(it), n, uncompress, result, is_end);
189  return;
190  }
191  if (!it || static_cast<size_t>(n) >= it->num_elems || n < 0) {
192  *is_end = true;
193  result->length = 0;
194  result->pointer = NULL;
195  result->is_null = true;
196  return;
197  }
198  *is_end = false;
199 
200  if (it->skip_size > 0) {
201  // for fixed-size
202  int8_t* current_pos = it->start_pos + n * it->skip_size;
203  if (uncompress && (it->type_info.get_compression() != kENCODING_NONE)) {
204  decompress(it->type_info, current_pos, result, &it->datum);
205  } else {
206  result->length = static_cast<size_t>(it->skip_size);
207  result->pointer = current_pos;
208  result->is_null = it->type_info.is_null(result->pointer);
209  }
210  } else {
211  int8_t* current_pos = it->start_pos + n * sizeof(StringOffsetT);
212  StringOffsetT offset = *(StringOffsetT*)current_pos;
213  result->length = static_cast<size_t>(*((StringOffsetT*)current_pos + 1) - offset);
214  result->pointer = it->second_buf + offset;
215  // @TODO(wei) treat zero length as null for now
216  result->is_null = (result->length == 0);
217  }
218 }
int8_t * start_pos
Definition: ChunkIter.h:34
SQLTypeInfo type_info
Definition: ChunkIter.h:31
static DEVICE void decompress(const SQLTypeInfo &ti, int8_t *compressed, VarlenDatum *result, Datum *datum)
Definition: ChunkIter.cpp:27
Datum datum
Definition: ChunkIter.h:39
bool is_null
Definition: Datum.h:59
int8_t * pointer
Definition: Datum.h:58
int32_t StringOffsetT
Definition: sqltypes.h:1495
size_t num_elems
Definition: ChunkIter.h:38
HOST DEVICE bool is_null(const Datum &d) const
Definition: sqltypes.h:868
int skip_size
Definition: ChunkIter.h:37
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
int8_t * second_buf
Definition: ChunkIter.h:32
constexpr double n
Definition: Utm.h:38
HOST static DEVICE bool isFlatBuffer(const void *buffer)
Definition: FlatBuffer.h:528
DEVICE void VarlenArray_get_nth(int8_t *buf, int n, ArrayDatum *result, bool *is_end)
Definition: sqltypes.h:1716
size_t length
Definition: Datum.h:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE void ChunkIter_get_nth ( ChunkIter it,
int  n,
ArrayDatum result,
bool *  is_end 
)

Definition at line 221 of file ChunkIter.cpp.

References SQLTypeInfo::get_notnull(), is_null(), SQLTypeInfo::is_null_fixlen_array(), FlatBufferManager::isFlatBuffer(), ChunkIter::num_elems, ChunkIter::second_buf, ChunkIter::skip_size, ChunkIter::start_pos, ChunkIter::type_info, and VarlenArray_get_nth().

221  {
223  VarlenArray_get_nth(reinterpret_cast<int8_t*>(it), n, result, is_end);
224  return;
225  }
226  if (!it || static_cast<size_t>(n) >= it->num_elems || n < 0) {
227  *is_end = true;
228  result->length = 0;
229  result->pointer = NULL;
230  result->is_null = true;
231  return;
232  }
233  *is_end = false;
234 
235  if (it->skip_size > 0) {
236  // for fixed-size
237  int8_t* current_pos = it->start_pos + n * it->skip_size;
238  result->length = static_cast<size_t>(it->skip_size);
239  result->pointer = current_pos;
240  bool is_null = false;
241  if (!it->type_info.get_notnull()) {
242  // Nulls can only be recognized when iterating over a !notnull-typed chunk
243  is_null = it->type_info.is_null_fixlen_array(result->pointer, result->length);
244  }
245  result->is_null = is_null;
246  } else {
247  int8_t* current_pos = it->start_pos + n * sizeof(ArrayOffsetT);
248  int8_t* next_pos = current_pos + sizeof(ArrayOffsetT);
249  ArrayOffsetT offset = *(ArrayOffsetT*)current_pos;
250  ArrayOffsetT next_offset = *(ArrayOffsetT*)next_pos;
251  if (next_offset < 0) { // Encoded NULL array
252  result->length = 0;
253  result->pointer = NULL;
254  result->is_null = true;
255  } else {
256  if (offset < 0) {
257  offset = -offset; // Previous array may have been NULL, remove negativity
258  }
259  result->length = static_cast<size_t>(next_offset - offset);
260  result->pointer = it->second_buf + offset;
261  result->is_null = false;
262  }
263  }
264 }
int8_t * start_pos
Definition: ChunkIter.h:34
SQLTypeInfo type_info
Definition: ChunkIter.h:31
HOST DEVICE bool is_null_fixlen_array(const int8_t *val, int array_size) const
Definition: sqltypes.h:930
size_t num_elems
Definition: ChunkIter.h:38
CONSTEXPR DEVICE bool is_null(const T &value)
int skip_size
Definition: ChunkIter.h:37
int32_t ArrayOffsetT
Definition: sqltypes.h:1496
int8_t * second_buf
Definition: ChunkIter.h:32
constexpr double n
Definition: Utm.h:38
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398
HOST static DEVICE bool isFlatBuffer(const void *buffer)
Definition: FlatBuffer.h:528
DEVICE void VarlenArray_get_nth(int8_t *buf, int n, ArrayDatum *result, bool *is_end)
Definition: sqltypes.h:1716

+ Here is the call graph for this function:

DEVICE void ChunkIter_get_nth_point_coords ( ChunkIter it,
int  n,
ArrayDatum result,
bool *  is_end 
)

Definition at line 321 of file ChunkIter.cpp.

References SQLTypeInfo::get_notnull(), is_null(), SQLTypeInfo::is_null_point_coord_array(), ChunkIter::num_elems, ChunkIter::skip_size, ChunkIter::start_pos, and ChunkIter::type_info.

324  {
325  if (!it || static_cast<size_t>(n) >= it->num_elems || n < 0) {
326  *is_end = true;
327  result->length = 0;
328  result->pointer = NULL;
329  result->is_null = true;
330  return;
331  }
332  *is_end = false;
333 
334  assert(it->skip_size > 0);
335  int8_t* current_pos = it->start_pos + n * it->skip_size;
336  result->length = static_cast<size_t>(it->skip_size);
337  result->pointer = current_pos;
338  bool is_null = false;
339  if (!it->type_info.get_notnull()) {
340  // Nulls can only be recognized when iterating over a !notnull-typed chunk
341  is_null = it->type_info.is_null_point_coord_array(result->pointer, result->length);
342  }
343  result->is_null = is_null;
344 }
int8_t * start_pos
Definition: ChunkIter.h:34
SQLTypeInfo type_info
Definition: ChunkIter.h:31
size_t num_elems
Definition: ChunkIter.h:38
CONSTEXPR DEVICE bool is_null(const T &value)
int skip_size
Definition: ChunkIter.h:37
constexpr double n
Definition: Utm.h:38
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398
HOST DEVICE bool is_null_point_coord_array(const int8_t *val, int array_size) const
Definition: sqltypes.h:963

+ Here is the call graph for this function:

DEVICE void ChunkIter_get_nth_varlen ( ChunkIter it,
int  n,
ArrayDatum result,
bool *  is_end 
)

Definition at line 267 of file ChunkIter.cpp.

References FlatBufferManager::isFlatBuffer(), anonymous_namespace{Utm.h}::n, ChunkIter::num_elems, ChunkIter::second_buf, ChunkIter::start_pos, and VarlenArray_get_nth().

270  {
272  VarlenArray_get_nth(reinterpret_cast<int8_t*>(it), n, result, is_end);
273  return;
274  }
275  *is_end = (!it || static_cast<size_t>(n) >= it->num_elems || n < 0);
276 
277  if (!*is_end) {
278  int8_t* current_pos = it->start_pos + n * sizeof(ArrayOffsetT);
279  int8_t* next_pos = current_pos + sizeof(ArrayOffsetT);
280  ArrayOffsetT offset = *(ArrayOffsetT*)current_pos;
281  ArrayOffsetT next_offset = *(ArrayOffsetT*)next_pos;
282 
283  if (next_offset >= 0) {
284  // Previous array may have been NULL, remove offset negativity
285  if (offset < 0) {
286  offset = -offset;
287  }
288  result->length = static_cast<size_t>(next_offset - offset);
289  result->pointer = it->second_buf + offset;
290  result->is_null = false;
291  return;
292  }
293  }
294  // Encoded NULL array or out of bounds
295  result->length = 0;
296  result->pointer = NULL;
297  result->is_null = true;
298 }
int8_t * start_pos
Definition: ChunkIter.h:34
size_t num_elems
Definition: ChunkIter.h:38
int32_t ArrayOffsetT
Definition: sqltypes.h:1496
int8_t * second_buf
Definition: ChunkIter.h:32
constexpr double n
Definition: Utm.h:38
HOST static DEVICE bool isFlatBuffer(const void *buffer)
Definition: FlatBuffer.h:528
DEVICE void VarlenArray_get_nth(int8_t *buf, int n, ArrayDatum *result, bool *is_end)
Definition: sqltypes.h:1716

+ Here is the call graph for this function:

DEVICE void ChunkIter_get_nth_varlen_notnull ( ChunkIter it,
int  n,
ArrayDatum result,
bool *  is_end 
)

Definition at line 301 of file ChunkIter.cpp.

References anonymous_namespace{Utm.h}::n, ChunkIter::num_elems, ChunkIter::second_buf, and ChunkIter::start_pos.

304  {
305  *is_end = (static_cast<size_t>(n) >= it->num_elems || n < 0);
306 
307  int8_t* current_pos = it->start_pos + n * sizeof(ArrayOffsetT);
308  int8_t* next_pos = current_pos + sizeof(ArrayOffsetT);
309  ArrayOffsetT offset = *(ArrayOffsetT*)current_pos;
310  ArrayOffsetT next_offset = *(ArrayOffsetT*)next_pos;
311 
312  result->length = static_cast<size_t>(next_offset - offset);
313  result->pointer = it->second_buf + offset;
314  result->is_null = false;
315 }
int8_t * start_pos
Definition: ChunkIter.h:34
size_t num_elems
Definition: ChunkIter.h:38
int32_t ArrayOffsetT
Definition: sqltypes.h:1496
int8_t * second_buf
Definition: ChunkIter.h:32
constexpr double n
Definition: Utm.h:38
void ChunkIter_reset ( ChunkIter it)

Definition at line 144 of file ChunkIter.cpp.

References ChunkIter::current_pos, and ChunkIter::start_pos.

144  {
145  it->current_pos = it->start_pos;
146 }
int8_t * start_pos
Definition: ChunkIter.h:34
int8_t * current_pos
Definition: ChunkIter.h:33
static DEVICE void decompress ( const SQLTypeInfo ti,
int8_t *  compressed,
VarlenDatum result,
Datum datum 
)
static

Definition at line 27 of file ChunkIter.cpp.

References Datum::bigintval, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_type(), Datum::intval, VarlenDatum::is_null, SQLTypeInfo::is_null(), kBIGINT, kDATE, kDECIMAL, kENCODING_DATE_IN_DAYS, kENCODING_DICT, kENCODING_DIFF, kENCODING_FIXED, kENCODING_NONE, kENCODING_RL, kENCODING_SPARSE, kINT, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, VarlenDatum::length, VarlenDatum::pointer, and Datum::smallintval.

Referenced by ChunkIter_get_next(), and ChunkIter_get_nth().

30  {
31  switch (ti.get_type()) {
32  case kSMALLINT:
33  result->length = sizeof(int16_t);
34  result->pointer = (int8_t*)&datum->smallintval;
35  switch (ti.get_compression()) {
36  case kENCODING_FIXED:
37  assert(ti.get_comp_param() == 8);
38  datum->smallintval = (int16_t) * (int8_t*)compressed;
39  break;
40  case kENCODING_RL:
41  case kENCODING_DIFF:
42  case kENCODING_SPARSE:
43  assert(false);
44  break;
45  default:
46  assert(false);
47  }
48  break;
49  case kINT:
50  result->length = sizeof(int32_t);
51  result->pointer = (int8_t*)&datum->intval;
52  switch (ti.get_compression()) {
53  case kENCODING_FIXED:
54  switch (ti.get_comp_param()) {
55  case 8:
56  datum->intval = (int32_t) * (int8_t*)compressed;
57  break;
58  case 16:
59  datum->intval = (int32_t) * (int16_t*)compressed;
60  break;
61  default:
62  assert(false);
63  }
64  break;
65  case kENCODING_RL:
66  case kENCODING_DIFF:
67  case kENCODING_SPARSE:
68  assert(false);
69  break;
70  default:
71  assert(false);
72  }
73  break;
74  case kBIGINT:
75  case kNUMERIC:
76  case kDECIMAL:
77  result->length = sizeof(int64_t);
78  result->pointer = (int8_t*)&datum->bigintval;
79  switch (ti.get_compression()) {
80  case kENCODING_FIXED:
81  switch (ti.get_comp_param()) {
82  case 8:
83  datum->bigintval = (int64_t) * (int8_t*)compressed;
84  break;
85  case 16:
86  datum->bigintval = (int64_t) * (int16_t*)compressed;
87  break;
88  case 32:
89  datum->bigintval = (int64_t) * (int32_t*)compressed;
90  break;
91  default:
92  assert(false);
93  }
94  break;
95  case kENCODING_RL:
96  case kENCODING_DIFF:
97  case kENCODING_SPARSE:
98  assert(false);
99  break;
100  default:
101  assert(false);
102  }
103  break;
104  case kTIME:
105  case kTIMESTAMP:
106  case kDATE:
107  switch (ti.get_compression()) {
108  case kENCODING_FIXED:
109  datum->bigintval = (int64_t) * (int32_t*)compressed;
110  break;
112  switch (ti.get_comp_param()) {
113  case 0:
114  case 32:
115  datum->bigintval = (int64_t) * (int32_t*)compressed;
116  break;
117  case 16:
118  datum->bigintval = (int64_t) * (int16_t*)compressed;
119  break;
120  default:
121  assert(false);
122  break;
123  }
124  break;
125  case kENCODING_RL:
126  case kENCODING_DIFF:
127  case kENCODING_DICT:
128  case kENCODING_SPARSE:
129  case kENCODING_NONE:
130  assert(false);
131  break;
132  default:
133  assert(false);
134  }
135  result->length = sizeof(int64_t);
136  result->pointer = (int8_t*)&datum->bigintval;
137  break;
138  default:
139  assert(false);
140  }
141  result->is_null = ti.is_null(*datum);
142 }
Definition: sqltypes.h:76
bool is_null
Definition: Datum.h:59
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
int32_t intval
Definition: Datum.h:75
int8_t * pointer
Definition: Datum.h:58
int64_t bigintval
Definition: Datum.h:76
int16_t smallintval
Definition: Datum.h:74
HOST DEVICE bool is_null(const Datum &d) const
Definition: sqltypes.h:868
Definition: sqltypes.h:80
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:402
Definition: sqltypes.h:72
size_t length
Definition: Datum.h:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function: