ImmutableBytesWritable destValue = dest.getProjectedValue(); int origDestBitSetLen = dest.getBitSetLength(); destBitSet.clear(); destBitSet.or(destValue, origDestBitSetLen); ImmutableBytesWritable srcValue = null; int srcValueLen = 0; 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 + srcValueLen + destBitSetLen]; int o = Bytes.putBytes(merged, 0, destValue.get(), destValue.getOffset(), destValue.getLength() - origDestBitSetLen); o = Bytes.putBytes(merged, o, srcValue.get(), srcValue.getOffset(), srcValueLen); destBitSet.toBytes(merged, o); return useNewValueColumnQualifier ? new ProjectedValueTuple(dest, dest.getTimestamp(), merged, 0, merged.length, destBitSetLen) : new OldProjectedValueTuple(dest, dest.getTimestamp(), merged, 0, merged.length, destBitSetLen);
KeyValueSchema kvSchema = buildKeyValueSchema(getPColumns(table, columns)); ImmutableBytesWritable ptr = new ImmutableBytesWritable(value); ValueBitSet valueSet = ValueBitSet.newInstance(kvSchema); valueSet.clear(); valueSet.or(ptr); int maxOffset = ptr.getOffset() + ptr.getLength(); Boolean hasValue;
public static ValueBitSet newInstance(ValueSchema schema) { if (schema.getFieldCount() == schema.getMinNullable()) { return EMPTY_VALUE_BITSET; } return new ValueBitSet(schema); }
public void or(ImmutableBytesWritable ptr) { or(ptr, isVarLength() ? Bytes.SIZEOF_SHORT + 1 : Bytes.SIZEOF_SHORT); }
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; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { try { KeyValueSchema schema = getSchema(); TupleProjector.decodeProjectedValue(tuple, ptr); bitSet.clear(); bitSet.or(ptr); int maxOffset = ptr.getOffset() + ptr.getLength() - bitSet.getEstimatedLength(); schema.iterator(ptr, position, bitSet); Boolean hasValue = schema.next(ptr, position, maxOffset, bitSet); if (hasValue == null || !hasValue.booleanValue()) { ptr.set(ByteUtil.EMPTY_BYTE_ARRAY); return true; } } catch (IOException e) { return false; } return true; }
@Test public void testMaxSetBit() { int nFields = 19; int nRepeating = 1; int nNotNull = 2; KeyValueSchema schema = generateSchema(nFields, nRepeating, nNotNull); ValueBitSet valueSet = ValueBitSet.newInstance(schema); setValueBitSet(schema, valueSet); int length = valueSet.getEstimatedLength(); byte[] buf = new byte[length]; valueSet.toBytes(buf, 0); ValueBitSet copyValueSet = ValueBitSet.newInstance(schema); copyValueSet.or(new ImmutableBytesWritable(buf)); assertTrue(copyValueSet.getMaxSetBit() >= valueSet.getMaxSetBit()); }
public TupleProjector(KeyValueSchema schema, Expression[] expressions) { this.schema = schema; this.expressions = expressions; this.valueSet = ValueBitSet.newInstance(schema); }
int offset = 0; int index = 0; valueSet.clear(); int minNullableIndex = getMinNullable(); byte[] b = new byte[getEstimatedValueLength() + valueSet.getEstimatedLength()]; List<Field> fields = getFields(); if (expressions[index].evaluate(tuple, ptr) && ptr.getLength() > 0) { // Skip null values if (index >= minNullableIndex) { valueSet.set(index - minNullableIndex); b = ensureSize(b, offset, offset + valueSet.getEstimatedLength()); offset = valueSet.toBytes(b, offset);
@Override public void aggregate(Aggregator[] aggregators, Tuple result) { TupleUtil.getAggregateValue(result, ptr); tempValueSet.clear(); tempValueSet.or(ptr); int i = 0, maxOffset = ptr.getOffset() + ptr.getLength(); Boolean hasValue; schema.iterator(ptr); while ((hasValue=schema.next(ptr, i, maxOffset, tempValueSet)) != null) { if (hasValue) { aggregators[i].aggregate(result, ptr); } i++; } }
int nNotNull = 8; KeyValueSchema schema = generateSchema(nFields, nRepeating, nNotNull); ValueBitSet valueSet = ValueBitSet.newInstance(schema); assertEquals(Bytes.SIZEOF_SHORT, valueSet.getEstimatedLength()); setValueBitSet(schema, valueSet); assertEquals(Bytes.SIZEOF_SHORT + Bytes.SIZEOF_LONG * 3, valueSet.getEstimatedLength()); nNotNull = 2; schema = generateSchema(nFields, nRepeating, nNotNull); valueSet = ValueBitSet.newInstance(schema); assertEquals(Bytes.SIZEOF_SHORT, valueSet.getEstimatedLength()); setValueBitSet(schema, valueSet); assertEquals(Bytes.SIZEOF_SHORT, valueSet.getEstimatedLength()); nNotNull = 2; schema = generateSchema(nFields, nRepeating, nNotNull); valueSet = ValueBitSet.newInstance(schema); assertEquals(Bytes.SIZEOF_SHORT, valueSet.getEstimatedLength()); setValueBitSet(schema, valueSet); assertEquals(Bytes.SIZEOF_SHORT + Bytes.SIZEOF_LONG, valueSet.getEstimatedLength()); nNotNull = 19; schema = generateSchema(nFields, nRepeating, nNotNull); valueSet = ValueBitSet.newInstance(schema); assertEquals(0, valueSet.getEstimatedLength()); nNotNull = 0; schema = generateSchema(nFields, nRepeating, nNotNull);
public ProjectedValueTuple projectResults(Tuple tuple) { byte[] bytesValue = schema.toBytes(tuple, getExpressions(), valueSet, ptr); Cell base = tuple.getValue(0); return new ProjectedValueTuple(base.getRowArray(), base.getRowOffset(), base.getRowLength(), base.getTimestamp(), bytesValue, 0, bytesValue.length, valueSet.getEstimatedLength()); }
@Test public void testNullCount() { int nFields = 32; int nRepeating = 5; int nNotNull = 8; KeyValueSchema schema = generateSchema(nFields, nRepeating, nNotNull); ValueBitSet valueSet = ValueBitSet.newInstance(schema); setValueBitSet(schema, valueSet); // From beginning, not spanning longs assertEquals(5, valueSet.getNullCount(0, 10)); // From middle, not spanning longs assertEquals(5, valueSet.getNullCount(10, 10)); // From middle, spanning to middle of next long assertEquals(10, valueSet.getNullCount(64 - 5, 20)); // from end, not spanning longs assertEquals(5, valueSet.getNullCount(nFields*nRepeating-nNotNull-10, 10)); // from beginning, spanning long entirely into middle of next long assertEquals(64, valueSet.getNullCount(2, 128)); }
/** * @return Max serialization size */ public int getEstimatedLength() { if (schema == null) { return 0; } return Bytes.SIZEOF_SHORT + (isVarLength() ? (maxSetBit + BITS_PER_LONG) / BITS_PER_LONG * Bytes.SIZEOF_LONG : 0); }
private static void setValueBitSet(KeyValueSchema schema, ValueBitSet valueSet) { for (int i = 0; i < schema.getFieldCount() - schema.getMinNullable(); i++) { if ((i & 1) == 1) { valueSet.set(i); } } }
public boolean isNull(int position, ValueBitSet bitSet) { int nBit = position - getMinNullable(); return (nBit >= 0 && !bitSet.get(nBit)); }
private ProjectedValueTuple convertLhs(Tuple lhs) throws IOException { ProjectedValueTuple t; if (lhs instanceof ProjectedValueTuple) { t = (ProjectedValueTuple) lhs; } else { ImmutableBytesWritable ptr = getContext().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 t; } };
public KeyValueSchema getSchema() { if (this.schema == null) { this.schema = buildSchema(columns); this.bitSet = ValueBitSet.newInstance(schema); } return schema; }
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; }
int offset = 0; int index = 0; valueSet.clear(); int minNullableIndex = getMinNullable(); byte[] b = new byte[getEstimatedValueLength() + valueSet.getEstimatedLength()]; List<Field> fields = getFields(); if (expressions[index].evaluate(tuple, ptr) && ptr.getLength() > 0) { // Skip null values if (index >= minNullableIndex) { valueSet.set(index - minNullableIndex); b = ensureSize(b, offset, offset + valueSet.getEstimatedLength()); offset = valueSet.toBytes(b, offset);