@Override public Integer getMaxLength() { return type.isFixedWidth() ? byteSize : null; }
public static int estimateSize(int size, PDataType baseType) { if (baseType.isFixedWidth()) { return baseType.getByteSize() * size; } else { return size * ValueSchema.ESTIMATED_VARIABLE_LENGTH_SIZE; } }
private static int getExpressionByteCount(Expression e) { PDataType childType = e.getDataType(); if (childType != null && !childType.isFixedWidth()) { return 1; } else { // Write at least one null byte in the case of the child being null with a childType of null return childType == null || !childType.isFixedWidth() ? 1 : SchemaUtil.getFixedByteSize(e); } }
@Override public void appendAbsentValue() { if ((serializationVersion == PArrayDataType.IMMUTABLE_SERIALIZATION_VERSION || serializationVersion == PArrayDataType.IMMUTABLE_SERIALIZATION_V2) && !baseType.isFixedWidth()) { offsetPos.add(-byteStream.size()); nulls++; } else { throw new UnsupportedOperationException("Cannot represent an absent element"); } }
private static int estimatePartLength(int pos, Iterator<PColumn> iterator) { int length = 0; while (iterator.hasNext()) { PColumn column = iterator.next(); if (column.getDataType().isFixedWidth()) { length += SchemaUtil.getFixedByteSize(column); } else { length += 1; // SEPARATOR byte. } } return length; }
private boolean isLastPKVariableLength(PTable table) { List<PColumn> pkColumns = table.getPKColumns(); return !pkColumns.get(pkColumns.size()-1).getDataType().isFixedWidth(); }
/** * Estimate the byte size from the type length. For example, for char, byte size would be the same as length. For * decimal, byte size would have no correlation with the length. */ public Integer estimateByteSizeFromLength(Integer length) { if (isFixedWidth()) { return getByteSize(); } if (isArrayType()) { return null; } // If not fixed width, default to say the byte size is the same as length. return length; }
private LiteralExpression(Object value, PDataType type, byte[] byteValue, Determinism determinism) { this(value, type, byteValue, type == null || !type.isFixedWidth() ? null : type.getMaxLength(value), null, SortOrder.getDefault(), determinism); }
public int estimateByteSize(Object o) { if (isFixedWidth()) { return getByteSize(); } if (isArrayType()) { PhoenixArray array = (PhoenixArray)o; int noOfElements = array.numElements; int totalVarSize = 0; for (int i = 0; i < noOfElements; i++) { totalVarSize += array.estimateByteSize(i); } return totalVarSize; } // Non fixed width types must override this throw new UnsupportedOperationException(); }
public PhoenixArray(PhoenixArray pArr, Integer desiredMaxLength) { this.baseType = pArr.baseType; Object[] elements = (Object[])pArr.array; if (baseType.isFixedWidth()) { if (baseType.getByteSize() == null) { elements = coerceToNewLength(baseType, (Object[])pArr.array, desiredMaxLength); maxLength = desiredMaxLength; } } this.array = convertObjectArrayToPrimitiveArray(elements); this.numElements = elements.length; }
private Field(PDatum datum, boolean isNullable, int count, SortOrder sortOrder) { Preconditions.checkNotNull(sortOrder); this.type = datum.getDataType(); this.sortOrder = sortOrder; this.count = count; this.isNullable = isNullable; if (this.type != null && this.type.isFixedWidth() && this.type.getByteSize() == null) { if (datum.getMaxLength() != null) { this.byteSize = datum.getMaxLength(); } } }
public static BytesComparator getComparator(Field field) { return getComparator(field.getDataType().isFixedWidth(),field.getSortOrder()); } /**
private static int getTerminatorCount(RowKeySchema schema) { int nTerminators = 0; for (int i = 0; i < schema.getFieldCount(); i++) { Field field = schema.getField(i); // We won't have a terminator on the last PK column // unless it is variable length and exclusive, but // having the extra byte irregardless won't hurt anything if (!field.getDataType().isFixedWidth()) { nTerminators++; } } return nTerminators; }
public static boolean isRowKeyOrderOptimized(PDataType type, SortOrder sortOrder, byte[] buf, int offset, int length) { PDataType baseType = PDataType.fromTypeId(type.getSqlType() - PDataType.ARRAY_TYPE_BASE); return isRowKeyOrderOptimized(baseType.isFixedWidth(), sortOrder, buf, offset, length); }
public TrimFunction(List<Expression> children) throws SQLException { super(children); if (getStringExpression().getDataType().isFixedWidth()) { maxLength = getStringExpression().getMaxLength(); } }
public static int getFixedByteSize(PDatum e) { assert(e.getDataType().isFixedWidth()); Integer maxLength = e.getMaxLength(); return maxLength == null ? e.getDataType().getByteSize() : maxLength; }
private Integer getMaxLength(Expression expression) { PDataType type = expression.getDataType(); if (type.isFixedWidth() && type.getByteSize() != null) { return type.getByteSize(); } return expression.getMaxLength(); }
@Override public void write(DataOutput output) throws IOException { WritableUtils.writeVInt(output, (type.ordinal() + 1) * (this.isNullable ? -1 : 1)); WritableUtils.writeVInt(output, count * (sortOrder == SortOrder.ASC ? 1 : -1)); if (type.isFixedWidth() && type.getByteSize() == null) { WritableUtils.writeVInt(output, byteSize); } } }
public static int getArrayLength(ImmutableBytesWritable ptr, PDataType baseType, Integer maxLength) { byte[] bytes = ptr.get(); if (ptr.getLength() == 0) { return 0; } if (baseType.isFixedWidth()) { int elemLength = maxLength == null ? baseType.getByteSize() : maxLength; return (ptr.getLength() / elemLength); } // In case where the number of elements is greater than SHORT.MAX_VALUE we do negate the number of // elements. So it is always better to return the absolute value return (Bytes.toInt(bytes, (ptr.getOffset() + ptr.getLength() - (Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT)))); }
private static void testRealNumberComparison(PDataType type, Object[] a) { for (SortOrder sortOrder : SortOrder.values()) { int factor = (sortOrder == SortOrder.ASC ? 1 : -1); byte[] prev_b = null; Object prev_o = null; for (Object o : a) { byte[] b = type.toBytes(o, sortOrder); if (prev_b != null) { assertTrue("Compare of " + o + " with " + prev_o + " " + sortOrder + " failed.", ScanUtil.getComparator(type.isFixedWidth(), sortOrder).compare(prev_b, 0, prev_b.length, b, 0, b.length) * factor < 0); } prev_b = b; prev_o = o; } } }