return cardinality;
}
public static TupleRange [] getPartitions(Schema schema, int partNum, TupleRange range) {
Tuple start = range.getStart();
Tuple end = range.getEnd();
Column col;
TupleRange [] partitioned = new TupleRange[partNum];
Datum[] term = new Datum[schema.getColumnNum()];
Datum[] prevValues = new Datum[schema.getColumnNum()];
// initialize term and previous values
for (int i = 0; i < schema.getColumnNum(); i++) {
col = schema.getColumn(i);
prevValues[i] = start.get(i);
switch (col.getDataType().getType()) {
case CHAR:
int sChar = start.get(i).asChar();
int eChar = end.get(i).asChar();
int rangeChar;
if ((eChar - sChar) > partNum) {
rangeChar = (eChar - sChar) / partNum;
} else {
rangeChar = 1;
}
term[i] = DatumFactory.createInt4(rangeChar);
case BIT:
byte sByte = start.get(i).asByte();
byte eByte = end.get(i).asByte();
int rangeByte;
if ((eByte - sByte) > partNum) {
rangeByte = (eByte - sByte) / partNum;
} else {
rangeByte = 1;
}
term[i] = DatumFactory.createBit((byte) rangeByte);
break;
case INT2:
short sShort = start.get(i).asInt2();
short eShort = end.get(i).asInt2();
int rangeShort;
if ((eShort - sShort) > partNum) {
rangeShort = (eShort - sShort) / partNum;
} else {
rangeShort = 1;
}
term[i] = DatumFactory.createInt2((short) rangeShort);
break;
case INT4:
int sInt = start.get(i).asInt4();
int eInt = end.get(i).asInt4();
int rangeInt;
if ((eInt - sInt) > partNum) {
rangeInt = (eInt - sInt) / partNum;
} else {
rangeInt = 1;
}
term[i] = DatumFactory.createInt4(rangeInt);
break;
case INT8:
long sLong = start.get(i).asInt8();
long eLong = end.get(i).asInt8();
long rangeLong;
if ((eLong - sLong) > partNum) {
rangeLong = ((eLong - sLong) / partNum);
} else {
rangeLong = 1;
}
term[i] = DatumFactory.createInt8(rangeLong);
break;
case FLOAT4:
float sFloat = start.get(i).asFloat4();
float eFloat = end.get(i).asFloat4();
float rangeFloat;
if ((eFloat - sFloat) > partNum) {
rangeFloat = ((eFloat - sFloat) / partNum);
} else {
rangeFloat = 1;
}
term[i] = DatumFactory.createFloat4(rangeFloat);
break;
case FLOAT8:
double sDouble = start.get(i).asFloat8();
double eDouble = end.get(i).asFloat8();
double rangeDouble;
if ((eDouble - sDouble) > partNum) {
rangeDouble = ((eDouble - sDouble) / partNum);
} else {
rangeDouble = 1;
}
term[i] = DatumFactory.createFloat8(rangeDouble);
break;
case TEXT:
char sChars = start.get(i).asChars().charAt(0);
char eChars = end.get(i).asChars().charAt(0);
int rangeString;
if ((eChars - sChars) > partNum) {
rangeString = ((eChars - sChars) / partNum);
} else {
rangeString = 1;
}
term[i] = DatumFactory.createText(((char) rangeString) + "");
break;
case INET4:
throw new UnsupportedOperationException();
case BLOB:
throw new UnsupportedOperationException();
default:
throw new UnsupportedOperationException();
}
}
for (int p = 0; p < partNum; p++) {
Tuple sTuple = new VTuple(schema.getColumnNum());
Tuple eTuple = new VTuple(schema.getColumnNum());
for (int i = 0; i < schema.getColumnNum(); i++) {
col = schema.getColumn(i);
sTuple.put(i, prevValues[i]);
switch (col.getDataType().getType()) {
case CHAR:
char endChar = (char) (prevValues[i].asChar() + term[i].asChar());
if (endChar > end.get(i).asByte()) {
eTuple.put(i, end.get(i));
} else {
eTuple.put(i, DatumFactory.createChar(endChar));
}
prevValues[i] = DatumFactory.createChar(endChar);
break;
case BIT:
byte endByte = (byte) (prevValues[i].asByte() + term[i].asByte());
if (endByte > end.get(i).asByte()) {
eTuple.put(i, end.get(i));
} else {
eTuple.put(i, DatumFactory.createBit(endByte));
}
prevValues[i] = DatumFactory.createBit(endByte);
break;
case INT2:
int endShort = (short) (prevValues[i].asInt2() + term[i].asInt2());
if (endShort > end.get(i).asInt2()) {
eTuple.put(i, end.get(i));
} else {
// TODO - to consider overflow
eTuple.put(i, DatumFactory.createInt2((short) endShort));
}
prevValues[i] = DatumFactory.createInt2((short) endShort);
break;
case INT4:
int endInt = (prevValues[i].asInt4() + term[i].asInt4());
if (endInt > end.get(i).asInt4()) {
eTuple.put(i, end.get(i));
} else {
// TODO - to consider overflow
eTuple.put(i, DatumFactory.createInt4(endInt));
}
prevValues[i] = DatumFactory.createInt4(endInt);
break;
case INT8:
long endLong = (prevValues[i].asInt8() + term[i].asInt8());
if (endLong > end.get(i).asInt8()) {
eTuple.put(i, end.get(i));
} else {
// TODO - to consider overflow
eTuple.put(i, DatumFactory.createInt8(endLong));
}
prevValues[i] = DatumFactory.createInt8(endLong);
break;
case FLOAT4:
float endFloat = (prevValues[i].asFloat4() + term[i].asFloat4());
if (endFloat > end.get(i).asFloat4()) {
eTuple.put(i, end.get(i));
} else {
// TODO - to consider overflow
eTuple.put(i, DatumFactory.createFloat4(endFloat));
}
prevValues[i] = DatumFactory.createFloat4(endFloat);
break;
case FLOAT8:
double endDouble = (prevValues[i].asFloat8() + term[i].asFloat8());
if (endDouble > end.get(i).asFloat8()) {
eTuple.put(i, end.get(i));
} else {
// TODO - to consider overflow
eTuple.put(i, DatumFactory.createFloat8(endDouble));
}
prevValues[i] = DatumFactory.createFloat8(endDouble);
break;
case TEXT:
String endString = ((char)(prevValues[i].asChars().charAt(0) + term[i].asChars().charAt(0))) + "";
if (endString.charAt(0) > end.get(i).asChars().charAt(0)) {
eTuple.put(i, end.get(i));
} else {
// TODO - to consider overflow
eTuple.put(i, DatumFactory.createText(endString));
}
prevValues[i] = DatumFactory.createText(endString);
break;
case INET4:
throw new UnsupportedOperationException();