public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualType, Integer actualMaxLength, Integer actualScale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier, boolean expectedRowKeyOrderOptimizable) { coerceBytes(ptr, o, actualType, actualMaxLength, actualScale, actualModifier, desiredMaxLength, desiredScale, expectedModifier); }
public final void coerceBytes(ImmutableBytesWritable ptr, PDataType actualType, SortOrder actualModifier, SortOrder expectedModifier) { coerceBytes(ptr, null, actualType, null, null, actualModifier, null, null, expectedModifier); }
public final void coerceBytes(ImmutableBytesWritable ptr, PDataType actualType, SortOrder actualModifier, SortOrder expectedModifier, Integer desiredMaxLength) { coerceBytes(ptr, null, actualType, null, null, actualModifier, desiredMaxLength, null, expectedModifier); }
@Override public String toString() { int maxToStringLen = 200; Expression firstChild = children.get(0); PDataType type = firstChild.getDataType(); StringBuilder buf = new StringBuilder(firstChild + " IN ("); for (ImmutableBytesPtr value : values) { ImmutableBytesWritable currValue = value; if (firstChild.getSortOrder() != null && !firstChild.getSortOrder().equals(SortOrder.getDefault())) { // if we have to invert the bytes create a new ImmutableBytesWritable so that the // original value is not changed currValue = new ImmutableBytesWritable(value); type.coerceBytes(currValue, type, firstChild.getSortOrder(), SortOrder.getDefault()); } buf.append(type.toStringLiteral(currValue, null)); buf.append(','); if (buf.length() >= maxToStringLen) { buf.append("... "); break; } } buf.setCharAt(buf.length()-1,')'); return buf.toString(); }
@Override public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualType, Integer actualMaxLength, Integer actualScale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) { if (o != null && actualType.equals(PVarchar.INSTANCE) && ((String)o).length() != ptr.getLength()) { throw newIllegalDataException("CHAR types may only contain single byte characters (" + o + ")"); } super.coerceBytes(ptr, o, actualType, actualMaxLength, actualScale, actualModifier, desiredMaxLength, desiredScale, expectedModifier); if (ptr.getLength() > 0 && desiredMaxLength != null && desiredMaxLength > ptr.getLength()) { pad(ptr, desiredMaxLength, expectedModifier); } }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { boolean evaluated = children.get(0).evaluate(tuple, ptr); if (evaluated && ptr.getLength() > 0) { return true; } if (evaluated || tuple.isImmutable()) { Expression secondChild = children.get(1); if (secondChild.evaluate(tuple, ptr)) { // Coerce the type of the second child to the type of the first child getDataType().coerceBytes(ptr, secondChild.getDataType(), secondChild.getSortOrder(), getSortOrder()); return true; } } return false; }
private void appendPKColumnValue(StringBuilder buf, byte[] range, Boolean isNull, int slotIndex, boolean changeViewIndexId) { if (Boolean.TRUE.equals(isNull)) { buf.append("null"); return; } if (Boolean.FALSE.equals(isNull)) { buf.append("not null"); return; } if (range.length == 0) { buf.append('*'); return; } ScanRanges scanRanges = context.getScanRanges(); PDataType type = scanRanges.getSchema().getField(slotIndex).getDataType(); SortOrder sortOrder = tableRef.getTable().getPKColumns().get(slotIndex).getSortOrder(); if (sortOrder == SortOrder.DESC) { buf.append('~'); ImmutableBytesWritable ptr = new ImmutableBytesWritable(range); type.coerceBytes(ptr, type, sortOrder, SortOrder.getDefault()); range = ptr.get(); } if (changeViewIndexId) { buf.append(getViewIndexValue(type, range).toString()); } else { Format formatter = context.getConnection().getFormatter(type); buf.append(type.toStringLiteral(range, formatter)); } }
protected void coerceBytes(ImmutableBytesWritable ptr, Expression arrayExpr, PDataType baseDataType, Expression otherExpr, PDataType otherExpressionType) { baseDataType.coerceBytes(ptr, null, otherExpressionType, otherExpr.getMaxLength(), otherExpr.getScale(), otherExpr.getSortOrder(), arrayExpr.getMaxLength(), arrayExpr.getScale(), arrayExpr.getSortOrder()); }
@Override public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType, Integer maxLength, Integer scale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) { if (ptr.getLength() > getByteSize()) { ptr.set(ptr.get(), ptr.getOffset(), getByteSize()); } super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength, desiredScale, expectedModifier); }
@Override public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType, Integer maxLength, Integer scale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) { // Decrease size of TIMESTAMP to size of DATE and continue coerce if (ptr.getLength() > getByteSize()) { ptr.set(ptr.get(), ptr.getOffset(), getByteSize()); } super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength, desiredScale, expectedModifier); }
@Override public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualType, Integer actualMaxLength, Integer actualScale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) { Preconditions.checkNotNull(actualModifier); Preconditions.checkNotNull(expectedModifier); if (ptr.getLength() == 0) { return; } if (this.isBytesComparableWith(actualType)) { // No coerce necessary if (actualModifier != expectedModifier || (actualType.isFixedWidth() && actualType.getByteSize() < this.getByteSize())) { byte[] b = new byte[this.getByteSize()]; System.arraycopy(ptr.get(), ptr.getOffset(), b, 0, actualType.getByteSize()); ptr.set(b); if (actualModifier != expectedModifier) { SortOrder.invert(b, 0, b, 0, b.length); } } return; } super.coerceBytes(ptr, o, actualType, actualMaxLength, actualScale, actualModifier, desiredMaxLength, desiredScale, expectedModifier); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getChildExpression().evaluate(tuple, ptr)) { return false; } if (ptr.getLength() == 0) { return true; } PDataType type = getDataType(); // FIXME: losing rowKeyOrderOptimizable here type.coerceBytes(ptr, type, getChildExpression().getSortOrder(), getSortOrder()); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { boolean evaluated = children.get(0).evaluate(tuple, ptr); if (evaluated) { // Will potentially evaluate to null without evaluating the second expression return true; } if (tuple.isImmutable()) {// True for the last time an evaluation is happening on the row Expression secondChild = children.get(1); if (secondChild.evaluate(tuple, ptr)) { // Coerce the type of the second child to the type of the first child getDataType().coerceBytes(ptr, null, secondChild.getDataType(), secondChild.getMaxLength(), secondChild.getScale(), secondChild.getSortOrder(), getMaxLength(), getScale(), getSortOrder()); return true; } } return false; }
private static void coerceDataValueToIndexValue(PColumn dataColumn, PColumn indexColumn, ImmutableBytesWritable ptr) { PDataType dataType = dataColumn.getDataType(); // TODO: push to RowKeySchema? SortOrder dataModifier = dataColumn.getSortOrder(); PDataType indexType = indexColumn.getDataType(); SortOrder indexModifier = indexColumn.getSortOrder(); // We know ordinal position will match pk position, because you cannot // alter an index table. indexType.coerceBytes(ptr, dataType, dataModifier, indexModifier); }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (getChild().evaluate(tuple, ptr)) { getDataType().coerceBytes(ptr, null, getChild().getDataType(), getChild().getMaxLength(), null, getChild().getSortOrder(), maxLength, null, getSortOrder(), rowKeyOrderOptimizable); return true; } return false; }
dataType.coerceBytes(ptr, dataType, pkColumns.get(index).getSortOrder(), SortOrder.getDefault()); Object actualObject = dataType.toObject(ptr); assertEquals(expectedObject, actualObject);
@Override public KeyRange getKeyRange(CompareOp op, Expression rhs) { KeyRange range = childPart.getKeyRange(op, rhs); byte[] lower = range.getLowerRange(); if (!range.lowerUnbound()) { ptr.set(lower); // Do the reverse translation so we can optimize out the coerce expression // For the actual type of the coerceBytes call, we use the node type instead of the rhs type, because // for IN, the rhs type will be VARBINARY and no coerce will be done in that case (and we need it to // be done). node.getChild().getDataType().coerceBytes(ptr, node.getDataType(), rhs.getSortOrder(), SortOrder.ASC); lower = ByteUtil.copyKeyBytesIfNecessary(ptr); } byte[] upper = range.getUpperRange(); if (!range.upperUnbound()) { ptr.set(upper); // Do the reverse translation so we can optimize out the coerce expression node.getChild().getDataType().coerceBytes(ptr, node.getDataType(), rhs.getSortOrder(), SortOrder.ASC); upper = ByteUtil.copyKeyBytesIfNecessary(ptr); } range = KeyRange.getKeyRange(lower, range.isLowerInclusive(), upper, range.isUpperInclusive()); return range; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { tuple.getKey(ptr); int offset = accessor.getOffset(ptr.get(), ptr.getOffset() + this.offset); // Null is represented in the last expression of a multi-part key // by the bytes not being present. int maxOffset = ptr.getOffset() + ptr.getLength(); if (offset < maxOffset) { byte[] buffer = ptr.get(); int byteSize = -1; // FIXME: fixedByteSize <= maxByteSize ? fixedByteSize : 0 required because HBase passes bogus keys to filter to position scan (HBASE-6562) if (fromType.isFixedWidth()) { Integer maxLength = getMaxLength(); byteSize = fromType.getByteSize() == null ? maxLength : fromType.getByteSize(); byteSize = byteSize <= maxOffset ? byteSize : 0; } int length = byteSize >= 0 ? byteSize : accessor.getLength(buffer, offset, maxOffset); // In the middle of the key, an empty variable length byte array represents null if (length > 0) { ptr.set(buffer,offset,length); type.coerceBytes(ptr, fromType, getSortOrder(), getSortOrder()); } else { ptr.set(ByteUtil.EMPTY_BYTE_ARRAY); } } else { ptr.set(ByteUtil.EMPTY_BYTE_ARRAY); } // Always return true because we're always able to evaluate a row key column return true; }
TYPE.coerceBytes(ptr, strExpression.getDataType(), strExpression.getSortOrder(), SortOrder.ASC);
getLHSExpr().getDataType().coerceBytes(ptr, null, getRHSExpr().getDataType(), getRHSExpr().getMaxLength(), getRHSExpr().getScale(), getRHSExpr().getSortOrder(), getLHSExpr().getMaxLength(), getLHSExpr().getScale(), getLHSExpr().getSortOrder(), isLHSRowKeyOrderOptimized);