joinin.h
Go to the documentation of this file.
1 // File: $Id$
2 // Author: John Wu <John.Wu at ACM.org>
3 // Copyright (c) 2008-2016 the Regents of the University of California
4 #ifndef IBIS_JOININ_H
5 #define IBIS_JOININ_H
6 
12 #include "join.h" // ibis::join
13 
14 namespace ibis {
15  class joinIN; // forward definition
16 } // namespace ibis
17 
19 class ibis::joinIN : public ibis::join {
20 public:
21  joinIN(const ibis::part& partr, const ibis::part& parts,
22  const char* colname, const char* condr, const char* conds);
23  virtual ~joinIN();
24 
25  virtual void estimate(uint64_t& nmin, uint64_t& nmax);
26  virtual int64_t evaluate();
27 
28  virtual ibis::join::result*
29  select(const std::vector<const char*>& colnames);
30 
31  class result;
32 
33 protected:
34  const ibis::part& R_;
35  const ibis::part& S_;
36  const ibis::column *colR_;
37  const ibis::column *colS_;
38  ibis::bitvector maskR_;
39  ibis::bitvector maskS_;
40  array_t<uint32_t> *orderR_;
41  array_t<uint32_t> *orderS_;
42  void *valR_;
43  void *valS_;
44  std::string desc_;
45  int64_t nrows;
46 
47  friend class ibis::joinIN::result;
48  static void freeBuffer(void* buffer, ibis::TYPE_T type);
49 
50 private:
51  joinIN(const joinIN&); // no copying
52  joinIN& operator=(const joinIN&); // no assignment
53 }; // class ibis::joinIN
54 
55 class ibis::joinIN::result : public ibis::join::result {
56 public:
57  virtual ~result();
58  result(const ibis::joinIN& jin, const std::vector<const char*>& colnames);
59 
60  virtual uint64_t nRows() const {return jin_.nrows;}
61  virtual uint32_t nColumns() const {return 0;}
62 
63  virtual std::vector<std::string> columnNames() const;
64  virtual ibis::table::typeArray columnTypes() const;
65  virtual void describe(std::ostream& out) const;
66 
67  virtual int fetch();
68  virtual int dump(std::ostream& out, const char* del=", ") const;
69 
70  virtual int getColumnAsByte(const char* cname, char&) const;
71  virtual int getColumnAsUByte(const char* cname, unsigned char&) const;
72  virtual int getColumnAsShort(const char* cname, int16_t&) const;
73  virtual int getColumnAsUShort(const char* cname, uint16_t&) const;
74  virtual int getColumnAsInt(const char* cname, int32_t&) const;
75  virtual int getColumnAsUInt(const char* cname, uint32_t&) const;
76  virtual int getColumnAsLong(const char* cname, int64_t&) const;
77  virtual int getColumnAsULong(const char* cname, uint64_t&) const;
78  virtual int getColumnAsFloat(const char* cname, float&) const;
79  virtual int getColumnAsDouble(const char* cname, double&) const;
80  virtual int getColumnAsString(const char* cname, std::string&) const;
81 
82  virtual int getColumnAsByte(uint32_t cnum, char&) const;
83  virtual int getColumnAsUByte(uint32_t cnum, unsigned char&) const;
84  virtual int getColumnAsShort(uint32_t cnum, int16_t&) const;
85  virtual int getColumnAsUShort(uint32_t cnum, uint16_t&) const;
86  virtual int getColumnAsInt(uint32_t cnum, int32_t&) const;
87  virtual int getColumnAsUInt(uint32_t cnum, uint32_t&) const;
88  virtual int getColumnAsLong(uint32_t cnum, int64_t&) const;
89  virtual int getColumnAsULong(uint32_t cnum, uint64_t&) const;
90  virtual int getColumnAsFloat(uint32_t cnum, float&) const;
91  virtual int getColumnAsDouble(uint32_t cnum, double&) const;
92  virtual int getColumnAsString(uint32_t cnum, std::string&) const;
93 
94 protected:
95  const ibis::joinIN& jin_;
96  const uint32_t endR_, endS_;
97  uint32_t currR_, currS_, blockR_, blockS_, startS_;
98  std::vector<const ibis::column*> colR_, colS_;
99  std::vector<ibis::TYPE_T> typeR_, typeS_;
100  std::vector<void*> valR_, valS_;
101  std::map<const char*, uint32_t, ibis::lessi> namesToPos;
102  std::vector<uint32_t> ipToPos;
103 
104  template <typename T>
105  int nextMatch(const array_t<T>& col1, const array_t<T>& col2);
106  int stringMatch(const std::vector<std::string>& col1,
107  const std::vector<std::string>& col2);
108  void dumpR(std::ostream& out, uint32_t ind) const;
109  void dumpS(std::ostream& out, uint32_t ind) const;
110 
111 private:
112  result(const result&); // no copying
113  result& operator=(const result&); // no assignment
114 }; // class ibis::joinIN::result
115 
116 inline int
117 ibis::joinIN::result::getColumnAsByte(uint32_t cnum, char& val) const {
118  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
119  return -1;
120 
121  int ierr = -2;
122  uint32_t pos = ipToPos[cnum];
123  if (pos < colR_.size()) {
124  if (typeR_[pos] == ibis::BYTE && colR_[pos] != 0) {
125  val = (*(static_cast<array_t<char>*>(valR_[pos])))
126  [(*jin_.orderR_)[currR_]];
127  ierr = 0;
128  }
129  }
130  else {
131  pos -= colR_.size();
132  if (typeS_[pos] == ibis::BYTE && colS_[pos] != 0) {
133  val = (*(static_cast<array_t<char>*>(valS_[pos])))
134  [(*jin_.orderS_)[currS_]];
135  ierr = 0;
136  }
137  }
138  return ierr;
139 } // ibis::joinIN::result::getColumnAsByte
140 
141 inline int
142 ibis::joinIN::result::getColumnAsUByte(uint32_t cnum, unsigned char& val) const {
143  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
144  return -1;
145 
146  int ierr = -2;
147  uint32_t pos = ipToPos[cnum];
148  if (pos < colR_.size()) {
149  if (typeR_[pos] == ibis::UBYTE && colR_[pos] != 0) {
150  val = (*(static_cast<array_t<unsigned char>*>(valR_[pos])))
151  [(*jin_.orderR_)[currR_]];
152  ierr = 0;
153  }
154  }
155  else {
156  pos -= colR_.size();
157  if (typeS_[pos] == ibis::UBYTE && colS_[pos] != 0) {
158  val = (*(static_cast<array_t<unsigned char>*>(valS_[pos])))
159  [(*jin_.orderS_)[currS_]];
160  ierr = 0;
161  }
162  }
163  return ierr;
164 } // ibis::joinIN::result::getColumnAsUByte
165 
166 inline int
167 ibis::joinIN::result::getColumnAsShort(uint32_t cnum, int16_t& val) const {
168  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
169  return -1;
170 
171  int ierr = -2;
172  uint32_t pos = ipToPos[cnum];
173  if (pos < colR_.size()) {
174  if (colR_[pos] != 0) {
175  switch (typeR_[pos]) {
176  default: break;
177  case ibis::BYTE:
178  val = (*(static_cast<array_t<char>*>(valR_[pos])))
179  [(*jin_.orderR_)[currR_]];
180  ierr = 0;
181  break;
182  case ibis::UBYTE:
183  val = (*(static_cast<array_t<unsigned char>*>(valR_[pos])))
184  [(*jin_.orderR_)[currR_]];
185  ierr = 0;
186  break;
187  case ibis::SHORT:
188  val = (*(static_cast<array_t<int16_t>*>(valR_[pos])))
189  [(*jin_.orderR_)[currR_]];
190  ierr = 0;
191  break;
192  }
193  }
194  }
195  else {
196  pos -= colR_.size();
197  if (colS_[pos] != 0) {
198  switch (typeS_[pos]) {
199  default: break;
200  case ibis::BYTE:
201  val = (*(static_cast<array_t<char>*>(valS_[pos])))
202  [(*jin_.orderS_)[currS_]];
203  ierr = 0;
204  break;
205  case ibis::UBYTE:
206  val = (*(static_cast<array_t<unsigned char>*>(valS_[pos])))
207  [(*jin_.orderS_)[currS_]];
208  ierr = 0;
209  break;
210  case ibis::SHORT:
211  val = (*(static_cast<array_t<int16_t>*>(valS_[pos])))
212  [(*jin_.orderS_)[currS_]];
213  ierr = 0;
214  break;
215  }
216  }
217  }
218  return ierr;
219 } // ibis::joinIN::result::getColumnAsShort
220 
221 inline int
222 ibis::joinIN::result::getColumnAsUShort(uint32_t cnum, uint16_t& val) const {
223  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
224  return -1;
225 
226  int ierr = -2;
227  uint32_t pos = ipToPos[cnum];
228  if (pos < colR_.size()) {
229  if (colR_[pos] != 0) {
230  switch (typeR_[pos]) {
231  default: break;
232  case ibis::BYTE:
233  val = (*(static_cast<array_t<char>*>(valR_[pos])))
234  [(*jin_.orderR_)[currR_]];
235  ierr = 0;
236  break;
237  case ibis::UBYTE:
238  val = (*(static_cast<array_t<unsigned char>*>(valR_[pos])))
239  [(*jin_.orderR_)[currR_]];
240  ierr = 0;
241  break;
242  case ibis::USHORT:
243  val = (*(static_cast<array_t<uint16_t>*>(valR_[pos])))
244  [(*jin_.orderR_)[currR_]];
245  ierr = 0;
246  break;
247  }
248  }
249  }
250  else {
251  pos -= colR_.size();
252  if (colS_[pos] != 0) {
253  switch (typeS_[pos]) {
254  default: break;
255  case ibis::BYTE:
256  val = (*(static_cast<array_t<char>*>(valS_[pos])))
257  [(*jin_.orderS_)[currS_]];
258  ierr = 0;
259  break;
260  case ibis::UBYTE:
261  val = (*(static_cast<array_t<unsigned char>*>(valS_[pos])))
262  [(*jin_.orderS_)[currS_]];
263  ierr = 0;
264  break;
265  case ibis::USHORT:
266  val = (*(static_cast<array_t<uint16_t>*>(valS_[pos])))
267  [(*jin_.orderS_)[currS_]];
268  ierr = 0;
269  break;
270  }
271  }
272  }
273  return ierr;
274 } // ibis::joinIN::result::getColumnAsUShort
275 
276 inline int
277 ibis::joinIN::result::getColumnAsInt(uint32_t cnum, int32_t& val) const {
278  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
279  return -1;
280 
281  int ierr = -2;
282  uint32_t pos = ipToPos[cnum];
283  if (pos < colR_.size()) {
284  if (colR_[pos] != 0) {
285  switch (typeR_[pos]) {
286  default: break;
287  case ibis::BYTE:
288  val = (*(static_cast<array_t<char>*>(valR_[pos])))
289  [(*jin_.orderR_)[currR_]];
290  ierr = 0;
291  break;
292  case ibis::UBYTE:
293  val = (*(static_cast<array_t<unsigned char>*>(valR_[pos])))
294  [(*jin_.orderR_)[currR_]];
295  ierr = 0;
296  break;
297  case ibis::SHORT:
298  val = (*(static_cast<array_t<int16_t>*>(valR_[pos])))
299  [(*jin_.orderR_)[currR_]];
300  ierr = 0;
301  break;
302  case ibis::USHORT:
303  val = (*(static_cast<array_t<uint16_t>*>(valR_[pos])))
304  [(*jin_.orderR_)[currR_]];
305  ierr = 0;
306  break;
307  case ibis::INT:
308  val = (*(static_cast<array_t<int32_t>*>(valR_[pos])))
309  [(*jin_.orderR_)[currR_]];
310  ierr = 0;
311  break;
312  }
313  }
314  }
315  else {
316  pos -= colR_.size();
317  if (colS_[pos] != 0) {
318  switch (typeS_[pos]) {
319  default: break;
320  case ibis::BYTE:
321  val = (*(static_cast<array_t<char>*>(valS_[pos])))
322  [(*jin_.orderS_)[currS_]];
323  ierr = 0;
324  break;
325  case ibis::UBYTE:
326  val = (*(static_cast<array_t<unsigned char>*>(valS_[pos])))
327  [(*jin_.orderS_)[currS_]];
328  ierr = 0;
329  break;
330  case ibis::SHORT:
331  val = (*(static_cast<array_t<int16_t>*>(valS_[pos])))
332  [(*jin_.orderS_)[currS_]];
333  ierr = 0;
334  break;
335  case ibis::USHORT:
336  val = (*(static_cast<array_t<uint16_t>*>(valS_[pos])))
337  [(*jin_.orderS_)[currS_]];
338  ierr = 0;
339  break;
340  case ibis::INT:
341  val = (*(static_cast<array_t<int32_t>*>(valS_[pos])))
342  [(*jin_.orderS_)[currS_]];
343  ierr = 0;
344  break;
345  }
346  }
347  }
348  return ierr;
349 } // ibis::joinIN::result::getColumnAsInt
350 
351 inline int
352 ibis::joinIN::result::getColumnAsUInt(uint32_t cnum, uint32_t& val) const {
353  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
354  return -1;
355 
356  int ierr = -2;
357  uint32_t pos = ipToPos[cnum];
358  if (pos < colR_.size()) {
359  if (colR_[pos] != 0) {
360  switch (typeR_[pos]) {
361  default: break;
362  case ibis::BYTE:
363  val = (*(static_cast<array_t<char>*>(valR_[pos])))
364  [(*jin_.orderR_)[currR_]];
365  ierr = 0;
366  break;
367  case ibis::UBYTE:
368  val = (*(static_cast<array_t<unsigned char>*>(valR_[pos])))
369  [(*jin_.orderR_)[currR_]];
370  ierr = 0;
371  break;
372  case ibis::SHORT:
373  val = (*(static_cast<array_t<int16_t>*>(valR_[pos])))
374  [(*jin_.orderR_)[currR_]];
375  ierr = 0;
376  break;
377  case ibis::USHORT:
378  val = (*(static_cast<array_t<uint16_t>*>(valR_[pos])))
379  [(*jin_.orderR_)[currR_]];
380  ierr = 0;
381  break;
382  case ibis::UINT:
383  val = (*(static_cast<array_t<uint32_t>*>(valR_[pos])))
384  [(*jin_.orderR_)[currR_]];
385  ierr = 0;
386  break;
387  }
388  }
389  }
390  else {
391  pos -= colR_.size();
392  if (colS_[pos] != 0) {
393  switch (typeS_[pos]) {
394  default: break;
395  case ibis::BYTE:
396  val = (*(static_cast<array_t<char>*>(valS_[pos])))
397  [(*jin_.orderS_)[currS_]];
398  ierr = 0;
399  break;
400  case ibis::UBYTE:
401  val = (*(static_cast<array_t<unsigned char>*>(valS_[pos])))
402  [(*jin_.orderS_)[currS_]];
403  ierr = 0;
404  break;
405  case ibis::SHORT:
406  val = (*(static_cast<array_t<int16_t>*>(valS_[pos])))
407  [(*jin_.orderS_)[currS_]];
408  ierr = 0;
409  break;
410  case ibis::USHORT:
411  val = (*(static_cast<array_t<uint16_t>*>(valS_[pos])))
412  [(*jin_.orderS_)[currS_]];
413  ierr = 0;
414  break;
415  case ibis::UINT:
416  val = (*(static_cast<array_t<uint32_t>*>(valS_[pos])))
417  [(*jin_.orderS_)[currS_]];
418  ierr = 0;
419  break;
420  }
421  }
422  }
423  return ierr;
424 } // ibis::joinIN::result::getColumnAsUInt
425 
426 inline int
427 ibis::joinIN::result::getColumnAsLong(uint32_t cnum, int64_t& val) const {
428  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
429  return -1;
430 
431  int ierr = -2;
432  uint32_t pos = ipToPos[cnum];
433  if (pos < colR_.size()) {
434  if (colR_[pos] != 0) {
435  switch (typeR_[pos]) {
436  default: break;
437  case ibis::BYTE:
438  val = (*(static_cast<array_t<char>*>(valR_[pos])))
439  [(*jin_.orderR_)[currR_]];
440  ierr = 0;
441  break;
442  case ibis::UBYTE:
443  val = (*(static_cast<array_t<unsigned char>*>(valR_[pos])))
444  [(*jin_.orderR_)[currR_]];
445  ierr = 0;
446  break;
447  case ibis::SHORT:
448  val = (*(static_cast<array_t<int16_t>*>(valR_[pos])))
449  [(*jin_.orderR_)[currR_]];
450  ierr = 0;
451  break;
452  case ibis::USHORT:
453  val = (*(static_cast<array_t<uint16_t>*>(valR_[pos])))
454  [(*jin_.orderR_)[currR_]];
455  ierr = 0;
456  break;
457  case ibis::INT:
458  val = (*(static_cast<array_t<int32_t>*>(valR_[pos])))
459  [(*jin_.orderR_)[currR_]];
460  ierr = 0;
461  break;
462  case ibis::UINT:
463  val = (*(static_cast<array_t<uint32_t>*>(valR_[pos])))
464  [(*jin_.orderR_)[currR_]];
465  ierr = 0;
466  break;
467  case ibis::LONG:
468  val = (*(static_cast<array_t<int64_t>*>(valR_[pos])))
469  [(*jin_.orderR_)[currR_]];
470  ierr = 0;
471  break;
472  }
473  }
474  }
475  else {
476  pos -= colR_.size();
477  if (colS_[pos] != 0) {
478  switch (typeS_[pos]) {
479  default: break;
480  case ibis::BYTE:
481  val = (*(static_cast<array_t<char>*>(valS_[pos])))
482  [(*jin_.orderS_)[currS_]];
483  ierr = 0;
484  break;
485  case ibis::UBYTE:
486  val = (*(static_cast<array_t<unsigned char>*>(valS_[pos])))
487  [(*jin_.orderS_)[currS_]];
488  ierr = 0;
489  break;
490  case ibis::SHORT:
491  val = (*(static_cast<array_t<int16_t>*>(valS_[pos])))
492  [(*jin_.orderS_)[currS_]];
493  ierr = 0;
494  break;
495  case ibis::USHORT:
496  val = (*(static_cast<array_t<uint16_t>*>(valS_[pos])))
497  [(*jin_.orderS_)[currS_]];
498  ierr = 0;
499  break;
500  case ibis::INT:
501  val = (*(static_cast<array_t<int32_t>*>(valS_[pos])))
502  [(*jin_.orderS_)[currS_]];
503  ierr = 0;
504  break;
505  case ibis::UINT:
506  val = (*(static_cast<array_t<uint32_t>*>(valS_[pos])))
507  [(*jin_.orderS_)[currS_]];
508  ierr = 0;
509  break;
510  case ibis::LONG:
511  val = (*(static_cast<array_t<int64_t>*>(valS_[pos])))
512  [(*jin_.orderS_)[currS_]];
513  ierr = 0;
514  break;
515  }
516  }
517  }
518  return ierr;
519 } // ibis::joinIN::result::getColumnAsLong
520 
521 inline int
522 ibis::joinIN::result::getColumnAsULong(uint32_t cnum, uint64_t& val) const {
523  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
524  return -1;
525 
526  int ierr = -2;
527  uint32_t pos = ipToPos[cnum];
528  if (pos < colR_.size()) {
529  if (colR_[pos] != 0) {
530  switch (typeR_[pos]) {
531  default: break;
532  case ibis::BYTE:
533  val = (*(static_cast<array_t<char>*>(valR_[pos])))
534  [(*jin_.orderR_)[currR_]];
535  ierr = 0;
536  break;
537  case ibis::UBYTE:
538  val = (*(static_cast<array_t<unsigned char>*>(valR_[pos])))
539  [(*jin_.orderR_)[currR_]];
540  ierr = 0;
541  break;
542  case ibis::SHORT:
543  val = (*(static_cast<array_t<int16_t>*>(valR_[pos])))
544  [(*jin_.orderR_)[currR_]];
545  ierr = 0;
546  break;
547  case ibis::USHORT:
548  val = (*(static_cast<array_t<uint16_t>*>(valR_[pos])))
549  [(*jin_.orderR_)[currR_]];
550  ierr = 0;
551  break;
552  case ibis::INT:
553  val = (*(static_cast<array_t<int32_t>*>(valR_[pos])))
554  [(*jin_.orderR_)[currR_]];
555  ierr = 0;
556  break;
557  case ibis::UINT:
558  val = (*(static_cast<array_t<uint32_t>*>(valR_[pos])))
559  [(*jin_.orderR_)[currR_]];
560  ierr = 0;
561  break;
562  case ibis::ULONG:
563  val = (*(static_cast<array_t<uint64_t>*>(valR_[pos])))
564  [(*jin_.orderR_)[currR_]];
565  ierr = 0;
566  break;
567  }
568  }
569  }
570  else {
571  pos -= colR_.size();
572  if (colS_[pos] != 0) {
573  switch (typeS_[pos]) {
574  default: break;
575  case ibis::BYTE:
576  val = (*(static_cast<array_t<char>*>(valS_[pos])))
577  [(*jin_.orderS_)[currS_]];
578  ierr = 0;
579  break;
580  case ibis::UBYTE:
581  val = (*(static_cast<array_t<unsigned char>*>(valS_[pos])))
582  [(*jin_.orderS_)[currS_]];
583  ierr = 0;
584  break;
585  case ibis::SHORT:
586  val = (*(static_cast<array_t<int16_t>*>(valS_[pos])))
587  [(*jin_.orderS_)[currS_]];
588  ierr = 0;
589  break;
590  case ibis::USHORT:
591  val = (*(static_cast<array_t<uint16_t>*>(valS_[pos])))
592  [(*jin_.orderS_)[currS_]];
593  ierr = 0;
594  break;
595  case ibis::INT:
596  val = (*(static_cast<array_t<int32_t>*>(valS_[pos])))
597  [(*jin_.orderS_)[currS_]];
598  ierr = 0;
599  break;
600  case ibis::UINT:
601  val = (*(static_cast<array_t<uint32_t>*>(valS_[pos])))
602  [(*jin_.orderS_)[currS_]];
603  ierr = 0;
604  break;
605  case ibis::ULONG:
606  val = (*(static_cast<array_t<uint64_t>*>(valS_[pos])))
607  [(*jin_.orderS_)[currS_]];
608  ierr = 0;
609  break;
610  }
611  }
612  }
613  return ierr;
614 } // ibis::joinIN::result::getColumnAsULong
615 
616 inline int
617 ibis::joinIN::result::getColumnAsFloat(uint32_t cnum, float& val) const {
618  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
619  return -1;
620 
621  int ierr = -2;
622  uint32_t pos = ipToPos[cnum];
623  if (pos < colR_.size()) {
624  if (colR_[pos] != 0) {
625  switch (typeR_[pos]) {
626  default: break;
627  case ibis::BYTE:
628  val = (*(static_cast<array_t<char>*>(valR_[pos])))
629  [(*jin_.orderR_)[currR_]];
630  ierr = 0;
631  break;
632  case ibis::UBYTE:
633  val = (*(static_cast<array_t<unsigned char>*>(valR_[pos])))
634  [(*jin_.orderR_)[currR_]];
635  ierr = 0;
636  break;
637  case ibis::SHORT:
638  val = (*(static_cast<array_t<int16_t>*>(valR_[pos])))
639  [(*jin_.orderR_)[currR_]];
640  ierr = 0;
641  break;
642  case ibis::USHORT:
643  val = (*(static_cast<array_t<uint16_t>*>(valR_[pos])))
644  [(*jin_.orderR_)[currR_]];
645  ierr = 0;
646  break;
647  case ibis::FLOAT:
648  val = (*(static_cast<array_t<float>*>(valR_[pos])))
649  [(*jin_.orderR_)[currR_]];
650  ierr = 0;
651  break;
652  }
653  }
654  }
655  else {
656  pos -= colR_.size();
657  if (colS_[pos] != 0) {
658  switch (typeS_[pos]) {
659  default: break;
660  case ibis::BYTE:
661  val = (*(static_cast<array_t<char>*>(valS_[pos])))
662  [(*jin_.orderS_)[currS_]];
663  ierr = 0;
664  break;
665  case ibis::UBYTE:
666  val = (*(static_cast<array_t<unsigned char>*>(valS_[pos])))
667  [(*jin_.orderS_)[currS_]];
668  ierr = 0;
669  break;
670  case ibis::SHORT:
671  val = (*(static_cast<array_t<int16_t>*>(valS_[pos])))
672  [(*jin_.orderS_)[currS_]];
673  ierr = 0;
674  break;
675  case ibis::USHORT:
676  val = (*(static_cast<array_t<uint16_t>*>(valS_[pos])))
677  [(*jin_.orderS_)[currS_]];
678  ierr = 0;
679  break;
680  case ibis::FLOAT:
681  val = (*(static_cast<array_t<float>*>(valS_[pos])))
682  [(*jin_.orderS_)[currS_]];
683  ierr = 0;
684  break;
685  }
686  }
687  }
688  return ierr;
689 } // ibis::joinIN::result::getColumnAsFloat
690 
691 inline int
692 ibis::joinIN::result::getColumnAsDouble(uint32_t cnum, double& val) const {
693  if (currR_ >= blockR_ || currS_ >= blockS_ || cnum >= ipToPos.size())
694  return -1;
695 
696  int ierr = -2;
697  uint32_t pos = ipToPos[cnum];
698  if (pos < colR_.size()) {
699  if (colR_[pos] != 0) {
700  switch (typeR_[pos]) {
701  default: break;
702  case ibis::BYTE:
703  val = (*(static_cast<array_t<char>*>(valR_[pos])))
704  [(*jin_.orderR_)[currR_]];
705  ierr = 0;
706  break;
707  case ibis::UBYTE:
708  val = (*(static_cast<array_t<unsigned char>*>(valR_[pos])))
709  [(*jin_.orderR_)[currR_]];
710  ierr = 0;
711  break;
712  case ibis::SHORT:
713  val = (*(static_cast<array_t<int16_t>*>(valR_[pos])))
714  [(*jin_.orderR_)[currR_]];
715  ierr = 0;
716  break;
717  case ibis::USHORT:
718  val = (*(static_cast<array_t<uint16_t>*>(valR_[pos])))
719  [(*jin_.orderR_)[currR_]];
720  ierr = 0;
721  break;
722  case ibis::INT:
723  val = (*(static_cast<array_t<int32_t>*>(valR_[pos])))
724  [(*jin_.orderR_)[currR_]];
725  ierr = 0;
726  break;
727  case ibis::UINT:
728  val = (*(static_cast<array_t<uint32_t>*>(valR_[pos])))
729  [(*jin_.orderR_)[currR_]];
730  ierr = 0;
731  break;
732  case ibis::FLOAT:
733  val = (*(static_cast<array_t<float>*>(valR_[pos])))
734  [(*jin_.orderR_)[currR_]];
735  ierr = 0;
736  break;
737  case ibis::DOUBLE:
738  val = (*(static_cast<array_t<double>*>(valR_[pos])))
739  [(*jin_.orderR_)[currR_]];
740  ierr = 0;
741  break;
742  }
743  }
744  }
745  else {
746  pos -= colR_.size();
747  if (colS_[pos] != 0) {
748  switch (typeS_[pos]) {
749  default: break;
750  case ibis::BYTE:
751  val = (*(static_cast<array_t<char>*>(valS_[pos])))
752  [(*jin_.orderS_)[currS_]];
753  ierr = 0;
754  break;
755  case ibis::UBYTE:
756  val = (*(static_cast<array_t<unsigned char>*>(valS_[pos])))
757  [(*jin_.orderS_)[currS_]];
758  ierr = 0;
759  break;
760  case ibis::SHORT:
761  val = (*(static_cast<array_t<int16_t>*>(valS_[pos])))
762  [(*jin_.orderS_)[currS_]];
763  ierr = 0;
764  break;
765  case ibis::USHORT:
766  val = (*(static_cast<array_t<uint16_t>*>(valS_[pos])))
767  [(*jin_.orderS_)[currS_]];
768  ierr = 0;
769  break;
770  case ibis::INT:
771  val = (*(static_cast<array_t<int32_t>*>(valS_[pos])))
772  [(*jin_.orderS_)[currS_]];
773  ierr = 0;
774  break;
775  case ibis::UINT:
776  val = (*(static_cast<array_t<uint32_t>*>(valS_[pos])))
777  [(*jin_.orderS_)[currS_]];
778  ierr = 0;
779  break;
780  case ibis::FLOAT:
781  val = (*(static_cast<array_t<float>*>(valS_[pos])))
782  [(*jin_.orderS_)[currS_]];
783  ierr = 0;
784  break;
785  case ibis::DOUBLE:
786  val = (*(static_cast<array_t<double>*>(valS_[pos])))
787  [(*jin_.orderS_)[currS_]];
788  ierr = 0;
789  break;
790  }
791  }
792  }
793  return ierr;
794 } // ibis::joinIN::result::getColumnAsDouble
795 
796 inline void
797 ibis::joinIN::result::dumpR(std::ostream& out, uint32_t ind) const {
798  if (colR_[ind] == 0) return;
799  switch (typeR_[ind]) {
800  default: break;
801  case ibis::BYTE:
802  out << (int)(*(static_cast<const array_t<char>*>(valR_[ind])))
803  [(*jin_.orderR_)[currR_]];
804  break;
805  case ibis::UBYTE:
806  out << (int)(*(static_cast<const array_t<unsigned char>*>(valR_[ind])))
807  [(*jin_.orderR_)[currR_]];
808  break;
809  case ibis::SHORT:
810  out << (*(static_cast<const array_t<int16_t>*>(valR_[ind])))
811  [(*jin_.orderR_)[currR_]];
812  break;
813  case ibis::USHORT:
814  out << (*(static_cast<const array_t<uint16_t>*>(valR_[ind])))
815  [(*jin_.orderR_)[currR_]];
816  break;
817  case ibis::INT:
818  out << (*(static_cast<const array_t<int32_t>*>(valR_[ind])))
819  [(*jin_.orderR_)[currR_]];
820  break;
821  case ibis::UINT:
822  out << (*(static_cast<const array_t<uint32_t>*>(valR_[ind])))
823  [(*jin_.orderR_)[currR_]];
824  break;
825  case ibis::LONG:
826  out << (*(static_cast<const array_t<int64_t>*>(valR_[ind])))
827  [(*jin_.orderR_)[currR_]];
828  break;
829  case ibis::ULONG:
830  out << (*(static_cast<const array_t<uint64_t>*>(valR_[ind])))
831  [(*jin_.orderR_)[currR_]];
832  break;
833  case ibis::FLOAT:
834  out << (*(static_cast<const array_t<float>*>(valR_[ind])))
835  [(*jin_.orderR_)[currR_]];
836  break;
837  case ibis::DOUBLE:
838  out << (*(static_cast<const array_t<double>*>(valR_[ind])))
839  [(*jin_.orderR_)[currR_]];
840  break;
841  case ibis::TEXT:
842  case ibis::CATEGORY:
843  out << (*(static_cast<const std::vector<std::string>*>(valR_[ind])))
844  [(*jin_.orderR_)[currR_]];
845  break;
846  }
847 } // ibis::joinIN::result::dumpR
848 
849 inline void
850 ibis::joinIN::result::dumpS(std::ostream& out, uint32_t ind) const {
851  if (colS_[ind] == 0) return;
852  switch (typeS_[ind]) {
853  default: break;
854  case ibis::BYTE:
855  out << (int)(*(static_cast<const array_t<char>*>(valS_[ind])))
856  [(*jin_.orderS_)[currS_]];
857  break;
858  case ibis::UBYTE:
859  out << (int)(*(static_cast<const array_t<unsigned char>*>(valS_[ind])))
860  [(*jin_.orderS_)[currS_]];
861  break;
862  case ibis::SHORT:
863  out << (*(static_cast<const array_t<int16_t>*>(valS_[ind])))
864  [(*jin_.orderS_)[currS_]];
865  break;
866  case ibis::USHORT:
867  out << (*(static_cast<const array_t<uint16_t>*>(valS_[ind])))
868  [(*jin_.orderS_)[currS_]];
869  break;
870  case ibis::INT:
871  out << (*(static_cast<const array_t<int32_t>*>(valS_[ind])))
872  [(*jin_.orderS_)[currS_]];
873  break;
874  case ibis::UINT:
875  out << (*(static_cast<const array_t<uint32_t>*>(valS_[ind])))
876  [(*jin_.orderS_)[currS_]];
877  break;
878  case ibis::LONG:
879  out << (*(static_cast<const array_t<int64_t>*>(valS_[ind])))
880  [(*jin_.orderS_)[currS_]];
881  break;
882  case ibis::ULONG:
883  out << (*(static_cast<const array_t<uint64_t>*>(valS_[ind])))
884  [(*jin_.orderS_)[currS_]];
885  break;
886  case ibis::FLOAT:
887  out << (*(static_cast<const array_t<float>*>(valS_[ind])))
888  [(*jin_.orderS_)[currS_]];
889  break;
890  case ibis::DOUBLE:
891  out << (*(static_cast<const array_t<double>*>(valS_[ind])))
892  [(*jin_.orderS_)[currS_]];
893  break;
894  case ibis::TEXT:
895  case ibis::CATEGORY:
896  out << (*(static_cast<const std::vector<std::string>*>(valS_[ind])))
897  [(*jin_.orderS_)[currS_]];
898  break;
899  }
900 } // ibis::joinIN::result::dumpS
901 #endif
An abstract join interface.
Definition: join.h:31
!< One bit per record, represented by a bit vector.
Definition: table.h:44
!< Four-byte signed integers, internally int32_t.
Definition: table.h:35
The current implementation of FastBit is code named IBIS; most data structures and functions are in t...
Definition: bord.h:16
!< Eight-byte unsigned integers, internally uint64_t.
Definition: table.h:38
The class to represent a column of a data partition.
Definition: column.h:65
FastBit Join Interface.
virtual void estimate(uint64_t &nmin, uint64_t &nmax)
Provide an estimate of the number of results.
Definition: joinin.cpp:123
!< Two-byte unsigned integers, internally uint16_t.
Definition: table.h:34
Arbitrary null-terminated strings.
Definition: table.h:51
!< Two-byte signed integers, internally int16_t.
Definition: table.h:33
!< Eight-byte signed integers, internally int64_t.
Definition: table.h:37
FastBit In-memory Natual Join.
Definition: joinin.h:19
!< One-byte unsigned integers, internally unsigned char.
Definition: table.h:32
virtual ibis::join::result * select(const std::vector< const char * > &colnames)
Produce a projection of the joined table.
Definition: joinin.cpp:403
!< Four-byte IEEE floating-point numbers, internally float.
Definition: table.h:39
The class ibis::part represents a partition of a relational table.
Definition: part.h:27
TYPE_T
Supported data types.
Definition: table.h:25
Definition: joinin.h:55
A data structure to represent a sequence of bits.
Definition: bitvector.h:62
virtual int64_t evaluate()
Compute the number of results.
Definition: joinin.cpp:130
!< One-byte signed integers, internally char.
Definition: table.h:31
!< Four-byte unsigned integers, internally uint32_t.
Definition: table.h:36

Make It A Bit Faster
Contact us
Disclaimers
FastBit source code
FastBit mailing list archive