@@ -205,8 +205,8 @@ class AbstractFastVector: public Vector{
205
205
IO_ERR deserialize (DataInputStream* in, INDEX indexStart, INDEX targetNumElement, INDEX& numElement){
206
206
IO_ERR ret=OK;
207
207
INDEX end = indexStart + targetNumElement;
208
- if (end > capacity_ && ! checkCapacity (end - size_))
209
- return NOSPACE;
208
+ checkCapacity (end - size_);
209
+
210
210
INDEX i=indexStart;
211
211
size_t unitLength = sizeof (T);
212
212
if (!in->isIntegerReversed ()){
@@ -693,11 +693,6 @@ class AbstractFastVector: public Vector{
693
693
return appendData<long long >(buf, len, type, LLONG_MIN);
694
694
}
695
695
696
- virtual bool appendInt128 (wide_integer::int128* buf, int len){
697
- DATA_TYPE type = getRawType ()== DT_DECIMAL128 ? getType () : DT_DECIMAL128;
698
- return appendData<wide_integer::int128>(buf, len, type, std::numeric_limits<wide_integer::int128>::min ());
699
- }
700
-
701
696
virtual bool appendIndex (INDEX* buf, int len){
702
697
DATA_TYPE type = getRawType ()== DT_INDEX ? getType () : DT_INDEX;
703
698
return appendData<INDEX>(buf, len, type, INDEX_MIN);
@@ -950,8 +945,7 @@ class AbstractFastVector: public Vector{
950
945
951
946
template <typename Y>
952
947
inline bool appendData (Y* buf, int len, DATA_TYPE sourceType, Y sourceNullVal){
953
- if (!checkCapacity (len))
954
- return false ;
948
+ checkCapacity (len);
955
949
if (getType () == sourceType)
956
950
memcpy (data_+size_, buf, sizeof (Y) * len);
957
951
else
@@ -961,7 +955,7 @@ class AbstractFastVector: public Vector{
961
955
return true ;
962
956
}
963
957
964
- bool checkCapacity (int appendSize){
958
+ void checkCapacity (int appendSize){
965
959
if (size_+appendSize>capacity_){
966
960
INDEX newCapacity= static_cast <INDEX>((size_ + appendSize) * 1.2 );
967
961
T* newData = new T[newCapacity];
@@ -970,7 +964,6 @@ class AbstractFastVector: public Vector{
970
964
capacity_=newCapacity;
971
965
data_=newData;
972
966
}
973
- return true ;
974
967
}
975
968
976
969
T* getDataArray (const Vector* indexVector, bool & haveNull) const {
@@ -1060,14 +1053,27 @@ class AbstractFastVector: public Vector{
1060
1053
}
1061
1054
1062
1055
void getDataArray (INDEX start, INDEX length, T* buf) const {
1063
- if (length>0 )
1064
- memcpy (buf,data_+start,length*sizeof (T));
1056
+ if (length>0 ){
1057
+ if (start >= 0 && start + length <= size_){
1058
+ memcpy (buf,data_ + start,length * sizeof (T));
1059
+ }
1060
+ else {
1061
+ for (INDEX i = 0 ; i < length; ++i){
1062
+ buf[i] = (start + i >= 0 && start + i < size_) ? data_[start + i] : getNullValue<T>();
1063
+ }
1064
+ }
1065
+ }
1065
1066
else {
1066
1067
T* src=data_+start;
1067
1068
T* dest=buf;
1068
1069
length=std::abs (length);
1069
1070
while (length>0 ){
1070
- *dest=*src;
1071
+ if (src >= data_ && src < data_ + size_){
1072
+ *dest = *src;
1073
+ }
1074
+ else {
1075
+ *dest = getNullValue<T>();
1076
+ }
1071
1077
++dest;
1072
1078
--src;
1073
1079
--length;
@@ -1091,27 +1097,6 @@ class AbstractFastVector: public Vector{
1091
1097
DATA_TYPE dataType_;
1092
1098
};
1093
1099
1094
- template <>
1095
- template <typename Y>
1096
- inline bool AbstractFastVector<wide_integer::int128>::setData(int start, int len, DATA_TYPE sourceType, Y sourceNullVal, const Y* buf){
1097
- (void )sourceType;
1098
- for (int i = 0 ; i < len; ++i)
1099
- data_[start + i] = (buf[i] == sourceNullVal) ? nullVal_ : static_cast <wide_integer::int128>(buf[i]);
1100
- return true ;
1101
- }
1102
-
1103
- template <>
1104
- template <typename Y>
1105
- inline bool AbstractFastVector<wide_integer::int128>::appendData(Y* buf, int len, DATA_TYPE sourceType, Y sourceNullVal){
1106
- (void )sourceType;
1107
- if (!checkCapacity (len))
1108
- return false ;
1109
- for (int i = 0 ; i < len; ++i)
1110
- data_[size_ + i]=(buf[i] == sourceNullVal)? nullVal_ : static_cast <wide_integer::int128>(buf[i]);
1111
- size_ += len;
1112
- return true ;
1113
- }
1114
-
1115
1100
class FastVoidVector :public AbstractFastVector <char >{
1116
1101
public:
1117
1102
FastVoidVector (int sz, int capacity, char * srcData, bool containNull):AbstractFastVector(sz,capacity,srcData,CHAR_MIN, containNull){
@@ -1754,16 +1739,6 @@ class FastNanoTimestampVector:public FastLongVector{
1754
1739
virtual ConstantSP castTemporal (DATA_TYPE expectType);
1755
1740
};
1756
1741
1757
- class FastCompressedVector : public FastCharVector {
1758
- public:
1759
- FastCompressedVector (int sz, int capacity, char * srcData)
1760
- :FastCharVector(sz, capacity, srcData, false ){}
1761
- virtual ~FastCompressedVector (){}
1762
- virtual DATA_TYPE getType () const {return DT_COMPRESS;}
1763
- virtual INDEX uncompressedRows () const ;
1764
- virtual int asof (const ConstantSP& value) const {throw RuntimeException (" asof not supported." );}
1765
- };
1766
-
1767
1742
class FastBoolMatrix :public Matrix , public FastBoolVector {
1768
1743
public:
1769
1744
FastBoolMatrix (int colNum, int rowNum, int colCapacity, char * data, bool containNull):Matrix(colNum,rowNum),FastBoolVector(colNum*rowNum,colCapacity*rowNum,data,containNull){setForm (DF_MATRIX);}
@@ -2423,9 +2398,18 @@ class StringVector: public AbstractStringVector{
2423
2398
virtual bool getString (INDEX start, int len, char ** buf) const ;
2424
2399
virtual std::string** getStringConst (INDEX start, int len, std::string** buf) const ;
2425
2400
virtual char ** getStringConst (INDEX start, int len, char ** buf) const ;
2426
- virtual void setString (const std::string& val){data_[0 ]=val;}
2427
- virtual void setString (INDEX index, const std::string& val){data_[index]=val;}
2401
+ virtual void setString (const std::string& val){
2402
+ checkString (val);
2403
+ data_[0 ]=val;
2404
+ }
2405
+ virtual void setString (INDEX index, const std::string& val){
2406
+ checkString (val);
2407
+ data_[index]=val;
2408
+ }
2428
2409
virtual bool setString (INDEX start, int len, const std::string* buf){
2410
+ for (int i = 0 ; i < len; ++i){
2411
+ checkString (*(buf+i));
2412
+ }
2429
2413
copy (buf,buf+len,data_.begin ()+start);
2430
2414
return true ;
2431
2415
}
@@ -2471,6 +2455,9 @@ class StringVector: public AbstractStringVector{
2471
2455
return end;
2472
2456
}
2473
2457
2458
+ private:
2459
+ void checkString (const std::string& val);
2460
+
2474
2461
private:
2475
2462
mutable std::vector<std::string> data_;
2476
2463
bool blob_;
@@ -2538,7 +2525,7 @@ class FastFixedLengthVector : public Vector {
2538
2525
virtual void neg (){throw IncompatibleTypeException (DT_DOUBLE,type_);}
2539
2526
2540
2527
protected:
2541
- bool checkCapacity (int appendSize);
2528
+ void checkCapacity (int appendSize);
2542
2529
ConstantSP retrieve (Vector* index) const ;
2543
2530
unsigned char * getDataArray (const Vector* indexVector, bool & hasNull) const ;
2544
2531
unsigned char ** getSegmentDataArray (const Vector* indexVector, bool & hasNull) const ;
@@ -2660,8 +2647,7 @@ class FastInt128Vector : public FastRecordVector<Guid, GuidHash> {
2660
2647
setBinary (index, fixedLength_, buf);
2661
2648
}
2662
2649
virtual bool appendString (std::string* strarray, int len) {
2663
- if (!checkCapacity (len))
2664
- return false ;
2650
+ checkCapacity (len);
2665
2651
bool haveNull = false ;
2666
2652
unsigned char *pdata = data_ + size_ * fixedLength_;
2667
2653
for (int i = 0 ; i < len; i++, strarray++, pdata += fixedLength_) {
@@ -2680,8 +2666,7 @@ class FastInt128Vector : public FastRecordVector<Guid, GuidHash> {
2680
2666
return true ;
2681
2667
}
2682
2668
virtual bool appendString (char ** buf, int len) {
2683
- if (!checkCapacity (len))
2684
- return false ;
2669
+ checkCapacity (len);
2685
2670
bool haveNull = false ;
2686
2671
unsigned char *pdata = data_ + size_ * fixedLength_;
2687
2672
for (int i = 0 ; i < len; i++, pdata += fixedLength_) {
@@ -2721,8 +2706,7 @@ class FastUuidVector : public FastInt128Vector {
2721
2706
setBinary (index, fixedLength_, buf);
2722
2707
}
2723
2708
virtual bool appendString (std::string* strarray, int len) {
2724
- if (!checkCapacity (len))
2725
- return false ;
2709
+ checkCapacity (len);
2726
2710
bool haveNull = false ;
2727
2711
unsigned char *pdata = data_ + size_ * fixedLength_;
2728
2712
for (int i = 0 ; i < len; i++, strarray++, pdata += fixedLength_) {
@@ -2741,8 +2725,7 @@ class FastUuidVector : public FastInt128Vector {
2741
2725
return true ;
2742
2726
}
2743
2727
virtual bool appendString (char ** buf, int len) {
2744
- if (!checkCapacity (len))
2745
- return false ;
2728
+ checkCapacity (len);
2746
2729
bool haveNull = false ;
2747
2730
unsigned char *pdata = data_ + size_ * fixedLength_;
2748
2731
for (int i = 0 ; i < len; i++, pdata += fixedLength_) {
@@ -2776,8 +2759,7 @@ class FastIPAddrVector : public FastInt128Vector {
2776
2759
setBinary (index, fixedLength_, buf);
2777
2760
}
2778
2761
virtual bool appendString (std::string* strarray, int len) {
2779
- if (!checkCapacity (len))
2780
- return false ;
2762
+ checkCapacity (len);
2781
2763
bool haveNull = false ;
2782
2764
unsigned char *pdata = data_ + size_ * fixedLength_;
2783
2765
for (int i = 0 ; i < len; i++, strarray++, pdata += fixedLength_) {
@@ -2796,8 +2778,7 @@ class FastIPAddrVector : public FastInt128Vector {
2796
2778
return true ;
2797
2779
}
2798
2780
virtual bool appendString (char ** buf, int len) {
2799
- if (!checkCapacity (len))
2800
- return false ;
2781
+ checkCapacity (len);
2801
2782
bool haveNull = false ;
2802
2783
unsigned char *pdata = data_ + size_ * fixedLength_;
2803
2784
for (int i = 0 ; i < len; i++, pdata += fixedLength_) {
@@ -2868,8 +2849,7 @@ class FastSymbolVector : public AbstractFastVector<int> {
2868
2849
return ConstantSP (new FastSymbolVector (base_, size_, capacity, data, false ));
2869
2850
}
2870
2851
virtual bool append (const ConstantSP& value, INDEX appendSize){
2871
- if (!checkCapacity (appendSize))
2872
- return false ;
2852
+ checkCapacity (appendSize);
2873
2853
2874
2854
if (appendSize==1 )
2875
2855
data_[size_] = base_->findAndInsert (value->getString (0 ));
@@ -2887,16 +2867,14 @@ class FastSymbolVector : public AbstractFastVector<int> {
2887
2867
return true ;
2888
2868
}
2889
2869
virtual bool appendString (std::string* buf, int len){
2890
- if (!checkCapacity (len))
2891
- return false ;
2870
+ checkCapacity (len);
2892
2871
for (int i=0 ;i<len;++i)
2893
2872
data_[size_+i] = base_->findAndInsert (buf[i]);
2894
2873
size_+=len;
2895
2874
return true ;
2896
2875
}
2897
2876
virtual bool appendString (char ** buf, int len){
2898
- if (!checkCapacity (len))
2899
- return false ;
2877
+ checkCapacity (len);
2900
2878
for (int i=0 ;i<len;++i)
2901
2879
data_[size_+i] = base_->findAndInsert (std::string (buf[i]));
2902
2880
size_+=len;
@@ -3942,10 +3920,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
3942
3920
return append (value, 0 , count);
3943
3921
}
3944
3922
bool append (const ConstantSP value, INDEX start, INDEX appendSize) override {
3945
- if (!this ->checkCapacity (appendSize)) {
3946
- return false ;
3947
- }
3948
-
3923
+ this ->checkCapacity (appendSize);
3949
3924
// fast path 1: append one element
3950
3925
if (appendSize == 1 || value->isScalar ())
3951
3926
{
@@ -3990,9 +3965,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
3990
3965
}
3991
3966
3992
3967
bool appendString (std::string *buf, int len) override {
3993
- if (!this ->checkCapacity (len)) {
3994
- return false ;
3995
- }
3968
+ this ->checkCapacity (len);
3996
3969
3997
3970
std::string errMsg;
3998
3971
for (int i = 0 ; i < len; ++i) {
@@ -4009,9 +3982,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
4009
3982
return true ;
4010
3983
}
4011
3984
bool appendString (char **buf, int len) override {
4012
- if (!this ->checkCapacity (len)) {
4013
- return false ;
4014
- }
3985
+ this ->checkCapacity (len);
4015
3986
4016
3987
std::string errMsg;
4017
3988
for (int i = 0 ; i < len; ++i) {
@@ -4029,9 +4000,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
4029
4000
}
4030
4001
bool appendBool (char * buf, int len) override
4031
4002
{
4032
- if (!this ->checkCapacity (len)) {
4033
- return false ;
4034
- }
4003
+ this ->checkCapacity (len);
4035
4004
for (int i = 0 ; i < len; ++i) {
4036
4005
decimal_util::valueToDecimalraw (buf[i], scale_, data_ + size_ + i);
4037
4006
if (!containNull_ && buf[i] == CHAR_MIN) {
@@ -4043,9 +4012,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
4043
4012
}
4044
4013
bool appendChar (char * buf, int len) override
4045
4014
{
4046
- if (!this ->checkCapacity (len)) {
4047
- return false ;
4048
- }
4015
+ this ->checkCapacity (len);
4049
4016
for (int i = 0 ; i < len; ++i) {
4050
4017
decimal_util::valueToDecimalraw (buf[i], scale_, data_ + size_ + i);
4051
4018
if (!containNull_ && buf[i] == CHAR_MIN) {
@@ -4057,9 +4024,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
4057
4024
}
4058
4025
bool appendDouble (double * buf, int len) override
4059
4026
{
4060
- if (!this ->checkCapacity (len)) {
4061
- return false ;
4062
- }
4027
+ this ->checkCapacity (len);
4063
4028
for (int i = 0 ; i < len; ++i) {
4064
4029
decimal_util::valueToDecimalraw (buf[i], scale_, data_ + size_ + i);
4065
4030
if (!containNull_ && buf[i] == DBL_NMIN) {
@@ -4071,9 +4036,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
4071
4036
}
4072
4037
bool appendFloat (float * buf, int len) override
4073
4038
{
4074
- if (!this ->checkCapacity (len)) {
4075
- return false ;
4076
- }
4039
+ this ->checkCapacity (len);
4077
4040
for (int i = 0 ; i < len; ++i) {
4078
4041
decimal_util::valueToDecimalraw (buf[i], scale_, data_ + size_ + i);
4079
4042
if (!containNull_ && buf[i] == FLT_NMIN) {
@@ -4085,9 +4048,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
4085
4048
}
4086
4049
bool appendInt (int * buf, int len) override
4087
4050
{
4088
- if (!this ->checkCapacity (len)) {
4089
- return false ;
4090
- }
4051
+ this ->checkCapacity (len);
4091
4052
for (int i = 0 ; i < len; ++i) {
4092
4053
decimal_util::valueToDecimalraw (buf[i], scale_, data_ + size_ + i);
4093
4054
if (!containNull_ && buf[i] == INT_MIN) {
@@ -4099,9 +4060,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
4099
4060
}
4100
4061
bool appendLong (long long * buf, int len) override
4101
4062
{
4102
- if (!this ->checkCapacity (len)) {
4103
- return false ;
4104
- }
4063
+ this ->checkCapacity (len);
4105
4064
for (int i = 0 ; i < len; ++i) {
4106
4065
decimal_util::valueToDecimalraw (buf[i], scale_, data_ + size_ + i);
4107
4066
if (!containNull_ && buf[i] == LLONG_MIN) {
@@ -4113,9 +4072,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
4113
4072
}
4114
4073
bool appendShort (short * buf, int len) override
4115
4074
{
4116
- if (!this ->checkCapacity (len)) {
4117
- return false ;
4118
- }
4075
+ this ->checkCapacity (len);
4119
4076
for (int i = 0 ; i < len; ++i) {
4120
4077
decimal_util::valueToDecimalraw (buf[i], scale_, data_ + size_ + i);
4121
4078
if (!containNull_ && buf[i] == SHRT_MIN) {
@@ -4298,9 +4255,7 @@ class FastDecimalVector : public AbstractFastVector<T> {
4298
4255
IO_ERR deserialize (DataInputStream *in, INDEX indexStart, INDEX targetNumElement,INDEX &numElement) override {
4299
4256
IO_ERR ret=OK;
4300
4257
INDEX end = indexStart + targetNumElement;
4301
- if (end > capacity_ && !this ->checkCapacity (end - size_)) {
4302
- return NOSPACE;
4303
- }
4258
+ this ->checkCapacity (end - size_);
4304
4259
4305
4260
INDEX i = indexStart;
4306
4261
size_t unitLength = sizeof (T);
0 commit comments