use of org.apache.phoenix.expression.function.ArrayConcatFunction in project phoenix by apache.
the class ArrayConcatFunctionTest method testForCorrectSeparatorBytes4.
@Test
public void testForCorrectSeparatorBytes4() throws Exception {
Object[] o1 = new Object[] { "a", "b", null };
Object[] o2 = new Object[] { null, "c", "d", "e" };
PDataType type = PVarcharArray.INSTANCE;
PDataType base = PVarchar.INSTANCE;
PhoenixArray arr1 = new PhoenixArray(base, o1);
PhoenixArray arr2 = new PhoenixArray(base, o2);
LiteralExpression array1Literal, array2Literal;
array1Literal = LiteralExpression.newConstant(arr1, type, null, null, SortOrder.ASC, Determinism.ALWAYS);
array2Literal = LiteralExpression.newConstant(arr2, type, null, null, SortOrder.DESC, Determinism.ALWAYS);
List<Expression> expressions = Lists.newArrayList((Expression) array1Literal);
expressions.add(array2Literal);
Expression arrayConcatFunction = new ArrayConcatFunction(expressions);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
arrayConcatFunction.evaluate(null, ptr);
byte[] expected = new byte[] { 97, 0, 98, 0, 0, -2, 99, 0, 100, 0, 101, 0, 0, 0, -128, 1, -128, 3, -128, 5, -128, 5, -128, 7, -128, 9, -128, 11, 0, 0, 0, 14, 0, 0, 0, 7, 1 };
assertArrayEquals(expected, ptr.get());
}
use of org.apache.phoenix.expression.function.ArrayConcatFunction in project phoenix by apache.
the class ArrayConcatFunctionTest method testForCorrectSeparatorBytes2.
@Test
public void testForCorrectSeparatorBytes2() throws Exception {
Object[] o1 = new Object[] { "a", "b" };
Object[] o2 = new Object[] { "c", "d", "e" };
PDataType type = PVarcharArray.INSTANCE;
PDataType base = PVarchar.INSTANCE;
PhoenixArray arr1 = new PhoenixArray(base, o1);
PhoenixArray arr2 = new PhoenixArray(base, o2);
LiteralExpression array1Literal, array2Literal;
array1Literal = LiteralExpression.newConstant(arr1, type, null, null, SortOrder.ASC, Determinism.ALWAYS);
array2Literal = LiteralExpression.newConstant(arr2, type, null, null, SortOrder.DESC, Determinism.ALWAYS);
List<Expression> expressions = Lists.newArrayList((Expression) array1Literal);
expressions.add(array2Literal);
Expression arrayConcatFunction = new ArrayConcatFunction(expressions);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
arrayConcatFunction.evaluate(null, ptr);
byte[] expected = new byte[] { 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 0, 0, -128, 1, -128, 3, -128, 5, -128, 7, -128, 9, 0, 0, 0, 12, 0, 0, 0, 5, 1 };
assertArrayEquals(expected, ptr.get());
}
use of org.apache.phoenix.expression.function.ArrayConcatFunction in project phoenix by apache.
the class ArrayConcatFunctionTest method testForCorrectSeparatorBytes3.
@Test
public void testForCorrectSeparatorBytes3() throws Exception {
Object[] o1 = new Object[] { "a", "b" };
Object[] o2 = new Object[] { "c", "d", "e" };
PDataType type = PVarcharArray.INSTANCE;
PDataType base = PVarchar.INSTANCE;
PhoenixArray arr1 = new PhoenixArray(base, o1);
PhoenixArray arr2 = new PhoenixArray(base, o2);
LiteralExpression array1Literal, array2Literal;
array1Literal = LiteralExpression.newConstant(arr1, type, null, null, SortOrder.DESC, Determinism.ALWAYS);
array2Literal = LiteralExpression.newConstant(arr2, type, null, null, SortOrder.DESC, Determinism.ALWAYS);
List<Expression> expressions = Lists.newArrayList((Expression) array1Literal);
expressions.add(array2Literal);
Expression arrayConcatFunction = new ArrayConcatFunction(expressions);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
arrayConcatFunction.evaluate(null, ptr);
byte[] expected = new byte[] { -98, -1, -99, -1, -100, -1, -101, -1, -102, -1, -1, -1, -128, 1, -128, 3, -128, 5, -128, 7, -128, 9, 0, 0, 0, 12, 0, 0, 0, 5, 1 };
assertArrayEquals(expected, ptr.get());
}
use of org.apache.phoenix.expression.function.ArrayConcatFunction in project phoenix by apache.
the class ArrayConcatFunctionTest method testForCorrectSeparatorBytes5.
@Test
public void testForCorrectSeparatorBytes5() throws Exception {
Object[] o1 = new Object[] { "a", "b", null, null };
Object[] o2 = new Object[] { null, "c", "d", "e" };
PDataType type = PVarcharArray.INSTANCE;
PDataType base = PVarchar.INSTANCE;
PhoenixArray arr1 = new PhoenixArray(base, o1);
PhoenixArray arr2 = new PhoenixArray(base, o2);
LiteralExpression array1Literal, array2Literal;
array1Literal = LiteralExpression.newConstant(arr1, type, null, null, SortOrder.DESC, Determinism.ALWAYS);
array2Literal = LiteralExpression.newConstant(arr2, type, null, null, SortOrder.DESC, Determinism.ALWAYS);
List<Expression> expressions = Lists.newArrayList((Expression) array1Literal);
expressions.add(array2Literal);
Expression arrayConcatFunction = new ArrayConcatFunction(expressions);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
arrayConcatFunction.evaluate(null, ptr);
byte[] expected = new byte[] { -98, -1, -99, -1, 0, -3, -100, -1, -101, -1, -102, -1, -1, -1, -128, 1, -128, 3, -128, 5, -128, 5, -128, 5, -128, 7, -128, 9, -128, 11, 0, 0, 0, 14, 0, 0, 0, 8, 1 };
assertArrayEquals(expected, ptr.get());
}
use of org.apache.phoenix.expression.function.ArrayConcatFunction in project phoenix by apache.
the class ArrayConcatFunctionTest method testExpression.
private static void testExpression(LiteralExpression array1, LiteralExpression array2, PhoenixArray expected) throws SQLException {
List<Expression> expressions = Lists.newArrayList((Expression) array1);
expressions.add(array2);
Expression arrayConcatFunction = new ArrayConcatFunction(expressions);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
arrayConcatFunction.evaluate(null, ptr);
PhoenixArray result = (PhoenixArray) arrayConcatFunction.getDataType().toObject(ptr, expressions.get(0).getSortOrder(), array1.getMaxLength(), array1.getScale());
assertEquals(expected, result);
}
Aggregations