OmniSciDB  04ee39c94c
ChunkIter.cpp File Reference
#include "ChunkIter.h"
#include <cstdlib>
+ Include dependency graph for ChunkIter.cpp:

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)
 

Function Documentation

◆ ChunkIter_get_next()

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

Definition at line 147 of file ChunkIter.cpp.

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

Referenced by scan_chunk().

150  {
151  if (it->current_pos >= it->end_pos) {
152  *is_end = true;
153  result->length = 0;
154  result->pointer = NULL;
155  result->is_null = true;
156  return;
157  }
158  *is_end = false;
159 
160  if (it->skip_size > 0) {
161  // for fixed-size
162  if (uncompress && (it->type_info.get_compression() != kENCODING_NONE)) {
163  decompress(it->type_info, it->current_pos, result, &it->datum);
164  } else {
165  result->length = static_cast<size_t>(it->skip_size);
166  result->pointer = it->current_pos;
167  result->is_null = it->type_info.is_null(result->pointer);
168  }
169  it->current_pos += it->skip * it->skip_size;
170  } else {
171  StringOffsetT offset = *(StringOffsetT*)it->current_pos;
172  result->length = static_cast<size_t>(*((StringOffsetT*)it->current_pos + 1) - offset);
173  result->pointer = it->second_buf + offset;
174  // @TODO(wei) treat zero length as null for now
175  result->is_null = (result->length == 0);
176  it->current_pos += it->skip * sizeof(StringOffsetT);
177  }
178 }
int8_t * current_pos
Definition: ChunkIter.h:32
SQLTypeInfo type_info
Definition: ChunkIter.h:30
static DEVICE void decompress(const SQLTypeInfo &ti, int8_t *compressed, VarlenDatum *result, Datum *datum)
Definition: ChunkIter.cpp:26
Datum datum
Definition: ChunkIter.h:38
bool is_null
Definition: sqltypes.h:73
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
int8_t * pointer
Definition: sqltypes.h:72
int32_t StringOffsetT
Definition: sqltypes.h:877
int8_t * end_pos
Definition: ChunkIter.h:34
int skip_size
Definition: ChunkIter.h:36
int8_t * second_buf
Definition: ChunkIter.h:31
int skip
Definition: ChunkIter.h:35
HOST DEVICE bool is_null(const Datum &d) const
Definition: sqltypes.h:537
size_t length
Definition: sqltypes.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ChunkIter_get_nth() [1/2]

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

Definition at line 181 of file ChunkIter.cpp.

References ChunkIter::datum, decompress(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), VarlenDatum::is_null, SQLTypeInfoCore< TYPE_FACET_PACK >::is_null(), kENCODING_NONE, VarlenDatum::length, ChunkIter::num_elems, VarlenDatum::pointer, ChunkIter::second_buf, ChunkIter::skip_size, ChunkIter::start_pos, and ChunkIter::type_info.

Referenced by anonymous_namespace{ResultSetIteration.cpp}::lazy_fetch_chunk(), ResultSet::lazyReadInt(), ResultSet::makeVarlenTargetValue(), scan_chunk(), Importer_NS::RenderGroupAnalyzer::seedFromExistingTableContents(), and string_decode().

185  {
186  if (static_cast<size_t>(n) >= it->num_elems || n < 0) {
187  *is_end = true;
188  result->length = 0;
189  result->pointer = NULL;
190  result->is_null = true;
191  return;
192  }
193  *is_end = false;
194 
195  if (it->skip_size > 0) {
196  // for fixed-size
197  int8_t* current_pos = it->start_pos + n * it->skip_size;
198  if (uncompress && (it->type_info.get_compression() != kENCODING_NONE)) {
199  decompress(it->type_info, current_pos, result, &it->datum);
200  } else {
201  result->length = static_cast<size_t>(it->skip_size);
202  result->pointer = current_pos;
203  result->is_null = it->type_info.is_null(result->pointer);
204  }
205  } else {
206  int8_t* current_pos = it->start_pos + n * sizeof(StringOffsetT);
207  StringOffsetT offset = *(StringOffsetT*)current_pos;
208  result->length = static_cast<size_t>(*((StringOffsetT*)current_pos + 1) - offset);
209  result->pointer = it->second_buf + offset;
210  // @TODO(wei) treat zero length as null for now
211  result->is_null = (result->length == 0);
212  }
213 }
int8_t * start_pos
Definition: ChunkIter.h:33
SQLTypeInfo type_info
Definition: ChunkIter.h:30
static DEVICE void decompress(const SQLTypeInfo &ti, int8_t *compressed, VarlenDatum *result, Datum *datum)
Definition: ChunkIter.cpp:26
Datum datum
Definition: ChunkIter.h:38
bool is_null
Definition: sqltypes.h:73
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
int8_t * pointer
Definition: sqltypes.h:72
int32_t StringOffsetT
Definition: sqltypes.h:877
size_t num_elems
Definition: ChunkIter.h:37
int skip_size
Definition: ChunkIter.h:36
int8_t * second_buf
Definition: ChunkIter.h:31
HOST DEVICE bool is_null(const Datum &d) const
Definition: sqltypes.h:537
size_t length
Definition: sqltypes.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ChunkIter_get_nth() [2/2]

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

Definition at line 216 of file ChunkIter.cpp.

References SQLTypeInfoCore< TYPE_FACET_PACK >::is_null_fixlen_array(), ChunkIter::num_elems, ChunkIter::second_buf, ChunkIter::skip_size, ChunkIter::start_pos, and ChunkIter::type_info.

