public byte[] toBytes(Object object, PDataType baseType, SortOrder sortOrder, boolean rowKeyOrderOptimizable) { if (object == null) { throw new ConstraintViolationException(this + " may not be null"); } PhoenixArray arr = toPhoenixArray(object, baseType); int noOfElements = arr.numElements; if (noOfElements == 0) { return ByteUtil.EMPTY_BYTE_ARRAY; } TrustedByteArrayOutputStream byteStream = null; if (!baseType.isFixedWidth()) { Pair<Integer, Integer> nullsVsNullRepeationCounter = new Pair<>(); int size = estimateByteSize(object, nullsVsNullRepeationCounter, PDataType.fromTypeId((baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE))); size += ((2 * Bytes.SIZEOF_BYTE) + (noOfElements - nullsVsNullRepeationCounter.getFirst()) * Bytes.SIZEOF_BYTE) + (nullsVsNullRepeationCounter.getSecond() * 2 * Bytes.SIZEOF_BYTE); // Assume an offset array that fit into Short.MAX_VALUE. Also not considering nulls that could be > 255 // In both of these cases, finally an array copy would happen int capacity = noOfElements * Bytes.SIZEOF_SHORT; // Here the int for noofelements, byte for the version, int for the offsetarray position and 2 bytes for the // end seperator byteStream = new TrustedByteArrayOutputStream(size + capacity + Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT); } else { int elemLength = (arr.getMaxLength() == null ? baseType.getByteSize() : arr.getMaxLength()); int size = elemLength * noOfElements; // Here the int for noofelements, byte for the version byteStream = new TrustedByteArrayOutputStream(size); } DataOutputStream oStream = new DataOutputStream(byteStream); // Handles bit inversion also return createArrayBytes(byteStream, oStream, arr, noOfElements, baseType, sortOrder, rowKeyOrderOptimizable); }
maxLength = ((PhoenixArray)value).getMaxLength();
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getElementExpr().evaluate(tuple, ptr)) { return false; } Object element = getElementExpr().getDataType().toObject(ptr, getElementExpr().getSortOrder(), getElementExpr().getMaxLength(), getElementExpr().getScale()); if (!getLengthExpr().evaluate(tuple, ptr) || ptr.getLength() == 0) { return false; } int length = (Integer) getLengthExpr().getDataType().toObject(ptr, getLengthExpr().getSortOrder(), getLengthExpr().getMaxLength(), getLengthExpr().getScale()); if (length <= 0) { throw new IllegalArgumentException("Array length should be greater than 0"); } Object[] elements = new Object[length]; Arrays.fill(elements, element); PhoenixArray array = PDataType.instantiatePhoenixArray(getElementExpr().getDataType(), elements); //When max length of a char array is not the max length of the element passed in if (getElementExpr().getDataType().isFixedWidth() && getMaxLength() != null && getMaxLength() != array.getMaxLength()) { array = new PhoenixArray(array, getMaxLength()); } ptr.set(((PArrayDataType) getDataType()).toBytes(array, getElementExpr().getDataType(), getElementExpr().getSortOrder())); return true; }
public byte[] toBytes(Object object, PDataType baseType, SortOrder sortOrder, boolean rowKeyOrderOptimizable) { if (object == null) { throw new ConstraintViolationException(this + " may not be null"); } PhoenixArray arr = toPhoenixArray(object, baseType); int noOfElements = arr.numElements; if (noOfElements == 0) { return ByteUtil.EMPTY_BYTE_ARRAY; } TrustedByteArrayOutputStream byteStream = null; if (!baseType.isFixedWidth()) { Pair<Integer, Integer> nullsVsNullRepeationCounter = new Pair<>(); int size = estimateByteSize(object, nullsVsNullRepeationCounter, PDataType.fromTypeId((baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE))); size += ((2 * Bytes.SIZEOF_BYTE) + (noOfElements - nullsVsNullRepeationCounter.getFirst()) * Bytes.SIZEOF_BYTE) + (nullsVsNullRepeationCounter.getSecond() * 2 * Bytes.SIZEOF_BYTE); // Assume an offset array that fit into Short.MAX_VALUE. Also not considering nulls that could be > 255 // In both of these cases, finally an array copy would happen int capacity = noOfElements * Bytes.SIZEOF_SHORT; // Here the int for noofelements, byte for the version, int for the offsetarray position and 2 bytes for the // end seperator byteStream = new TrustedByteArrayOutputStream(size + capacity + Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT); } else { int elemLength = (arr.getMaxLength() == null ? baseType.getByteSize() : arr.getMaxLength()); int size = elemLength * noOfElements; // Here the int for noofelements, byte for the version byteStream = new TrustedByteArrayOutputStream(size); } DataOutputStream oStream = new DataOutputStream(byteStream); // Handles bit inversion also return createArrayBytes(byteStream, oStream, arr, noOfElements, baseType, sortOrder, rowKeyOrderOptimizable); }
public byte[] toBytes(Object object, PDataType baseType, SortOrder sortOrder, boolean rowKeyOrderOptimizable) { if (object == null) { throw new ConstraintViolationException(this + " may not be null"); } PhoenixArray arr = toPhoenixArray(object, baseType); int noOfElements = arr.numElements; if (noOfElements == 0) { return ByteUtil.EMPTY_BYTE_ARRAY; } TrustedByteArrayOutputStream byteStream = null; if (!baseType.isFixedWidth()) { Pair<Integer, Integer> nullsVsNullRepeationCounter = new Pair<>(); int size = estimateByteSize(object, nullsVsNullRepeationCounter, PDataType.fromTypeId((baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE))); size += ((2 * Bytes.SIZEOF_BYTE) + (noOfElements - nullsVsNullRepeationCounter.getFirst()) * Bytes.SIZEOF_BYTE) + (nullsVsNullRepeationCounter.getSecond() * 2 * Bytes.SIZEOF_BYTE); // Assume an offset array that fit into Short.MAX_VALUE. Also not considering nulls that could be > 255 // In both of these cases, finally an array copy would happen int capacity = noOfElements * Bytes.SIZEOF_SHORT; // Here the int for noofelements, byte for the version, int for the offsetarray position and 2 bytes for the // end seperator byteStream = new TrustedByteArrayOutputStream(size + capacity + Bytes.SIZEOF_INT + Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT); } else { int elemLength = (arr.getMaxLength() == null ? baseType.getByteSize() : arr.getMaxLength()); int size = elemLength * noOfElements; // Here the int for noofelements, byte for the version byteStream = new TrustedByteArrayOutputStream(size); } DataOutputStream oStream = new DataOutputStream(byteStream); // Handles bit inversion also return createArrayBytes(byteStream, oStream, arr, noOfElements, baseType, sortOrder, rowKeyOrderOptimizable); }
maxLength = ((PhoenixArray)value).getMaxLength();
maxLength = ((PhoenixArray)value).getMaxLength();
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getElementExpr().evaluate(tuple, ptr)) { return false; } Object element = getElementExpr().getDataType().toObject(ptr, getElementExpr().getSortOrder(), getElementExpr().getMaxLength(), getElementExpr().getScale()); if (!getLengthExpr().evaluate(tuple, ptr) || ptr.getLength() == 0) { return false; } int length = (Integer) getLengthExpr().getDataType().toObject(ptr, getLengthExpr().getSortOrder(), getLengthExpr().getMaxLength(), getLengthExpr().getScale()); if (length <= 0) { throw new IllegalArgumentException("Array length should be greater than 0"); } Object[] elements = new Object[length]; Arrays.fill(elements, element); PhoenixArray array = PDataType.instantiatePhoenixArray(getElementExpr().getDataType(), elements); //When max length of a char array is not the max length of the element passed in if (getElementExpr().getDataType().isFixedWidth() && getMaxLength() != null && getMaxLength() != array.getMaxLength()) { array = new PhoenixArray(array, getMaxLength()); } ptr.set(((PArrayDataType) getDataType()).toBytes(array, getElementExpr().getDataType(), getElementExpr().getSortOrder())); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { if (!getElementExpr().evaluate(tuple, ptr)) { return false; } Object element = getElementExpr().getDataType().toObject(ptr, getElementExpr().getSortOrder(), getElementExpr().getMaxLength(), getElementExpr().getScale()); if (!getLengthExpr().evaluate(tuple, ptr) || ptr.getLength() == 0) { return false; } int length = (Integer) getLengthExpr().getDataType().toObject(ptr, getLengthExpr().getSortOrder(), getLengthExpr().getMaxLength(), getLengthExpr().getScale()); if (length <= 0) { throw new IllegalArgumentException("Array length should be greater than 0"); } Object[] elements = new Object[length]; Arrays.fill(elements, element); PhoenixArray array = PDataType.instantiatePhoenixArray(getElementExpr().getDataType(), elements); //When max length of a char array is not the max length of the element passed in if (getElementExpr().getDataType().isFixedWidth() && getMaxLength() != null && getMaxLength() != array.getMaxLength()) { array = new PhoenixArray(array, getMaxLength()); } ptr.set(((PArrayDataType) getDataType()).toBytes(array, getElementExpr().getDataType(), getElementExpr().getSortOrder())); return true; }