@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getLHSExpr().evaluate(tuple, ptr)){ return false; boolean isLHSRowKeyOrderOptimized = PArrayDataType.isRowKeyOrderOptimized(getLHSExpr().getDataType(), getLHSExpr().getSortOrder(), ptr); SortOrder sortOrder = getRHSExpr().getSortOrder(); int actualLengthOfArray1 = Math.abs(PArrayDataType.getArrayLength(ptr, getLHSBaseType(), getLHSExpr().getMaxLength())); int lengthArray1 = ptr.getLength(); int offsetArray1 = ptr.getOffset(); byte[] array1Bytes = ptr.get(); if (!getRHSExpr().evaluate(tuple, ptr)) { return false; checkSizeCompatibility(ptr, sortOrder, getLHSExpr(), getLHSExpr().getDataType(), getRHSExpr(),getRHSExpr().getDataType()); getLHSExpr().getDataType().coerceBytes(ptr, null, getRHSExpr().getDataType(), getRHSExpr().getMaxLength(), getRHSExpr().getScale(), getRHSExpr().getSortOrder(), getLHSExpr().getMaxLength(), getLHSExpr().getScale(), getLHSExpr().getSortOrder(), isLHSRowKeyOrderOptimized); if (lengthArray1 == 0) { return true; return modifierFunction(ptr, lengthArray1, offsetArray1, array1Bytes, getLHSBaseType(), actualLengthOfArray1, getMaxLength(), getLHSExpr());
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); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getLHSExpr().evaluate(tuple, ptr)){ return false; boolean isLHSRowKeyOrderOptimized = PArrayDataType.isRowKeyOrderOptimized(getLHSExpr().getDataType(), getLHSExpr().getSortOrder(), ptr); SortOrder sortOrder = getRHSExpr().getSortOrder(); int actualLengthOfArray1 = Math.abs(PArrayDataType.getArrayLength(ptr, getLHSBaseType(), getLHSExpr().getMaxLength())); int lengthArray1 = ptr.getLength(); int offsetArray1 = ptr.getOffset(); byte[] array1Bytes = ptr.get(); if (!getRHSExpr().evaluate(tuple, ptr)) { return false; checkSizeCompatibility(ptr, sortOrder, getLHSExpr(), getLHSExpr().getDataType(), getRHSExpr(),getRHSExpr().getDataType()); getLHSExpr().getDataType().coerceBytes(ptr, null, getRHSExpr().getDataType(), getRHSExpr().getMaxLength(), getRHSExpr().getScale(), getRHSExpr().getSortOrder(), getLHSExpr().getMaxLength(), getLHSExpr().getScale(), getLHSExpr().getSortOrder(), isLHSRowKeyOrderOptimized); if (lengthArray1 == 0) { return true; return modifierFunction(ptr, lengthArray1, offsetArray1, array1Bytes, getLHSBaseType(), actualLengthOfArray1, getMaxLength(), getLHSExpr());
@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()); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getLHSExpr().evaluate(tuple, ptr)){ return false; boolean isLHSRowKeyOrderOptimized = PArrayDataType.isRowKeyOrderOptimized(getLHSExpr().getDataType(), getLHSExpr().getSortOrder(), ptr); SortOrder sortOrder = getRHSExpr().getSortOrder(); int actualLengthOfArray1 = Math.abs(PArrayDataType.getArrayLength(ptr, getLHSBaseType(), getLHSExpr().getMaxLength())); int lengthArray1 = ptr.getLength(); int offsetArray1 = ptr.getOffset(); byte[] array1Bytes = ptr.get(); if (!getRHSExpr().evaluate(tuple, ptr)) { return false; checkSizeCompatibility(ptr, sortOrder, getLHSExpr(), getLHSExpr().getDataType(), getRHSExpr(),getRHSExpr().getDataType()); getLHSExpr().getDataType().coerceBytes(ptr, null, getRHSExpr().getDataType(), getRHSExpr().getMaxLength(), getRHSExpr().getScale(), getRHSExpr().getSortOrder(), getLHSExpr().getMaxLength(), getLHSExpr().getScale(), getLHSExpr().getSortOrder(), isLHSRowKeyOrderOptimized); if (lengthArray1 == 0) { return true; return modifierFunction(ptr, lengthArray1, offsetArray1, array1Bytes, getLHSBaseType(), actualLengthOfArray1, getMaxLength(), getLHSExpr());
@Test public void testForCorrectSeparatorBytes1() 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.ASC, 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()); }
@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()); }
@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()); }
@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()); } }