216  {
217  if (static_cast<size_t>(n) >= it->num_elems || n < 0) {
218  *is_end = true;
219  result->length = 0;
220  result->pointer = NULL;
221  result->is_null = true;
222  return;
223  }
224  *is_end = false;
225 
226  if (it->skip_size > 0) {
227  // for fixed-size
228  int8_t* current_pos = it->start_pos + n * it->skip_size;
229  result->length = static_cast<size_t>(it->skip_size);
230  result->pointer = current_pos;
231  result->is_null = it->type_info.is_null_fixlen_array(result->pointer, result->length);
232  } else {
233  int8_t* current_pos = it->start_pos + n * sizeof(ArrayOffsetT);
234  int8_t* next_pos = current_pos + sizeof(ArrayOffsetT);
235  ArrayOffsetT offset = *(ArrayOffsetT*)current_pos;
236  ArrayOffsetT next_offset = *(ArrayOffsetT*)next_pos;
237  if (next_offset < 0) { // Encoded NULL array
238  result->length = 0;
239  result->pointer = NULL;
240  result->is_null = true;
241  } else {
242  if (offset < 0) {
243  offset = -offset; // Previous array may have been NULL, remove negativity
244  }
245  result->length = static_cast<size_t>(next_offset - offset);
246  result->pointer = it->second_buf + offset;
247  result->is_null = false;
248  }
249  }
250 }
int8_t * start_pos
Definition: ChunkIter.h:33
SQLTypeInfo type_info
Definition: ChunkIter.h:30
size_t num_elems
Definition: ChunkIter.h:37
int skip_size
Definition: ChunkIter.h:36
int32_t ArrayOffsetT
Definition: sqltypes.h:878
int8_t * second_buf
Definition: ChunkIter.h:31
HOST DEVICE bool is_null_fixlen_array(const int8_t *val, int array_size) const
Definition: sqltypes.h:599
+ Here is the call graph for this function:

◆ ChunkIter_get_nth_varlen()

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

Definition at line 253 of file ChunkIter.cpp.

References ChunkIter::num_elems, ChunkIter::second_buf, and ChunkIter::start_pos.

256  {
257  *is_end = (static_cast<size_t>(n) >= it->num_elems || n < 0);
258 
259  if (!*is_end) {
260  int8_t* current_pos = it->start_pos + n * sizeof(ArrayOffsetT);
261  int8_t* next_pos = current_pos + sizeof(ArrayOffsetT);
262  ArrayOffsetT offset = *(ArrayOffsetT*)current_pos;
263  ArrayOffsetT next_offset = *(ArrayOffsetT*)next_pos;
264 
265  if (next_offset >= 0) {
266  // Previous array may have been NULL, remove offset negativity
267  if (offset < 0) {
268  offset = -offset;
269  }
270  result->length = static_cast<size_t>(next_offset - offset);
271  result->pointer = it->second_buf + offset;
272  result->is_null = false;
273  return;
274  }
275  }
276  // Encoded NULL array or out of bounds
277  result->length = 0;
278  result->pointer = NULL;
279  result->is_null = true;
280 }
int8_t * start_pos
Definition: ChunkIter.h:33
size_t num_elems
Definition: ChunkIter.h:37
int32_t ArrayOffsetT
Definition: sqltypes.h:878
int8_t * second_buf
Definition: ChunkIter.h:31

◆ ChunkIter_get_nth_varlen_notnull()

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

Definition at line 283 of file ChunkIter.cpp.

References ChunkIter::num_elems, ChunkIter::second_buf, and ChunkIter::start_pos.

286  {
287  *is_end = (static_cast<size_t>(n) >= it->num_elems || n < 0);
288 
289  int8_t* current_pos = it->start_pos + n * sizeof(ArrayOffsetT);
290  int8_t* next_pos = current_pos + sizeof(ArrayOffsetT);
291  ArrayOffsetT offset = *(ArrayOffsetT*)current_pos;
292  ArrayOffsetT next_offset = *(ArrayOffsetT*)next_pos;
293 
294  result->length = static_cast<size_t>(next_offset - offset);
295  result->pointer = it->second_buf + offset;
296  result->is_null = false;
297 }
int8_t * start_pos
Definition: ChunkIter.h:33
size_t num_elems
Definition: ChunkIter.h:37
int32_t ArrayOffsetT
Definition: sqltypes.h:878
int8_t * second_buf
Definition: ChunkIter.h:31

◆ ChunkIter_reset()

void ChunkIter_reset ( ChunkIter it)

Definition at line 143 of file ChunkIter.cpp.

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

143  {
144  it->current_pos = it->start_pos;
145 }
int8_t * start_pos
Definition: ChunkIter.h:33
int8_t * current_pos
Definition: ChunkIter.h:32

◆ decompress()

static DEVICE void decompress ( const SQLTypeInfo ti,
int8_t *  compressed,
VarlenDatum result,
Datum datum 
)
static

Definition at line 26 of file ChunkIter.cpp.

References Datum::bigintval, SQLTypeInfoCore< TYPE_FACET_PACK >::get_comp_param(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), Datum::intval, VarlenDatum::is_null, SQLTypeInfoCore< TYPE_FACET_PACK >::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(), ChunkIter_get_nth(), Analyzer::Expr::find_expr(), and BloscCompressor::getScratchSpaceSize().

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