@Override protected boolean modifierFunction(ImmutableBytesWritable ptr, int len, int offset, byte[] arrayBytes, PDataType baseDataType, int arrayLength, Integer maxLength, Expression arrayExp) { return PArrayDataType.appendItemToArray(ptr, len, offset, arrayBytes, baseDataType, arrayLength, getMaxLength(), arrayExp.getSortOrder()); }
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)); }
@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()); }
@Override protected boolean modifierFunction(ImmutableBytesWritable ptr, int len, int offset, byte[] arrayBytes, PDataType baseDataType, int arrayLength, Integer maxLength, Expression arrayExp) { return PArrayDataType.appendItemToArray(ptr, len, offset, arrayBytes, baseDataType, arrayLength, getMaxLength(), arrayExp.getSortOrder()); }
@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()); }
@Override protected boolean modifierFunction(ImmutableBytesWritable ptr, int len, int offset, byte[] arrayBytes, PDataType baseDataType, int arrayLength, Integer maxLength, Expression arrayExp) { return PArrayDataType.appendItemToArray(ptr, len, offset, arrayBytes, baseDataType, arrayLength, getMaxLength(), arrayExp.getSortOrder()); }
@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()); } }