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); }
public BasicJoinIterator(ResultIterator lhsIterator, ResultIterator rhsIterator) { this.lhsIterator = lhsIterator; this.rhsIterator = rhsIterator; this.initialized = false; this.lhsTuple = null; this.rhsTuple = null; this.lhsKey = new JoinKey(lhsKeyExpressions); this.rhsKey = new JoinKey(rhsKeyExpressions); this.nextLhsTuple = null; this.nextRhsTuple = null; this.nextLhsKey = new JoinKey(lhsKeyExpressions); this.nextRhsKey = new JoinKey(rhsKeyExpressions); this.destBitSet = ValueBitSet.newInstance(joinedSchema); this.lhsBitSet = ValueBitSet.newInstance(lhsSchema); this.rhsBitSet = ValueBitSet.newInstance(rhsSchema); lhsBitSet.clear(); int len = lhsBitSet.getEstimatedLength(); this.emptyProjectedValue = new byte[len]; lhsBitSet.toBytes(emptyProjectedValue, 0); this.queue = new MappedByteBufferTupleQueue(thresholdBytes); this.queueIterator = null; }
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); } }