use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class SortOrderIT method testNonPKCompare.
@Test
public void testNonPKCompare() throws Exception {
List<Integer> expectedResults = Lists.newArrayList(2, 3, 4);
Integer[] saltBuckets = new Integer[] { null, 3 };
PDataType[] dataTypes = new PDataType[] { PDecimal.INSTANCE, PDouble.INSTANCE, PFloat.INSTANCE };
for (Integer saltBucket : saltBuckets) {
for (PDataType dataType : dataTypes) {
for (SortOrder sortOrder : SortOrder.values()) {
testCompareCompositeKey(saltBucket, dataType, sortOrder, "", expectedResults, "");
}
}
}
}
use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class RoundJodaDateExpression method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
if (children.get(0).evaluate(tuple, ptr)) {
if (ptr.getLength() == 0) {
// child evaluated to null
return true;
}
PDataType dataType = getDataType();
long time = dataType.getCodec().decodeLong(ptr, children.get(0).getSortOrder());
DateTime dt = new DateTime(time, ISOChronology.getInstanceUTC());
long value = roundDateTime(dt);
Date d = new Date(value);
byte[] byteValue = dataType.toBytes(d);
ptr.set(byteValue);
return true;
}
return false;
}
use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class TestUtil method in.
public static Expression in(Expression e, Object... literals) throws SQLException {
PDataType childType = e.getDataType();
List<Expression> expressions = new ArrayList<Expression>(literals.length + 1);
expressions.add(e);
for (Object o : literals) {
expressions.add(LiteralExpression.newConstant(o, childType));
}
return InListExpression.create(expressions, false, new ImmutableBytesWritable(), true);
}
use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class SecondFunction method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
Expression expression = getChildExpression();
if (!expression.evaluate(tuple, ptr)) {
return false;
}
if (ptr.getLength() == 0) {
//means null
return true;
}
long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
int sec = (int) ((dateTime / 1000) % 60);
PDataType returnType = getDataType();
byte[] byteValue = new byte[returnType.getByteSize()];
returnType.getCodec().encodeInt(sec, byteValue, 0);
ptr.set(byteValue);
return true;
}
use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class RoundTimestampExpression method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
if (children.get(0).evaluate(tuple, ptr)) {
SortOrder sortOrder = children.get(0).getSortOrder();
PDataType dataType = getDataType();
int nanos = dataType.getNanos(ptr, sortOrder);
if (nanos >= HALF_OF_NANOS_IN_MILLI) {
long timeMillis = dataType.getMillis(ptr, sortOrder);
Timestamp roundedTs = new Timestamp(timeMillis + 1);
byte[] byteValue = dataType.toBytes(roundedTs);
ptr.set(byteValue);
}
// for timestamp we only support rounding up the milliseconds.
return true;
}
return false;
}
Aggregations