public static ProjectedValueTuple mergeProjectedValue( ProjectedValueTuple dest, KeyValueSchema destSchema, ValueBitSet destBitSet, Tuple src, KeyValueSchema srcSchema, ValueBitSet srcBitSet, int offset) throws IOException { ImmutableBytesWritable destValue = new ImmutableBytesWritable(dest.getProjectedValue()); destBitSet.clear(); destBitSet.or(destValue); int origDestBitSetLen = dest.getBitSetLength(); ImmutableBytesWritable srcValue = new ImmutableBytesWritable(); decodeProjectedValue(src, srcValue); srcBitSet.clear(); srcBitSet.or(srcValue); int origSrcBitSetLen = srcBitSet.getEstimatedLength(); for (int i = 0; i < srcBitSet.getMaxSetBit(); i++) { if (srcBitSet.get(i)) { destBitSet.set(offset + i); } } int destBitSetLen = destBitSet.getEstimatedLength(); byte[] merged = new byte [destValue.getLength() - origDestBitSetLen + srcValue.getLength() - origSrcBitSetLen + destBitSetLen]; int o = Bytes.putBytes( merged, 0, destValue.get(), destValue.getOffset(), destValue.getLength() - origDestBitSetLen); o = Bytes.putBytes( merged, o, srcValue.get(), srcValue.getOffset(), srcValue.getLength() - origSrcBitSetLen); destBitSet.toBytes(merged, o); ImmutableBytesWritable keyPtr = dest.getKeyPtr(); return new ProjectedValueTuple( keyPtr.get(), keyPtr.getOffset(), keyPtr.getLength(), dest.getTimestamp(), merged, destBitSetLen); }
private Tuple join(Tuple lhs, Tuple rhs) throws SQLException { try { ProjectedValueTuple t = null; if (lhs == null) { t = new ProjectedValueTuple( rhs, rhs.getValue(0).getTimestamp(), this.emptyProjectedValue, 0, this.emptyProjectedValue.length, this.emptyProjectedValue.length); } else if (lhs instanceof ProjectedValueTuple) { t = (ProjectedValueTuple) lhs; } else { ImmutableBytesWritable ptr = context.getTempPtr(); TupleProjector.decodeProjectedValue(lhs, ptr); lhsBitSet.clear(); lhsBitSet.or(ptr); int bitSetLen = lhsBitSet.getEstimatedLength(); t = new ProjectedValueTuple( lhs, lhs.getValue(0).getTimestamp(), ptr.get(), ptr.getOffset(), ptr.getLength(), bitSetLen); } return rhsBitSet == ValueBitSet.EMPTY_VALUE_BITSET ? t : TupleProjector.mergeProjectedValue( t, joinedSchema, destBitSet, rhs, rhsSchema, rhsBitSet, rhsFieldPosition); } catch (IOException e) { throw new SQLException(e); } }