if (incs[i] == null) {
incs[i] = new BigDecimal(0);
}
}
Tuple end = new VTuple(sortSpecs.length);
Column column;
for (int i = 0; i < last.size(); i++) {
column = sortSpecs[i].getSortKey();
switch (column.getDataType().getType()) {
case CHAR:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createChar((char) (range.getStart().get(i).asChar() + incs[i].longValue())));
} else {
end.put(i, DatumFactory.createChar((char) (last.get(i).asChar() + incs[i].longValue())));
}
break;
case BIT:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createBit(
(byte) (range.getStart().get(i).asByte() + incs[i].longValue())));
} else {
end.put(i, DatumFactory.createBit((byte) (last.get(i).asByte() + incs[i].longValue())));
}
break;
case INT2:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createInt2(
(short) (range.getStart().get(i).asInt2() + incs[i].longValue())));
} else {
end.put(i, DatumFactory.createInt2((short) (last.get(i).asInt2() + incs[i].longValue())));
}
break;
case INT4:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createInt4(
(int) (range.getStart().get(i).asInt4() + incs[i].longValue())));
} else {
if (sortSpecs[i].isAscending()) {
end.put(i, DatumFactory.createInt4((int) (last.get(i).asInt4() + incs[i].longValue())));
} else {
end.put(i, DatumFactory.createInt4((int) (last.get(i).asInt4() - incs[i].longValue())));
}
}
break;
case INT8:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createInt8(
range.getStart().get(i).asInt8() + incs[i].longValue()));
} else {
end.put(i, DatumFactory.createInt8(last.get(i).asInt8() + incs[i].longValue()));
}
break;
case FLOAT4:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createFloat4(
range.getStart().get(i).asFloat4() + incs[i].longValue()));
} else {
end.put(i, DatumFactory.createFloat4(last.get(i).asFloat4() + incs[i].longValue()));
}
break;
case FLOAT8:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createFloat8(
range.getStart().get(i).asFloat8() + incs[i].longValue()));
} else {
end.put(i, DatumFactory.createFloat8(last.get(i).asFloat8() + incs[i].longValue()));
}
break;
case TEXT:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createText(((char) (range.getStart().get(i).asChars().charAt(0)
+ incs[i].longValue())) + ""));
} else {
end.put(i, DatumFactory.createText(
((char) ((last.get(i) instanceof NullDatum ? '0': last.get(i).asChars().charAt(0)) + incs[i].longValue())) + ""));
}
break;
case DATE:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createDate((int) (range.getStart().get(i).asInt4() + incs[i].longValue())));
} else {
end.put(i, DatumFactory.createDate((int) (last.get(i).asInt4() + incs[i].longValue())));
}
break;
case TIME:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createTime(range.getStart().get(i).asInt8() + incs[i].longValue()));
} else {
end.put(i, DatumFactory.createTime(last.get(i).asInt8() + incs[i].longValue()));
}
break;
case TIMESTAMP:
if (overflowFlag[i]) {
end.put(i, DatumFactory.createTimeStampFromMillis(
range.getStart().get(i).asInt8() + incs[i].longValue()));
} else {
end.put(i, DatumFactory.createTimeStampFromMillis(last.get(i).asInt8() + incs[i].longValue()));
}
break;
case INET4:
byte[] ipBytes;
if (overflowFlag[i]) {
ipBytes = range.getStart().get(i).asByteArray();
assert ipBytes.length == 4;
end.put(i, DatumFactory.createInet4(ipBytes));
} else {
int lastVal = last.get(i).asInt4() + incs[i].intValue();
ipBytes = new byte[4];
Bytes.putInt(ipBytes, 0, lastVal);
end.put(i, DatumFactory.createInet4(ipBytes));
}
break;
default:
throw new UnsupportedOperationException(column.getDataType() + " is not supported yet");
}