use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class RoundFloorCeilExpressionsTest method testRoundDateExpression.
// Date Expression Tests
@Test
public void testRoundDateExpression() throws Exception {
LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
Expression roundDateExpression = RoundDateExpression.create(dateLiteral, TimeUnit.DAY);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
roundDateExpression.evaluate(null, ptr);
Object result = roundDateExpression.getDataType().toObject(ptr);
assertTrue(result instanceof Date);
Date resultDate = (Date) result;
assertEquals(DateUtil.parseDate("2012-01-02 00:00:00"), resultDate);
}
use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class GetSetByteBitFunctionTest method testSetByteExpression.
private void testSetByteExpression(Expression data, Expression offset, Expression newValue, byte[] expected) throws SQLException {
List<Expression> expressions = Lists.newArrayList(data, offset, newValue);
Expression setByteFunction = new SetByteFunction(expressions);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
setByteFunction.evaluate(null, ptr);
byte[] result = (byte[]) setByteFunction.getDataType().toObject(ptr, setByteFunction.getSortOrder());
assertArrayEquals(expected, result);
}
use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class GetSetByteBitFunctionTest method testSetBitExpression.
private void testSetBitExpression(Expression data, Expression offset, Expression newValue, byte[] expected) throws SQLException {
List<Expression> expressions = Lists.newArrayList(data, offset, newValue);
Expression setBitFunction = new SetBitFunction(expressions);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
setBitFunction.evaluate(null, ptr);
byte[] result = (byte[]) setBitFunction.getDataType().toObject(ptr, setBitFunction.getSortOrder());
assertArrayEquals(expected, result);
}
use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class TestTableRowkeyPair method testsRowsKeys.
private void testsRowsKeys(String aTable, String akey, String bTable, String bkey, int expectedSignum) throws IOException {
final ImmutableBytesWritable arowkey = new ImmutableBytesWritable(Bytes.toBytes(akey));
TableRowkeyPair pair1 = new TableRowkeyPair(aTable, arowkey);
ImmutableBytesWritable browkey = new ImmutableBytesWritable(Bytes.toBytes(bkey));
TableRowkeyPair pair2 = new TableRowkeyPair(bTable, browkey);
TableRowkeyPair.Comparator comparator = new TableRowkeyPair.Comparator();
try (ByteArrayOutputStream baosA = new ByteArrayOutputStream();
ByteArrayOutputStream baosB = new ByteArrayOutputStream()) {
pair1.write(new DataOutputStream(baosA));
pair2.write(new DataOutputStream(baosB));
Assert.assertEquals(expectedSignum, signum(pair1.compareTo(pair2)));
Assert.assertEquals(expectedSignum, signum(comparator.compare(baosA.toByteArray(), 0, baosA.size(), baosB.toByteArray(), 0, baosB.size())));
Assert.assertEquals(expectedSignum, -signum(comparator.compare(baosB.toByteArray(), 0, baosB.size(), baosA.toByteArray(), 0, baosA.size())));
}
}
use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class PDataTypeForArraysTest method testPositionSearchWithVarLengthArrayWithNullValue1.
@Test
public void testPositionSearchWithVarLengthArrayWithNullValue1() {
String[] strArr = new String[5];
strArr[0] = "abx";
strArr[1] = "ereref";
strArr[2] = "random";
strArr[3] = null;
strArr[4] = "ran";
PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
PArrayDataTypeDecoder.positionAtArrayElement(ptr, 2, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
int offset = ptr.getOffset();
int length = ptr.getLength();
byte[] bs = ptr.get();
byte[] res = new byte[length];
System.arraycopy(bs, offset, res, 0, length);
assertEquals("random", Bytes.toString(res));
}
Aggregations