@Override public boolean next(ImmutableBytesWritable key, Result value) throws IOException { if (!delegate.nextKeyValue()) { return false; } ImmutableBytesWritable currentKey = delegate.getCurrentKey(); key.set(currentKey.get(), currentKey.getOffset(), currentKey.getLength()); value.copyFrom(delegate.getCurrentValue()); return true; }
ImmutableBytesWritable first = sorted.first(); if (writeMultipleTables) { first = new ImmutableBytesWritable(MultiTableHFileOutputFormat.getSuffix(sorted.first ().get())); + Bytes.toStringBinary(first.get()));
if (key == null) key = new ImmutableBytesWritable(); if (value == null) value = new Result(); try { key.set(value.getRow()); lastSuccessfulRow = key.get(); return true; key.set(value.getCursor().getRow()); lastSuccessfulRow = key.get(); return true;
private boolean isTenantRowCell(Cell cell) { ImmutableBytesWritable key = new ImmutableBytesWritable(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); //rows in system.catalog that aren't tenant-owned will have a leading separator byte return key.get()[key.getOffset()] != QueryConstants.SEPARATOR_BYTE; } }
@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) elementLiteral); expressions.add(arrayLiteral); Expression arrayPrependFunction = new ArrayPrependFunction(expressions); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); arrayPrependFunction.evaluate(null, ptr); byte[] expected = new byte[]{100, 0, 97, 0, 98, 0, 99, 0, 0, 0, -128, 1, -128, 3, -128, 5, -128, 7, 0, 0, 0, 10, 0, 0, 0, 4, 1}; assertArrayEquals(expected, ptr.get()); }
@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) elementLiteral); expressions.add(arrayLiteral); Expression arrayPrependFunction = new ArrayPrependFunction(expressions); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); arrayPrependFunction.evaluate(null, ptr); byte[] expected = new byte[]{-101, -1, -98, -1, -99, -1, -100, -1, -1, -1, -128, 1, -128, 3, -128, 5, -128, 7, 0, 0, 0, 10, 0, 0, 0, 4, 1}; assertArrayEquals(expected, ptr.get()); }
private void writeResult(ImmutableBytesWritable key, Result result, Context context) throws IOException, InterruptedException { Put put = null; Delete delete = null; if (LOG.isTraceEnabled()) { LOG.trace("Considering the row." + Bytes.toString(key.get(), key.getOffset(), key.getLength())); } if (filter == null || !filter.filterRowKey(PrivateCellUtil.createFirstOnRow(key.get(), key.getOffset(), (short) key.getLength()))) { processKV(key, result, context, put, delete); } }
@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()); }
/** * @param row The current table row key. * @param value The columns. * @param context The current context. * @throws IOException When something is broken with the data. */ @Override public void map(ImmutableBytesWritable row, Result value, Context context) throws IOException { try { if (LOG.isTraceEnabled()) { LOG.trace("Considering the row." + Bytes.toString(row.get(), row.getOffset(), row.getLength())); } if (filter == null || !filter.filterRowKey(PrivateCellUtil.createFirstOnRow(row.get(), row.getOffset(), (short) row.getLength()))) { for (Cell kv : value.rawCells()) { kv = filterKv(filter, kv); // skip if we filtered it out if (kv == null) continue; context.write(row, new MapReduceExtendedCell(convertKv(kv, cfRenameMap))); } } } catch (InterruptedException e) { LOG.error("Interrupted while emitting Cell", e); Thread.currentThread().interrupt(); } }
private static void assertEqualValue(Expression e, PDataType type, Object value) { ImmutableBytesWritable ptr = new ImmutableBytesWritable(); boolean evaluated = e.evaluate(null, ptr); assertTrue(evaluated); assertEquals(value, type.toObject(ptr.get())); CloneExpressionVisitor visitor = new CloneExpressionVisitor(); Expression clone = e.accept(visitor); evaluated = clone.evaluate(null, ptr); assertTrue(evaluated); assertEquals(value, type.toObject(ptr.get())); } }
/** * @param row The current table row key. * @param value The columns. * @param context The current context. * @throws IOException When something is broken with the data. */ @Override public void map(ImmutableBytesWritable row, Result value, Context context) throws IOException { try { if (LOG.isTraceEnabled()) { LOG.trace("Considering the row." + Bytes.toString(row.get(), row.getOffset(), row.getLength())); } if (filter == null || !filter.filterRowKey( PrivateCellUtil.createFirstOnRow(row.get(), row.getOffset(), (short) row.getLength()))) { for (Cell kv : value.rawCells()) { kv = filterKv(filter, kv); // skip if we filtered it out if (kv == null) continue; Cell ret = convertKv(kv, cfRenameMap); context.write(new CellWritableComparable(ret), ret); } } } catch (InterruptedException e) { LOG.error("Interrupted while emitting Cell", e); Thread.currentThread().interrupt(); } }
@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()); }