Search in sources :

Example 1 with ArrayAppendFunction

use of org.apache.phoenix.expression.function.ArrayAppendFunction in project phoenix by apache.

the class ArrayAppendFunctionTest method testForCorrectSeparatorBytes3.

@Test
public void testForCorrectSeparatorBytes3() throws Exception {
    Object[] o = new Object[] { "a", null, null, "c" };
    Object element = "d";
    PDataType baseType = PVarchar.INSTANCE;
    PhoenixArray arr = new PhoenixArray(baseType, o);
    LiteralExpression arrayLiteral, elementLiteral;
    arrayLiteral = LiteralExpression.newConstant(arr, PVarcharArray.INSTANCE, null, null, SortOrder.DESC, Determinism.ALWAYS);
    elementLiteral = LiteralExpression.newConstant(element, baseType, null, null, SortOrder.ASC, Determinism.ALWAYS);
    List<Expression> expressions = Lists.newArrayList((Expression) arrayLiteral);
    expressions.add(elementLiteral);
    Expression arrayAppendFunction = new ArrayAppendFunction(expressions);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    arrayAppendFunction.evaluate(null, ptr);
    byte[] expected = new byte[] { -98, -1, 0, -2, -100, -1, -101, -1, -1, -1, -128, 1, -128, 3, -128, 3, -128, 5, -128, 7, 0, 0, 0, 10, 0, 0, 0, 5, 1 };
    assertArrayEquals(expected, ptr.get());
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) ArrayAppendFunction(org.apache.phoenix.expression.function.ArrayAppendFunction) Test(org.junit.Test)

Example 2 with ArrayAppendFunction

use of org.apache.phoenix.expression.function.ArrayAppendFunction in project phoenix by apache.

the class ArrayAppendFunctionTest method testForCorrectSeparatorBytes2.

@Test
public void testForCorrectSeparatorBytes2() throws Exception {
    Object[] o = new Object[] { "a", "b", "c" };
    Object element = "d";
    PDataType baseType = PVarchar.INSTANCE;
    PhoenixArray arr = new PhoenixArray(baseType, o);
    LiteralExpression arrayLiteral, elementLiteral;
    arrayLiteral = LiteralExpression.newConstant(arr, PVarcharArray.INSTANCE, null, null, SortOrder.DESC, Determinism.ALWAYS);
    elementLiteral = LiteralExpression.newConstant(element, baseType, null, null, SortOrder.ASC, Determinism.ALWAYS);
    List<Expression> expressions = Lists.newArrayList((Expression) arrayLiteral);
    expressions.add(elementLiteral);
    Expression arrayAppendFunction = new ArrayAppendFunction(expressions);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    arrayAppendFunction.evaluate(null, ptr);
    byte[] expected = new byte[] { -98, -1, -99, -1, -100, -1, -101, -1, -1, -1, -128, 1, -128, 3, -128, 5, -128, 7, 0, 0, 0, 10, 0, 0, 0, 4, 1 };
    assertArrayEquals(expected, ptr.get());
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) ArrayAppendFunction(org.apache.phoenix.expression.function.ArrayAppendFunction) Test(org.junit.Test)

Example 3 with ArrayAppendFunction

use of org.apache.phoenix.expression.function.ArrayAppendFunction in project phoenix by apache.

the class ArrayAppendFunctionTest method testForCorrectSeparatorBytes1.

@Test
public void testForCorrectSeparatorBytes1() throws Exception {
    Object[] o = new Object[] { "a", "b", "c" };
    Object element = "d";
    PDataType baseType = PVarchar.INSTANCE;
    PhoenixArray arr = new PhoenixArray(baseType, o);
    LiteralExpression arrayLiteral, elementLiteral;
    arrayLiteral = LiteralExpression.newConstant(arr, PVarcharArray.INSTANCE, null, null, SortOrder.ASC, Determinism.ALWAYS);
    elementLiteral = LiteralExpression.newConstant(element, baseType, null, null, SortOrder.ASC, Determinism.ALWAYS);
    List<Expression> expressions = Lists.newArrayList((Expression) arrayLiteral);
    expressions.add(elementLiteral);
    Expression arrayAppendFunction = new ArrayAppendFunction(expressions);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    arrayAppendFunction.evaluate(null, ptr);
    byte[] expected = new byte[] { 97, 0, 98, 0, 99, 0, 100, 0, 0, 0, -128, 1, -128, 3, -128, 5, -128, 7, 0, 0, 0, 10, 0, 0, 0, 4, 1 };
    assertArrayEquals(expected, ptr.get());
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) ArrayAppendFunction(org.apache.phoenix.expression.function.ArrayAppendFunction) Test(org.junit.Test)

Example 4 with ArrayAppendFunction

use of org.apache.phoenix.expression.function.ArrayAppendFunction in project phoenix by apache.

the class ArrayAppendFunctionTest method testExpression.

private static void testExpression(LiteralExpression array, LiteralExpression element, PhoenixArray expected) throws SQLException {
    List<Expression> expressions = Lists.newArrayList((Expression) array);
    expressions.add(element);
    Expression arrayAppendFunction = new ArrayAppendFunction(expressions);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    arrayAppendFunction.evaluate(null, ptr);
    PhoenixArray result = (PhoenixArray) arrayAppendFunction.getDataType().toObject(ptr, expressions.get(0).getSortOrder(), array.getMaxLength(), array.getScale());
    assertTrue(result.equals(expected));
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) ArrayAppendFunction(org.apache.phoenix.expression.function.ArrayAppendFunction)

Aggregations

ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)4 ArrayAppendFunction (org.apache.phoenix.expression.function.ArrayAppendFunction)4 Test (org.junit.Test)3