Skip to content

Commit 810a5e9

Browse files
author
chengyitian
committed
AJ-706: support decimal vector combine method;
1 parent d4a63ad commit 810a5e9

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/com/xxdb/data/BasicDecimal128Vector.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,15 @@ public void setExtraParamForType(int scale){
231231

232232
@Override
233233
public Vector combine(Vector vector) {
234-
throw new RuntimeException("BasicDecimal128Vector not support combine yet!");
234+
BasicDecimal128Vector v = (BasicDecimal128Vector)vector;
235+
if (v.getScale() != this.scale_)
236+
throw new RuntimeException("The scale of the vector to be combine does not match the scale of the current vector.");
237+
int newSize = this.rows() + v.rows();
238+
BigInteger[] newValue = new BigInteger[newSize];
239+
System.arraycopy(this.unscaledValues,0, newValue,0,this.rows());
240+
System.arraycopy(v.unscaledValues,0, newValue,this.rows(),v.rows());
241+
242+
return new BasicDecimal128Vector(newValue, this.scale_);
235243
}
236244

237245
@Override

src/com/xxdb/data/BasicDecimal32Vector.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,15 @@ protected void writeVectorToOutputStream(ExtendedDataOutput out) throws IOExcept
151151

152152
@Override
153153
public Vector combine(Vector vector) {
154-
return null;
154+
BasicDecimal32Vector v = (BasicDecimal32Vector)vector;
155+
if (v.getScale() != this.scale_)
156+
throw new RuntimeException("The scale of the vector to be combine does not match the scale of the current vector.");
157+
int newSize = this.rows() + v.rows();
158+
int[] newValue = new int[newSize];
159+
System.arraycopy(this.unscaledValues,0, newValue,0,this.rows());
160+
System.arraycopy(v.unscaledValues,0, newValue,this.rows(),v.rows());
161+
162+
return new BasicDecimal32Vector(newValue, this.scale_);
155163
}
156164

157165
@Override

src/com/xxdb/data/BasicDecimal64Vector.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,15 @@ public void setExtraParamForType(int scale){
159159

160160
@Override
161161
public Vector combine(Vector vector) {
162-
return null;
162+
BasicDecimal64Vector v = (BasicDecimal64Vector)vector;
163+
if (v.getScale() != this.scale_)
164+
throw new RuntimeException("The scale of the vector to be combine does not match the scale of the current vector.");
165+
int newSize = this.rows() + v.rows();
166+
long[] newValue = new long[newSize];
167+
System.arraycopy(this.unscaledValues,0, newValue,0,this.rows());
168+
System.arraycopy(v.unscaledValues,0, newValue,this.rows(),v.rows());
169+
170+
return new BasicDecimal64Vector(newValue, this.scale_);
163171
}
164172

165173
@Override

0 commit comments

Comments
 (0)