-
Notifications
You must be signed in to change notification settings - Fork 34
/
SpecialConstant.h
2719 lines (2633 loc) · 128 KB
/
SpecialConstant.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
133
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* SpecialConstant.h
*
* Created on: Mar 22, 2021
* Author: dzhou
*/
#ifndef SPECIALCONSTANT_H_
#define SPECIALCONSTANT_H_
#include "CoreConcept.h"
#include "Util.h"
class AnyVector:public Vector{
public:
AnyVector(int size, bool isTableColumn = false, DATA_TYPE dt = DT_VOID, int decimalExtra = -1);
AnyVector(const deque<ConstantSP>& data, bool containNull, bool isTableColumn = false, DATA_TYPE dt = DT_VOID,
int decimalExtra = -1);
AnyVector(const vector<ConstantSP>& data, bool containNull, bool isTableColumn = false, DATA_TYPE dt = DT_VOID,
int decimalExtra = -1);
virtual ~AnyVector(){}
virtual bool containNotMarshallableObject() const;
virtual bool isLargeConstant() const {return !isStatic() && !containNotMarshallableObject();}
virtual bool getNullFlag() const {return containNull_;}
virtual void setNullFlag(bool containNull){containNull_=containNull;}
virtual INDEX getCapacity() const {return 0;}
virtual bool isFastMode() const {return false;}
virtual short getUnitLength() const {return 0;}
virtual void clear();
virtual bool sizeable() const {return true;}
virtual DATA_TYPE getRawType() const { return DT_ANY;}
virtual string getString(INDEX index) const {return data_[index]->getString();}
virtual const DolphinString& getStringRef(INDEX index) const { throw RuntimeException("getStringRef method not supported for AnyVector");}
virtual bool set(INDEX index, const ConstantSP& value, INDEX valueIndex);
virtual bool set(INDEX index, const ConstantSP& value);
virtual bool set(const ConstantSP& index, const ConstantSP& value);
virtual bool set(Heap* heap, const ConstantSP& index, const ConstantSP& value, int dim);
virtual bool setItem(INDEX index, const ConstantSP& value);
virtual bool modifyMember(Heap* heap, const FunctionDefSP& func, const ConstantSP& index, const ConstantSP& parameters, int dim);
virtual bool assign(const ConstantSP& value);
virtual ConstantSP get(INDEX index) const {return data_[index];}
virtual ConstantSP get(const ConstantSP& index) const;
virtual ConstantSP get(INDEX offset, const ConstantSP& index) const override;
virtual bool hasNull(){return hasNull(0, data_.size());}
virtual bool hasNull(INDEX start, INDEX length);
virtual bool isNull(INDEX index) const;
virtual bool isNull() const {return false;}
virtual void setNull(INDEX index);
virtual void setNull(){}
virtual void fill(INDEX start, INDEX length, const ConstantSP& value, INDEX valueOffset = 0) override;
virtual void nullFill(const ConstantSP& val);
virtual bool isNull(INDEX start, int len, char* buf) const override;
virtual bool isNull(INDEX* indices, int len, char* buf) const override;
virtual bool isValid(INDEX start, int len, char* buf) const override;
virtual bool isValid(INDEX* indices, int len, char* buf) const override;
virtual ConstantSP getSubVector(INDEX start, INDEX length) const;
virtual ConstantSP getInstance(INDEX size) const {return ConstantSP(new AnyVector(size, isTableColumn_, dt_, decimalExtra_));}
virtual ConstantSP getValue() const;
virtual ConstantSP getValue(INDEX capacity) const {return ConstantSP(new AnyVector(data_, containNull_, isTableColumn_, dt_, decimalExtra_));}
bool append(const ConstantSP& value, bool wholistic);
virtual bool append(const ConstantSP& value);
virtual bool append(const ConstantSP& value, INDEX appendSize);
virtual bool remove(INDEX count);
virtual bool remove(const ConstantSP& index) override;
virtual void resize(INDEX size) override;
virtual void prev(INDEX steps);
virtual void next(INDEX steps);
virtual void contain(const ConstantSP& targetSP, const ConstantSP& resultSP) const;
virtual void find(INDEX start, INDEX length, const ConstantSP& targetSP, const ConstantSP& resultSP){
throw RuntimeException("find method not supported for AnyVector");
}
virtual char getBool() const;
virtual char getChar() const;
virtual short getShort() const;
virtual int getInt() const;
virtual long long getLong() const;
virtual INDEX getIndex() const;
virtual float getFloat() const;
virtual double getDouble() const;
virtual char getBool(INDEX index) const {return get(index)->getBool();}
virtual char getChar(INDEX index) const { return get(index)->getChar();}
virtual short getShort(INDEX index) const { return get(index)->getShort();}
virtual int getInt(INDEX index) const {return get(index)->getInt();}
virtual long long getLong(INDEX index) const {return get(index)->getLong();}
virtual INDEX getIndex(INDEX index) const {return get(index)->getIndex();}
virtual float getFloat(INDEX index) const {return get(index)->getFloat();}
virtual double getDouble(INDEX index) const {return get(index)->getDouble();}
virtual IO_ERR serialize(Heap* pHeap, const ByteArrayCodeBufferSP& buffer) const;
virtual int serialize(char* buf, int bufSize, INDEX indexStart, int offset, int& numElement, int& partial) const {
throw RuntimeException("serialize method not supported for AnyVector");
}
virtual bool getBool(INDEX start, int len, char* buf) const;
virtual bool getChar(INDEX start, int len,char* buf) const;
virtual bool getShort(INDEX start, int len, short* buf) const;
virtual bool getInt(INDEX start, int len, int* buf) const;
virtual bool getLong(INDEX start, int len, long long* buf) const;
virtual bool getIndex(INDEX start, int len, INDEX* buf) const;
virtual bool getFloat(INDEX start, int len, float* buf) const;
virtual bool getDouble(INDEX start, int len, double* buf) const;
virtual const char* getBoolConst(INDEX start, int len, char* buf) const;
virtual const char* getCharConst(INDEX start, int len,char* buf) const;
virtual const short* getShortConst(INDEX start, int len, short* buf) const;
virtual const int* getIntConst(INDEX start, int len, int* buf) const;
virtual const long long* getLongConst(INDEX start, int len, long long* buf) const;
virtual const INDEX* getIndexConst(INDEX start, int len, INDEX* buf) const;
virtual const float* getFloatConst(INDEX start, int len, float* buf) const;
virtual const double* getDoubleConst(INDEX start, int len, double* buf) const;
virtual bool getSymbol(INDEX start, int len, int* buf, SymbolBase* symBase, bool insertIfNotThere) const {
throw RuntimeException("getSymbol method not supported for AnyVector");
}
virtual const int* getSymbolConst(INDEX start, int len, int* buf, SymbolBase* symBase, bool insertIfNotThere) const {
throw RuntimeException("getSymbolConst method not supported for AnyVector");
}
virtual bool getString(INDEX start, int len, DolphinString** buf) const {
throw RuntimeException("getString method not supported for AnyVector");
}
virtual bool getString(INDEX start, int len, char** buf) const {
throw RuntimeException("getString method not supported for AnyVector");
}
virtual DolphinString** getStringConst(INDEX start, int len, DolphinString** buf) const {
throw RuntimeException("getStringConst method not supported for AnyVector");
}
virtual char** getStringConst(INDEX start, int len, char** buf) const {
throw RuntimeException("getStringConst method not supported for AnyVector");
}
public: /// getDecimal{32,64,128}
virtual int getDecimal32(int scale) const override;
virtual long long getDecimal64(int scale) const override;
virtual int128 getDecimal128(int scale) const override;
virtual int getDecimal32(INDEX index, int scale) const override;
virtual long long getDecimal64(INDEX index, int scale) const override;
virtual int128 getDecimal128(INDEX index, int scale) const override;
virtual bool getDecimal32(INDEX start, int len, int scale, int *buf) const override;
virtual bool getDecimal64(INDEX start, int len, int scale, long long *buf) const override;
virtual bool getDecimal128(INDEX start, int len, int scale, int128 *buf) const override;
virtual const int* getDecimal32Const(INDEX start, int len, int scale, int *buf) const override;
virtual const long long* getDecimal64Const(INDEX start, int len, int scale, long long *buf) const override;
virtual const int128* getDecimal128Const(INDEX start, int len, int scale,
int128 *buf) const override;
public:
virtual INDEX size() const {return data_.size();}
virtual long long count() const{
return count(0, data_.size());
}
virtual long long count(INDEX start, INDEX length) const;
/**
* @param rightMost If there are multiple maximum/minimum values, choose the last one if `rightMost` is true.
*/
virtual INDEX imax(bool rightMost = false) const override {throw RuntimeException("imax method not supported for AnyVector");}
virtual INDEX imin(bool rightMost = false) const override {throw RuntimeException("imin method not supported for AnyVector");}
virtual INDEX imax(INDEX start, INDEX length, bool rightMost = false) const override {throw RuntimeException("imax method not supported for AnyVector");}
virtual INDEX imin(INDEX start, INDEX length, bool rightMost = false) const override {throw RuntimeException("imin method not supported for AnyVector");}
virtual ConstantSP avg() const {return avg(0, data_.size());}
virtual ConstantSP avg(INDEX start, INDEX length) const;
virtual void avg(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const { out->set(outputStart, avg(start, length)); }
virtual ConstantSP sum() const {return sum(0, data_.size());}
virtual ConstantSP sum(INDEX start, INDEX length) const;
virtual void sum(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const { out->set(outputStart, sum(start, length)); }
virtual ConstantSP sum2() const {return sum2(0, data_.size());}
virtual ConstantSP sum2(INDEX start, INDEX length) const;
virtual void sum2(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const { out->set(outputStart, sum2(start, length)); }
virtual ConstantSP prd() const {return prd(0, data_.size());}
virtual ConstantSP prd(INDEX start, INDEX length) const;
virtual void prd(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const { out->set(outputStart, prd(start, length)); }
virtual ConstantSP var() const {return var(0, data_.size());}
virtual ConstantSP var(INDEX start, INDEX length) const;
virtual void var(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const { out->set(outputStart, var(start, length)); }
virtual ConstantSP std() const {return std(0, data_.size());}
virtual ConstantSP std(INDEX start, INDEX length) const;
virtual void std(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const { out->set(outputStart, std(start, length)); }
virtual ConstantSP median() const {return median(0, data_.size());}
virtual ConstantSP median(INDEX start, INDEX length) const;
virtual void median(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart=0) const { out->set(outputStart, median(start, length)); }
virtual ConstantSP firstNot(const ConstantSP& exclude) const { return firstNot(0, data_.size(), exclude); }
virtual ConstantSP firstNot(INDEX start, INDEX length, const ConstantSP& exclude) const;
virtual void firstNot(INDEX start, INDEX length, const ConstantSP& exclude, const ConstantSP& out, INDEX outputStart = 0) const {
out->set(outputStart, firstNot(start, length, exclude));
}
virtual ConstantSP lastNot(const ConstantSP& exclude) const { return lastNot(0, data_.size(), exclude); }
virtual ConstantSP lastNot(INDEX start, INDEX length, const ConstantSP& exclude) const;
virtual void lastNot(INDEX start, INDEX length, const ConstantSP& exclude, const ConstantSP& out, INDEX outputStart = 0) const {
out->set(outputStart, lastNot(start, length, exclude));
}
virtual ConstantSP searchK(INDEX k) const {throw RuntimeException("searchK method not supported for AnyVector");}
virtual ConstantSP searchK(INDEX start, INDEX length, INDEX k) const {return searchK(k);}
virtual void searchK(INDEX start, INDEX length, INDEX k, const ConstantSP& out, INDEX outputStart=0) const {
throw RuntimeException("searchK method not supported for AnyVector");
}
virtual ConstantSP mode() const {throw RuntimeException("mode method not supported for AnyVector");}
virtual ConstantSP mode(INDEX start, INDEX length) const { return mode();}
virtual void mode(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart=0) const {
throw RuntimeException("mode method not supported for AnyVector");
}
virtual ConstantSP min() const { return min(0, data_.size()); }
virtual ConstantSP min(INDEX start, INDEX length) const;
virtual void min(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart=0) const { out->set(outputStart, min(start, length)); }
virtual ConstantSP max() const { return max(0, data_.size()); }
virtual ConstantSP max(INDEX start, INDEX length) const;
virtual void max(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart=0) const { out->set(outputStart, max(start, length)); }
virtual void neg(){throw RuntimeException("neg method not supported for AnyVector");}
virtual void reverse(){std::reverse(data_.begin(),data_.end());}
virtual void reverse(INDEX start, INDEX length){
std::reverse(data_.begin()+start,data_.begin()+ start + length);
}
virtual void replace(const ConstantSP& oldVal, const ConstantSP& newVal);
virtual void shuffle();
virtual bool findDuplicatedElements(Vector* indices, INDEX start, INDEX length, vector<pair<INDEX,INDEX> >& duplicates){return false;}
virtual bool findDuplicatedElements(INDEX start, INDEX length, vector<pair<INDEX,INDEX> >& duplicates){return false;}
virtual bool findUniqueElements(INDEX start, INDEX length, vector<pair<INDEX,INDEX> >& uniques){return false;}
virtual bool findRange(INDEX* ascIndices,const ConstantSP& target,INDEX* targetIndices,vector<pair<INDEX,INDEX> >& ranges){return false;}
virtual bool findRange(const ConstantSP& target,INDEX* targetIndices,vector<pair<INDEX,INDEX> >& ranges){return false;}
virtual INDEX lowerBound(INDEX start, const ConstantSP& target){
throw RuntimeException("lowerBound method not supported for AnyVector");
}
virtual bool rank(bool sorted, INDEX* indices, INDEX* ranking){return false;}
virtual bool sortSelectedIndices(Vector* indices, INDEX start, INDEX length, bool asc, char nullsOrder){ return false;}
virtual bool isSorted(INDEX start, INDEX length, bool asc, bool strict, char nullsOrder) const { return false;}
virtual bool sort(bool asc, char nullsOrder){return false;}
virtual bool sort(bool asc, Vector* indices, char nullsOrder){ return false;}
virtual INDEX sortTop(bool asc, Vector* indices, INDEX top, char nullsOrder){ return -1;}
virtual long long getAllocatedMemory();
virtual int getExtraParamForType() const override { return dt_; }
ConstantSP flatten(INDEX rowStart, INDEX count) const override;
ConstantSP rowFirst(INDEX rowStart, INDEX count) const override;
ConstantSP rowLast(INDEX rowStart, INDEX count) const override;
ConstantSP rowFirstNot(INDEX rowStart, INDEX count, const ConstantSP& exclude) const override;
ConstantSP rowLastNot(INDEX rowStart, INDEX count, const ConstantSP& exclude) const override;
ConstantSP rowSum(INDEX rowStart, INDEX count) const override;
ConstantSP rowSum2(INDEX rowStart, INDEX count) const override;
ConstantSP rowCount(INDEX rowStart, INDEX count) const override;
ConstantSP rowSize(INDEX rowStart, INDEX count) const override;
ConstantSP rowAvg(INDEX rowStart, INDEX count) const override;
ConstantSP rowStd(INDEX rowStart, INDEX count) const override;
ConstantSP rowStdp(INDEX rowStart, INDEX count) const override;
ConstantSP rowVar(INDEX rowStart, INDEX count) const override;
ConstantSP rowVarp(INDEX rowStart, INDEX count) const override;
ConstantSP rowMin(INDEX rowStart, INDEX count) const override;
ConstantSP rowMax(INDEX rowStart, INDEX count) const override;
ConstantSP rowProd(INDEX rowStart, INDEX count) const override;
ConstantSP rowAnd(INDEX rowStart, INDEX count) const override;
ConstantSP rowOr(INDEX rowStart, INDEX count) const override;
ConstantSP rowXor(INDEX rowStart, INDEX count) const override;
ConstantSP rowKurtosis(INDEX rowStart, INDEX count, bool biased) const override;
ConstantSP rowSkew(INDEX rowStart, INDEX count, bool biased) const override;
void collectUserDefinedFunctions(unordered_map<string,FunctionDef*>& functionDefs) const;
bool isHomogeneousScalar(DATA_TYPE& type) const;
bool isHomogeneousScalarOrArray(DATA_TYPE& type, int& decimalExtra) const;
bool isConsistent() const;
bool isConsistentArray(int& len) const;
bool isTabular() const;
ConstantSP convertToRegularVector() const;
bool isDimension() const { return isDim_;}
void setDimension(bool option) { isDim_ = option;}
virtual bool isTableColumn() const override { return isTableColumn_;}
void setTableColumn(bool option) { isTableColumn_ = option;}
void setExtraParamForType(int extra){
DATA_TYPE type = (DATA_TYPE)extra;
if(type != DT_ANY)
dt_ = type;
}
void setDecimalExtra(int extra){ decimalExtra_ = extra; }
int getDecimalExtra() { return decimalExtra_; }
INDEX reserve(INDEX capacity);
inline long long getAllocatedMemory() const override {
long long memSize = 0;
for (size_t i = 0; i < data_.size(); ++i) {
memSize += data_[i]->getAllocatedMemory();
}
return memSize;
}
const ConstantSP& getConstant(INDEX index) const { return data_[index];}
void toVector(vector<ConstantSP>& v) const {
if(!v.empty())
v.clear();
v.insert(v.begin(), data_.begin(), data_.end());
}
virtual IO_ERR serialize(const ByteArrayCodeBufferSP& buffer) const {
if(!data_.empty())
throw RuntimeException("Code serialization is supported for a non-empty tuple.");
/*
* We want to keep the property isStatic after serialization.
* For this reason, we add 128 to the type if the object is static.
*/
DATA_TYPE type = getType();
if(isStatic())
type = (DATA_TYPE)((int)type + 128);
short flag = (getForm() <<8) + type;
buffer->write((char)CONSTOBJ);
buffer->write(flag);
buffer->write((int)rows());
return buffer->write((int)columns());
}
/**
* @brief cast a Vector to AnyVector
* @param v MUST BE a tuple Vector(isTuple() is true)
* @return nullptr if v isn't a tuple vector
* @return a copyed vector if v is subVector or SlicedVector(isView() is true)
* @return v if v is an AnyVector
*/
static SmartPointer<AnyVector> toAnyVector(const VectorSP& v) {
if (LIKELY(!v->isView()))
return v;
// v may be a SubVector or SlicedVector
return ((Constant*)v.get())->getValue();
}
private:
ConstantSP calcRowMetric(INDEX rowStart, INDEX count, OptrFunc func, FastFunc fastFunc, const ConstantSP& b, DATA_TYPE type) const;
ConstantSP sliceOneColumn(int colIndex, INDEX rowStart, INDEX rowEnd) const;
/**
* colStart: inclusive
* colEnd: exclusive
* rowStart: inclusive
* rowEnd: exclusive
*/
ConstantSP sliceColumnRange(int colStart, int colEnd, INDEX rowStart, INDEX rowEnd) const;
private:
mutable deque<ConstantSP> data_;
bool containNull_;
bool isDim_;
bool isTableColumn_;
DATA_TYPE dt_;
int decimalExtra_;
};
class SlicedVector : public Vector {
public:
/**
* source: a regular array or huge array. Can't be a SubVector, SlicedVector, RepeatingVector, or ArrayVector.
* index: a regular index array.
*/
SlicedVector(const VectorSP& source, const VectorSP& index);
virtual ~SlicedVector(){}
virtual VECTOR_TYPE getVectorType() const {return VECTOR_TYPE::SLICEDVECTOR;}
VectorSP getSourceVector() const { return source_;}
VectorSP getIndexVector() const { return index_;}
void reset(const VectorSP& source, const VectorSP& index);
virtual bool copyable() const {return false;}
virtual bool isView() const {return true;}
virtual INDEX size() const { return size_;}
virtual DATA_TYPE getRawType() const {return source_->getRawType();}
virtual int getExtraParamForType() const { return source_->getExtraParamForType();}
virtual SymbolBaseSP getSymbolBase() const {return source_->getSymbolBase();}
virtual DATA_FORM getForm() const { return DF_VECTOR;}
virtual ConstantSP getInstance() const {return source_->getInstance(size_);}
virtual ConstantSP getInstance(INDEX size) const {return source_->getInstance(size);}
virtual ConstantSP getValue() const { return ((Constant*)source_.get())->get(index_);}
virtual ConstantSP getValue(INDEX capacity) const;
virtual ConstantSP getWindow(INDEX colStart, int colLength, INDEX rowStart, int rowLength) const;
virtual ConstantSP getSubVector(INDEX start, INDEX length, INDEX capacity) const;
virtual ConstantSP getSubVector(INDEX start, INDEX length) const;
virtual void fill(INDEX start, INDEX length, const ConstantSP& value, INDEX valueOffset = 0) override{throw RuntimeException("Sliced vector doesn't support method fill");}
virtual bool validIndex(INDEX uplimit){throw RuntimeException("Sliced vector doesn't support method validIndex");}
virtual bool validIndex(INDEX start, INDEX length, INDEX uplimit){throw RuntimeException("Sliced vector doesn't support method validIndex");}
virtual int compare(INDEX index, const ConstantSP& target) const {return source_->compare(pindex_[index], target);}
virtual bool getNullFlag() const {return source_->getNullFlag();}
virtual void setNullFlag(bool containNull){}
virtual bool hasNull(){return hasNull(0, size_);}
virtual bool hasNull(INDEX start, INDEX length);
virtual INDEX getCapacity() const {return size_;}
virtual bool isFastMode() const { return source_->isFastMode();}
virtual void* getDataArray() const { return nullptr;}
virtual bool isIndexArray() const { return false;}
virtual INDEX* getIndexArray() const { return nullptr;}
virtual short getUnitLength() const {return source_->getUnitLength();}
virtual void** getDataSegment() const {return nullptr;}
virtual bool sizeable() const {return false;}
virtual char getBool() const {return source_->getBool(pindex_[0]);}
virtual char getChar() const { return source_->getChar(pindex_[0]);}
virtual short getShort() const { return source_->getShort(pindex_[0]);}
virtual int getInt() const {return source_->getInt(pindex_[0]);}
virtual long long getLong() const {return source_->getLong(pindex_[0]);}
virtual INDEX getIndex() const {return source_->getIndex(pindex_[0]);}
virtual float getFloat() const {return source_->getFloat(pindex_[0]);}
virtual double getDouble() const {return source_->getDouble(pindex_[0]);}
virtual ConstantSP get(INDEX index) const { return source_->get(pindex_[index]);}
virtual ConstantSP get(const ConstantSP& index) const;
virtual ConstantSP get(INDEX offset, const ConstantSP& index) const;
virtual void setBool(bool val){throw RuntimeException("Sliced vector doesn't support method setBool");}
virtual void setChar(char val){throw RuntimeException("Sliced vector doesn't support method setChar");}
virtual void setShort(short val){throw RuntimeException("Sliced vector doesn't support method setShort");}
virtual void setInt(int val){throw RuntimeException("Sliced vector doesn't support method setInt");}
virtual void setLong(long long val){throw RuntimeException("Sliced vector doesn't support method setLong");}
virtual void setIndex(INDEX val){throw RuntimeException("Sliced vector doesn't support method setIndex");}
virtual void setFloat(float val){throw RuntimeException("Sliced vector doesn't support method setFloat");}
virtual void setDouble(double val){throw RuntimeException("Sliced vector doesn't support method setDouble");}
virtual void setString(const string& val){throw RuntimeException("Sliced vector doesn't support method setString");}
virtual void setNull(){throw RuntimeException("Sliced vector doesn't support method setNull");}
virtual char getBool(INDEX index) const {return source_->getBool(pindex_[index]);}
virtual char getChar(INDEX index) const { return source_->getChar(pindex_[index]);}
virtual short getShort(INDEX index) const { return source_->getShort(pindex_[index]);}
virtual int getInt(INDEX index) const {return source_->getInt(pindex_[index]);}
virtual long long getLong(INDEX index) const {return source_->getLong(pindex_[index]);}
virtual INDEX getIndex(INDEX index) const {return source_->getIndex(pindex_[index]);}
virtual float getFloat(INDEX index) const {return source_->getFloat(pindex_[index]);}
virtual double getDouble(INDEX index) const {return source_->getDouble(pindex_[index]);}
virtual bool isNull(INDEX index) const {return source_->isNull(pindex_[index]);}
virtual string getString(INDEX index) const {return source_->getString(pindex_[index]);}
virtual const DolphinString& getStringRef(INDEX index) const {return source_->getStringRef(pindex_[index]);}
virtual void clear(){throw RuntimeException("Sliced vector doesn't support method clear");}
virtual bool remove(INDEX count){throw RuntimeException("Sliced vector doesn't support method remove");}
virtual bool remove(const ConstantSP& index){throw RuntimeException("Indexed vector doesn't support method remove");}
virtual void next(INDEX steps){throw RuntimeException("Sliced vector doesn't support method next");}
virtual void prev(INDEX steps){throw RuntimeException("Sliced vector doesn't support method prev");}
virtual void nullFill(const ConstantSP& val){throw RuntimeException("Sliced vector doesn't support method nullFill");}
virtual bool isNull(INDEX start, int len, char* buf) const { return source_->isNull(pindex_ + start, len, buf);}
virtual bool isValid(INDEX start, int len, char* buf) const {return source_->isValid(pindex_ + start, len, buf);}
virtual bool getBool(INDEX start, int len, char* buf) const {return source_->getBool(pindex_ + start, len, buf);}
virtual const char* getBoolConst(INDEX start, int len, char* buf) const {
source_->getBool(pindex_ + start, len, buf);
return buf;
}
virtual char* getBoolBuffer(INDEX start, int len, char* buf) const {return buf;}
virtual bool getChar(INDEX start, int len, char* buf) const {return source_->getChar(pindex_ + start, len, buf);}
virtual const char* getCharConst(INDEX start, int len, char* buf) const {
source_->getChar(pindex_ + start, len, buf);
return buf;
}
virtual char* getCharBuffer(INDEX start, int len, char* buf) const {return buf;}
virtual bool getShort(INDEX start, int len, short* buf) const {return source_->getShort(pindex_ + start, len, buf);}
virtual const short* getShortConst(INDEX start, int len, short* buf) const {
source_->getShort(pindex_ + start, len, buf);
return buf;
}
virtual short* getShortBuffer(INDEX start, int len, short* buf) const {return buf;}
virtual bool getInt(INDEX start, int len, int* buf) const {return source_->getInt(pindex_ + start, len, buf);}
virtual const int* getIntConst(INDEX start, int len, int* buf) const {
source_->getInt(pindex_ + start, len, buf);
return buf;
}
virtual int* getIntBuffer(INDEX start, int len, int* buf) const {return buf;}
virtual bool getLong(INDEX start, int len, long long* buf) const {return source_->getLong(pindex_ + start, len, buf);}
virtual const long long* getLongConst(INDEX start, int len, long long* buf) const {
source_->getLong(pindex_ + start, len, buf);
return buf;
}
virtual long long* getLongBuffer(INDEX start, int len, long long* buf) const {return buf;}
virtual bool getBinary(INDEX start, int len, int unitLength, unsigned char* buf) const {return source_->getBinary(pindex_ + start, len, unitLength, buf);}
virtual const unsigned char* getBinaryConst(INDEX start, int len, int unitLength, unsigned char* buf) const {
source_->getBinary(pindex_ + start, len, unitLength, buf);
return buf;
}
virtual unsigned char* getBinaryBuffer(INDEX start, int len, int unitLength, unsigned char* buf) const {return buf;}
virtual bool getIndex(INDEX start, int len, INDEX* buf) const {return source_->getIndex(pindex_ + start, len, buf);}
virtual const INDEX* getIndexConst(INDEX start, int len, INDEX* buf) const {
source_->getIndex(pindex_ + start, len, buf);
return buf;
}
virtual INDEX* getIndexBuffer(INDEX start, int len, INDEX* buf) const {return buf;}
virtual bool getFloat(INDEX start, int len, float* buf) const {return source_->getFloat(pindex_ + start, len, buf);}
virtual const float* getFloatConst(INDEX start, int len, float* buf) const {
source_->getFloat(pindex_ + start, len, buf);
return buf;
}
virtual float* getFloatBuffer(INDEX start, int len, float* buf) const {return buf;}
virtual bool getDouble(INDEX start, int len, double* buf) const {return source_->getDouble(pindex_ + start, len, buf);}
virtual const double* getDoubleConst(INDEX start, int len, double* buf) const {
source_->getDouble(pindex_ + start, len, buf);
return buf;
}
virtual double* getDoubleBuffer(INDEX start, int len, double* buf) const {return buf;}
virtual bool getString(INDEX start, int len, char** buf) const {return ((Constant*)source_.get())->getString(pindex_ + start, len, buf);}
virtual char** getStringConst(INDEX start, int len, char** buf) const {
((Constant*)source_.get())->getString(pindex_ + start, len, buf);
return buf;
}
virtual bool getString(INDEX start, int len, DolphinString** buf) const {return ((Constant*)source_.get())->getString(pindex_ + start, len, buf);}
virtual DolphinString** getStringConst(INDEX start, int len, DolphinString** buf) const {
((Constant*)source_.get())->getString(pindex_ + start, len, buf);
return buf;
}
virtual const int* getSymbolConst(INDEX start, int len, int* buf, SymbolBase* symBase, bool insertIfNotThere) const {
source_->getSymbol(pindex_ + start, len, buf, symBase, insertIfNotThere);
return buf;
}
virtual bool getSymbol(INDEX start, int len, int* buf, SymbolBase* symBase, bool insertIfNotThere) const { return source_->getSymbol(pindex_ + start, len, buf, symBase, insertIfNotThere);}
virtual bool isNull(INDEX* indices, int len, char* buf) const;
virtual bool isValid(INDEX* indices, int len, char* buf) const;
virtual bool getBool(INDEX* indices, int len, char* buf) const;
virtual bool getChar(INDEX* indices, int len,char* buf) const;
virtual bool getShort(INDEX* indices, int len, short* buf) const;
virtual bool getInt(INDEX* indices, int len, int* buf) const;
virtual bool getLong(INDEX* indices, int len, long long* buf) const;
virtual bool getIndex(INDEX* indices, int len, INDEX* buf) const;
virtual bool getFloat(INDEX* indices, int len, float* buf) const;
virtual bool getDouble(INDEX* indices, int len, double* buf) const;
virtual bool getSymbol(INDEX* indices, int len, int* buf, SymbolBase* symBase,bool insertIfNotThere) const;
virtual bool getString(INDEX* indices, int len, DolphinString** buf) const;
virtual bool getString(INDEX* indices, int len, char** buf) const;
virtual bool getBinary(INDEX* indices, int len, int unitLength, unsigned char* buf) const;
virtual bool isNullSafe(INDEX offset, INDEX* indices, int len, char* buf) const;
virtual bool isValidSafe(INDEX offset, INDEX* indices, int len, char* buf) const;
virtual bool getBoolSafe(INDEX offset, INDEX* indices, int len, char* buf) const;
virtual bool getCharSafe(INDEX offset, INDEX* indices, int len,char* buf) const;
virtual bool getShortSafe(INDEX offset, INDEX* indices, int len, short* buf) const;
virtual bool getIntSafe(INDEX offset, INDEX* indices, int len, int* buf) const;
virtual bool getLongSafe(INDEX offset, INDEX* indices, int len, long long* buf) const;
virtual bool getIndexSafe(INDEX offset, INDEX* indices, int len, INDEX* buf) const;
virtual bool getFloatSafe(INDEX offset, INDEX* indices, int len, float* buf) const;
virtual bool getDoubleSafe(INDEX offset, INDEX* indices, int len, double* buf) const;
virtual bool getSymbolSafe(INDEX offset, INDEX* indices, int len, int* buf, SymbolBase* symBase,bool insertIfNotThere) const;
virtual bool getStringSafe(INDEX offset, INDEX* indices, int len, DolphinString** buf) const;
virtual bool getStringSafe(INDEX offset, INDEX* indices, int len, char** buf) const;
virtual bool getBinarySafe(INDEX offset, INDEX* indices, int len, int unitLength, unsigned char* buf) const;
virtual long long count() const {return count(0, index_->size());}
virtual long long count(INDEX start, INDEX length) const;
virtual ConstantSP minmax() const {return minmax(0, size_);}
virtual ConstantSP minmax(INDEX start, INDEX length) const;
/**
* @param rightMost If there are multiple maximum/minimum values, choose the last one if `rightMost` is true.
*/
virtual INDEX imax(bool rightMost = false) const override { return imax(0, size_, rightMost); }
virtual INDEX imax(INDEX start, INDEX length, bool rightMost = false) const override;
virtual INDEX imin(bool rightMost = false) const override { return imin(0, size_, rightMost); }
virtual INDEX imin(INDEX start, INDEX length, bool rightMost = false) const override;
virtual ConstantSP max() const {return max(0, index_->size());}
virtual ConstantSP max(INDEX start, INDEX length) const;
virtual void max(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP min() const {return min(0, index_->size());}
virtual ConstantSP min(INDEX start, INDEX length) const;
virtual void min(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP avg() const {return avg(0, index_->size());}
virtual ConstantSP avg(INDEX start, INDEX length) const;
virtual void avg(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP sum() const {return sum(0, index_->size());}
virtual ConstantSP sum(INDEX start, INDEX length) const;
virtual void sum(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP sum2() const {return sum2(0, index_->size());}
virtual ConstantSP sum2(INDEX start, INDEX length) const;
virtual void sum2(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP prd() const {return prd(0, index_->size());}
virtual ConstantSP prd(INDEX start, INDEX length) const;
virtual void prd(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP var() const {return var(0, index_->size());}
virtual ConstantSP var(INDEX start, INDEX length) const;
virtual void var(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP std() const {return std(0, index_->size());}
virtual ConstantSP std(INDEX start, INDEX length) const;
virtual void std(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP mode() const {return mode(0, index_->size());}
virtual ConstantSP mode(INDEX start, INDEX length) const;
virtual void mode(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP median() const {return median(0, index_->size());}
virtual ConstantSP median(INDEX start, INDEX length) const;
virtual void median(INDEX start, INDEX length, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP searchK(INDEX k) const {return searchK(0, size_, k);}
virtual ConstantSP searchK(INDEX start, INDEX length, INDEX k) const;
virtual void searchK(INDEX start, INDEX length, INDEX k, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP firstNot(const ConstantSP& exclude) const { return firstNot(0, size_, exclude);}
virtual ConstantSP firstNot(INDEX start, INDEX length, const ConstantSP& exclude) const;
virtual void firstNot(INDEX start, INDEX length, const ConstantSP& exclude, const ConstantSP& out, INDEX outputStart = 0) const;
virtual ConstantSP lastNot(const ConstantSP& exclude) const { return lastNot(0, size_, exclude);}
virtual ConstantSP lastNot(INDEX start, INDEX length, const ConstantSP& exclude) const;
virtual void lastNot(INDEX start, INDEX length, const ConstantSP& exclude, const ConstantSP& out, INDEX outputStart = 0) const;
virtual void neg(){throw RuntimeException("Sliced vector doesn't support method neg");}
virtual void replace(const ConstantSP& oldVal, const ConstantSP& newVal){throw RuntimeException("Sliced vector doesn't support method replace");}
virtual void shuffle(){throw RuntimeException("Sliced vector doesn't support method shuffle");}
virtual void reverse(){throw RuntimeException("Sliced vector doesn't support method reverse");}
virtual void reverse(INDEX start, INDEX length){throw RuntimeException("Sliced vector doesn't support method reverse");}
virtual bool rank(bool sorted, INDEX* indices, INDEX* ranking){throw RuntimeException("Sliced vector doesn't support method rank");}
virtual void find(INDEX start, INDEX length, const ConstantSP& target, const ConstantSP& resultSP);
virtual void binarySearch(INDEX start, INDEX length, const ConstantSP& target, const ConstantSP& resultSP);
virtual void asof(INDEX start, INDEX length, const ConstantSP& target, const ConstantSP& resultSP);
virtual bool findDuplicatedElements(Vector* indices, INDEX start, INDEX length, vector<pair<INDEX,INDEX> >& duplicates){
throw RuntimeException("Sliced vector doesn't support method findDuplicatedElements");
}
virtual bool findDuplicatedElements(INDEX start, INDEX length, vector<pair<INDEX,INDEX> >& duplicates){
throw RuntimeException("Sliced vector doesn't support method findDuplicatedElements");
}
virtual bool findUniqueElements(INDEX start, INDEX length, vector<pair<INDEX,INDEX> >& uniques){
throw RuntimeException("Sliced vector doesn't support method findUniqueElements");
}
virtual bool findRange(INDEX* ascIndices,const ConstantSP& target,INDEX* targetIndices,vector<pair<INDEX,INDEX> >& ranges){
throw RuntimeException("Sliced vector doesn't support method findRange");
}
virtual bool findRange(const ConstantSP& target,INDEX* targetIndices,vector<pair<INDEX,INDEX> >& ranges){
throw RuntimeException("Sliced vector doesn't support method findRange");
}
virtual INDEX lowerBound(INDEX start, const ConstantSP& target);
virtual long long getAllocatedMemory() const {return sizeof(SlicedVector);}
virtual int serialize(char* buf, int bufSize, INDEX indexStart, int offset, int& numElement, int& partial) const {
throw RuntimeException("Sliced vector doesn't support method serialize");
}
virtual int serialize(char* buf, int bufSize, INDEX indexStart, int offset, int targetNumElement, int& numElement, int& partial) const {
throw RuntimeException("Sliced vector doesn't support method serialize");
}
virtual IO_ERR serialize(const ByteArrayCodeBufferSP& buffer) const {throw RuntimeException("Sliced vector doesn't support method serialize");}
virtual bool isSorted(INDEX start, INDEX length, bool asc, bool strict, char nullsOrder = 0) const {throw RuntimeException("Sliced vector doesn't support method isSorted");}
virtual ConstantSP topK(INDEX start, INDEX length, INDEX top, bool asc, bool extendEqualValue) const {throw RuntimeException("Sliced vector doesn't support method topK");}
virtual bool sort(bool asc, char nullsOrder = 0) {throw RuntimeException("Sliced vector doesn't support method sort");}
virtual bool sort(bool asc, Vector* indices, char nullsOrder = 0) {throw RuntimeException("Sliced vector doesn't support method sort");}
virtual bool sortSelectedIndices(Vector* indices, INDEX start, INDEX length, bool asc, char nullsOrder = 0) {
throw RuntimeException("Sliced vector doesn't support method sortSelectedIndices");
}
private:
VectorSP source_;
VectorSP index_;
INDEX* pindex_;
INDEX size_;
};
class SubVector : public Vector {
public:
SubVector(const VectorSP& target, INDEX offset, INDEX length, bool updatable = false);
void reset(const VectorSP& target, INDEX offset, INDEX length);
void reset(INDEX offset, INDEX length);
virtual ~SubVector(){}
virtual bool isLargeConstant() const {return true;}
virtual VECTOR_TYPE getVectorType() const {return VECTOR_TYPE::SUBVECTOR;}
VectorSP getSourceVector() const { return source_;}
INDEX getSubVectorStart() const { return offset_;}
INDEX getSubVectorLength() const { return size_;}
virtual int getSegmentSizeInBit() const override { return source_->getSegmentSizeInBit(); }
virtual bool copyable() const {return true;}
virtual bool isView() const {return true;}
virtual DATA_TYPE getRawType() const {return source_->getRawType();}
virtual int getExtraParamForType() const { return source_->getExtraParamForType();}
virtual bool isTableColumn() const { return source_->isTableColumn();}
virtual SymbolBaseSP getSymbolBase() const {return source_->getSymbolBase();}
virtual DATA_FORM getForm() const { return DF_VECTOR;}
virtual ConstantSP getInstance() const {return getInstance(size_);}
virtual ConstantSP getInstance(INDEX size) const;
virtual ConstantSP getValue() const { return source_->getSubVector(offset_, size_);}
virtual ConstantSP getValue(INDEX capacity) const { return source_->getSubVector(offset_, size_, capacity);}
virtual ConstantSP get(INDEX column, INDEX rowStart,INDEX rowEnd) const {return source_->getSubVector(offset_ + rowStart,rowEnd-rowStart);}
virtual ConstantSP getWindow(INDEX colStart, int colLength, INDEX rowStart, int rowLength) const;
virtual ConstantSP getSlice(const ConstantSP& rowIndex, const ConstantSP& colIndex) const;
virtual ConstantSP getSubVector(INDEX start, INDEX length, INDEX capacity) const;
virtual ConstantSP getSubVector(INDEX start, INDEX length) const {
return getSubVector(start, length, std::abs(length));
}
virtual void fill(INDEX start, INDEX length, const ConstantSP& value, INDEX valueOffset = 0) override{
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method fill");
else
source_->fill(offset_ + start, length, value, valueOffset);
}
virtual bool validIndex(INDEX uplimit){return source_->validIndex(offset_, size_, uplimit);}
virtual bool validIndex(INDEX start, INDEX length, INDEX uplimit){return source_->validIndex(start + offset_, length, uplimit);}
virtual int compare(INDEX index, const ConstantSP& target) const {return source_->compare(offset_ + index, target);}
virtual bool getNullFlag() const {
if (offset_ >= 0 && offset_ + size_ <= source_->size())
return source_->getNullFlag();
return true;
}
virtual void setNullFlag(bool containNull){}
virtual bool hasNull(){
if (offset_ >= 0 && offset_ + size_ <= source_->size())
return source_->hasNull(offset_, size_);
return true;
}
virtual bool hasNull(INDEX start, INDEX length){
if (start + offset_ >= 0 && start + offset_ + length <= source_->size())
return source_->hasNull(start + offset_, length);
return true;
}
virtual INDEX getCapacity() const {return size_;}
virtual bool isFastMode() const { return source_->isFastMode();}
virtual void* getDataArray() const;
virtual bool isIndexArray() const { return source_->isIndexArray();}
virtual INDEX* getIndexArray() const { return source_->isIndexArray() ? source_->getIndexArray() + offset_ : NULL;}
virtual short getUnitLength() const {return source_->getUnitLength();}
virtual void** getDataSegment() const;
virtual bool sizeable() const {return source_->sizeable();}
virtual char getBool() const {return source_->getBool(offset_);}
virtual char getChar() const { return source_->getChar(offset_);}
virtual short getShort() const { return source_->getShort(offset_);}
virtual int getInt() const {return source_->getInt(offset_);}
virtual long long getLong() const {return source_->getLong(offset_);}
virtual INDEX getIndex() const {return source_->getIndex(offset_);}
virtual float getFloat() const {return source_->getFloat(offset_);}
virtual double getDouble() const {return source_->getDouble(offset_);}
virtual void contain(const ConstantSP& target, const ConstantSP& resultSP) const override;
virtual ConstantSP get(INDEX index) const override;
virtual ConstantSP get(const ConstantSP& index) const;
virtual ConstantSP get(INDEX offset, const ConstantSP& index) const;
virtual void setBool(bool val){throw RuntimeException("Immutable sub vector doesn't support method setBool");}
virtual void setChar(char val){throw RuntimeException("Immutable sub vector doesn't support method setChar");}
virtual void setShort(short val){throw RuntimeException("Immutable sub vector doesn't support method setShort");}
virtual void setInt(int val){throw RuntimeException("Immutable sub vector doesn't support method setInt");}
virtual void setLong(long long val){throw RuntimeException("Immutable sub vector doesn't support method setLong");}
virtual void setIndex(INDEX val){throw RuntimeException("Immutable sub vector doesn't support method setIndex");}
virtual void setFloat(float val){throw RuntimeException("Immutable sub vector doesn't support method setFloat");}
virtual void setDouble(double val){throw RuntimeException("Immutable sub vector doesn't support method setDouble");}
virtual void setString(const string& val){throw RuntimeException("Immutable sub vector doesn't support method setString");}
virtual void setNull(){throw RuntimeException("Immutable sub vector doesn't support method setNull");}
virtual char getBool(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return CHAR_MIN;
}
return source_->getBool(offset_ + index);
}
virtual char getChar(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return CHAR_MIN;
}
return source_->getChar(offset_ + index);
}
virtual short getShort(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return SHRT_MIN;
}
return source_->getShort(offset_ + index);
}
virtual int getInt(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return INT_MIN;
}
return source_->getInt(offset_ + index);
}
virtual long long getLong(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return LONG_MIN;
}
return source_->getLong(offset_ + index);
}
virtual INDEX getIndex(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return INDEX_MIN;
}
return source_->getIndex(offset_ + index);
}
virtual float getFloat(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return FLT_NMIN;
}
return source_->getFloat(offset_ + index);
}
virtual double getDouble(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return DBL_NMIN;
}
return source_->getDouble(offset_ + index);
}
virtual bool isNull(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return true;
}
return source_->isNull(offset_ + index);
}
virtual string getString(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
return "";
}
return source_->getString(offset_ + index);
}
virtual const DolphinString& getStringRef(INDEX index) const {
if (index < 0 || index >= size_ || offset_ + index < 0 || offset_ + index >= source_->size()) {
throw RuntimeException("Index out of range.");
}
return source_->getStringRef(offset_ + index);
}
virtual void setBool(INDEX index,char val) {
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setBool");
else
source_->setBool(offset_ + index, val);
}
virtual void setChar(INDEX index,char val){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setChar");
else
source_->setChar(offset_ + index, val);
}
virtual void setShort(INDEX index,short val){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setShort");
else
source_->setShort(offset_ + index, val);
}
virtual void setInt(INDEX index,int val){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setInt");
else
source_->setInt(offset_ + index, val);
}
virtual void setLong(INDEX index,long long val){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setLong");
else
source_->setLong(offset_ + index, val);
}
virtual void setIndex(INDEX index, INDEX val){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setIndex");
else
source_->setIndex(offset_ + index, val);
}
virtual void setFloat(INDEX index,float val){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setFloat");
else
source_->setFloat(offset_ + index, val);
}
virtual void setDouble(INDEX index, double val){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setDouble");
else
source_->setDouble(offset_ + index, val);
}
virtual void setString(INDEX index, const DolphinString& val){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setString");
else
source_->setString(offset_ + index, val);
}
virtual void setBinary(INDEX index, int unitLength, const unsigned char* val){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setBinary");
else
source_->setBinary(offset_ + index, unitLength, val);
}
virtual void setNull(INDEX index){
if(!updatable_)
throw RuntimeException("Immutable sub vector doesn't support method setNull");
else
source_->setNull(offset_ + index);
}
virtual void clear(){throw RuntimeException("Immutable sub vector doesn't support method clear");}
virtual bool remove(INDEX count){throw RuntimeException("Immutable sub vector doesn't support method remove");}
virtual bool remove(const ConstantSP& index){throw RuntimeException("Immutable sub vector doesn't support method remove");}
virtual void next(INDEX steps){throw RuntimeException("Immutable sub vector doesn't support method next");}
virtual void prev(INDEX steps){throw RuntimeException("Immutable sub vector doesn't support method prev");}
virtual INDEX size() const {
if(source_->size() < offset_ + size_ && source_->size() == 0)
throw RuntimeException("The source vector has been shortened and the sub vector is not valid any more.");
return size_;
}
virtual void nullFill(const ConstantSP& val){throw RuntimeException("Immutable sub vector doesn't support method nullFill");}
virtual bool isNull(INDEX start, int len, char* buf) const {
if (start < 0 || offset_ + start < 0) {
INDEX cur = 0;
if (start < 0) {
cur = std::max(cur, std::abs(start));
}
if (offset_ + start < 0) {
cur = std::max(cur, std::abs(offset_ + start));
}
cur = std::min(len, cur);
for (INDEX i = 0; i < cur; ++i) {
buf[i] = true;
}
start += cur;
len -= cur;
buf += cur;
}
int validLen = std::max(0, std::min(len, std::min(size_ - start, source_->size() - offset_ - start)));
if(offset_ + start < source_->size() && validLen > 0 && !source_->isNull(offset_ + start, validLen, buf)) {
return false;
}
if (validLen < len) {
for (int i = validLen; i < len; ++i) {
buf[i] = true;
}
}
return true;
}
virtual bool isValid(INDEX start, int len, char* buf) const {
if (start < 0 || offset_ + start < 0) {
INDEX cur = 0;
if (start < 0) {
cur = std::max(cur, std::abs(start));
}
if (offset_ + start < 0) {
cur = std::max(cur, std::abs(offset_ + start));
}
cur = std::min(len, cur);
for (INDEX i = 0; i < cur; ++i) {
buf[i] = false;
}
start += cur;
len -= cur;
buf += cur;
}
int validLen = std::max(0, std::min(len, std::min(size_ - start, source_->size() - offset_ - start)));
if(offset_ + start < source_->size() && validLen > 0 && !source_->isValid(offset_ + start, validLen, buf)) {
return false;
}
if (validLen < len) {
for (int i = validLen; i < len; ++i) {
buf[i] = false;
}
}
return true;
}
virtual bool getBool(INDEX start, int len, char* buf) const {
if (start < 0 || offset_ + start < 0) {
INDEX cur = 0;
if (start < 0) {
cur = std::max(cur, std::abs(start));
}
if (offset_ + start < 0) {
cur = std::max(cur, std::abs(offset_ + start));
}
cur = std::min(len, cur);
for (INDEX i = 0; i < cur; ++i) {
buf[i] = CHAR_MIN;
}
start += cur;
len -= cur;
buf += cur;
}
int validLen = std::max(0, std::min(len, std::min(size_ - start, source_->size() - offset_ - start)));
if(offset_ + start < source_->size() && validLen > 0 && !source_->getBool(offset_ + start, validLen, buf)) {
return false;
}
if (validLen < len) {
for (int i = validLen; i < len; ++i) {
buf[i] = CHAR_MIN;
}
}
return true;
}
virtual const char* getBoolConst(INDEX start, int len, char* buf) const {
if (start >= 0 && start + len <= size_ && offset_ + start >= 0 && offset_ + start + len <= source_->size()) {
return source_->getBoolConst(offset_ + start, len, buf);
}
char* originalBuf = buf;
if (start < 0 || offset_ + start < 0) {
INDEX cur = 0;
if (start < 0) {
cur = std::max(cur, std::abs(start));
}
if (offset_ + start < 0) {
cur = std::max(cur, std::abs(offset_ + start));
}
cur = std::min(len, cur);
for (INDEX i = 0; i < cur; ++i) {
buf[i] = CHAR_MIN;
}
start += cur;
len -= cur;
buf += cur;
}
int validLen = std::max(0, std::min(len, std::min(size_ - start, source_->size() - offset_ - start)));
if (offset_ + start < source_->size() && validLen > 0)
source_->getBool(offset_ + start, validLen, buf);
if (validLen < len) {
for (int i = validLen; i < len; ++i) {
buf[i] = CHAR_MIN;
}
}
return originalBuf;
}
virtual char* getBoolBuffer(INDEX start, int len, char* buf) const {return source_->getBoolBuffer(offset_ + start, len, buf);}
virtual bool getChar(INDEX start, int len, char* buf) const {
if (start < 0 || offset_ + start < 0) {
INDEX cur = 0;
if (start < 0) {
cur = std::max(cur, std::abs(start));
}
if (offset_ + start < 0) {
cur = std::max(cur, std::abs(offset_ + start));
}
cur = std::min(len, cur);
for (INDEX i = 0; i < cur; ++i) {
buf[i] = CHAR_MIN;
}
start += cur;
len -= cur;
buf += cur;
}
int validLen = std::max(0, std::min(len, std::min(size_ - start, source_->size() - offset_ - start)));
if(offset_ + start < source_->size() && validLen > 0 && !source_->getChar(offset_ + start, validLen, buf)) {
return false;
}
if (validLen < len) {
for (int i = validLen; i < len; ++i) {
buf[i] = CHAR_MIN;
}
}
return true;
}