public static Slice truncateToLength(Slice slice, VarcharType varcharType) { requireNonNull(varcharType, "varcharType is null"); return truncateToLength(slice, varcharType.getLength()); }
public static Slice varcharPartitionKey(String value, String name, Type columnType) { Slice partitionKey = Slices.utf8Slice(value); VarcharType varcharType = (VarcharType) columnType; if (SliceUtf8.countCodePoints(partitionKey) > varcharType.getLength()) { throw new PrestoException(HIVE_INVALID_PARTITION_VALUE, format("Invalid partition value '%s' for %s partition key: %s", value, columnType.toString(), name)); } return partitionKey; }
private static Integer charOctetLength(Type type) { if (isVarcharType(type)) { return ((VarcharType) type).getLength(); } if (isCharType(type)) { return ((CharType) type).getLength(); } if (type.equals(VARBINARY)) { return Integer.MAX_VALUE; } return null; }
return ((VarcharType) type).getLength();
public static int calculateTruncationLength(Type type, Slice slice, int offset, int length) { requireNonNull(type, "type is null"); if (type instanceof VarcharType) { return calculateTruncationLength(((VarcharType) type).getLength(), slice, offset, length); } if (type instanceof CharType) { int truncationLength = calculateTruncationLength(((CharType) type).getLength(), slice, offset, length); // At run-time char(x) is represented without trailing spaces while (truncationLength > 0 && slice.getByte(offset + truncationLength - 1) == ' ') { truncationLength--; } return truncationLength; } return length; }
int varcharLength = varcharType.getLength();
slice = constantSlice.slice(0, Math.min(((VarcharType) type).getLength(), constantSlice.length()));
int varcharLength = varcharType.getLength(); if (varcharLength <= HiveVarchar.MAX_VARCHAR_LENGTH) { return getVarcharTypeInfo(varcharLength);
public static Slice truncateToLength(Slice slice, VarcharType varcharType) { requireNonNull(varcharType, "varcharType is null"); return truncateToLength(slice, varcharType.getLength()); }
public static int calculateTruncationLength(Type type, Slice slice, int offset, int length) { requireNonNull(type, "type is null"); if (type instanceof VarcharType) { return calculateTruncationLength(((VarcharType) type).getLength(), slice, offset, length); } if (type instanceof CharType) { int truncationLength = calculateTruncationLength(((CharType) type).getLength(), slice, offset, length); // At run-time char(x) is represented without trailing spaces while (truncationLength > 0 && slice.getByte(offset + truncationLength - 1) == ' ') { truncationLength--; } return truncationLength; } return length; }
int length = SliceUtf8.countCodePoints(value); if (length == ((VarcharType) type).getLength()) { return new StringLiteral(value.toStringUtf8());