Search in sources :

Example 71 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class LikeExpressionTest method testExpression.

private boolean testExpression(String value, String expression, SortOrder sortorder) throws SQLException {
    LiteralExpression v = LiteralExpression.newConstant(value, PVarchar.INSTANCE, sortorder);
    LiteralExpression p = LiteralExpression.newConstant(expression, PVarchar.INSTANCE, sortorder);
    List<Expression> children = Arrays.<Expression>asList(v, p);
    LikeExpression e1 = ByteBasedLikeExpression.create(children, LikeType.CASE_SENSITIVE);
    LikeExpression e2 = StringBasedLikeExpression.create(children, LikeType.CASE_SENSITIVE);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    boolean evaluated1 = e1.evaluate(null, ptr);
    Boolean result1 = (Boolean) e1.getDataType().toObject(ptr);
    assertTrue(evaluated1);
    boolean evaluated2 = e2.evaluate(null, ptr);
    Boolean result2 = (Boolean) e2.getDataType().toObject(ptr);
    assertTrue(evaluated2);
    assertEquals(result1, result2);
    return result1;
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable)

Example 72 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class RegexpReplaceFunctionTest method evalExp.

private String evalExp(Expression exp) {
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    boolean eval = exp.evaluate(null, ptr);
    assertTrue(eval);
    String res = (String) exp.getDataType().toObject(ptr);
    return res;
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable)

Example 73 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class RegexpSplitFunctionTest method evalExp.

private String[] evalExp(Expression exp) throws SQLException {
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    boolean eval = exp.evaluate(null, ptr);
    assertTrue(eval);
    PhoenixArray evalRes = (PhoenixArray) exp.getDataType().toObject(ptr);
    String[] res = (String[]) evalRes.getArray();
    return res;
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray)

Example 74 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class RegexpSubstrFunctionTest method evalExp.

private String evalExp(Expression exp) {
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    boolean eval = exp.evaluate(null, ptr);
    assertTrue(eval);
    String res = (String) exp.getDataType().toObject(ptr);
    return res;
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable)

Example 75 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class RoundFloorCeilExpressionsTest method testCeilDateExpressionWithMultiplier.

@Test
public void testCeilDateExpressionWithMultiplier() throws Exception {
    Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
    Expression ceilDateExpression = CeilDateExpression.create(dateLiteral, TimeUnit.SECOND, 10);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    ceilDateExpression.evaluate(null, ptr);
    Object result = ceilDateExpression.getDataType().toObject(ptr);
    assertTrue(result instanceof Date);
    Date resultDate = (Date) result;
    assertEquals(DateUtil.parseDate("2012-01-01 14:25:30"), resultDate);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) RoundDecimalExpression(org.apache.phoenix.expression.function.RoundDecimalExpression) FloorDateExpression(org.apache.phoenix.expression.function.FloorDateExpression) CeilDateExpression(org.apache.phoenix.expression.function.CeilDateExpression) CeilDecimalExpression(org.apache.phoenix.expression.function.CeilDecimalExpression) FloorDecimalExpression(org.apache.phoenix.expression.function.FloorDecimalExpression) PDate(org.apache.phoenix.schema.types.PDate) Date(java.sql.Date) Test(org.junit.Test)

Aggregations

ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)296 Test (org.junit.Test)86 Expression (org.apache.phoenix.expression.Expression)36 IOException (java.io.IOException)33 PhoenixArray (org.apache.phoenix.schema.types.PhoenixArray)30 ArrayList (java.util.ArrayList)28 Configuration (org.apache.hadoop.conf.Configuration)28 Result (org.apache.hadoop.hbase.client.Result)28 Cell (org.apache.hadoop.hbase.Cell)27 KeyValue (org.apache.hadoop.hbase.KeyValue)27 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)27 PTable (org.apache.phoenix.schema.PTable)27 PDataType (org.apache.phoenix.schema.types.PDataType)26 PSmallint (org.apache.phoenix.schema.types.PSmallint)25 PTinyint (org.apache.phoenix.schema.types.PTinyint)23 Put (org.apache.hadoop.hbase.client.Put)20 PUnsignedSmallint (org.apache.phoenix.schema.types.PUnsignedSmallint)20 PUnsignedTinyint (org.apache.phoenix.schema.types.PUnsignedTinyint)20 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)19 List (java.util.List)18