public static Slice padSpaces(Slice slice, CharType charType) { requireNonNull(charType, "charType is null"); return padSpaces(slice, charType.getLength()); }
public static Slice truncateToLengthAndTrimSpaces(Slice slice, CharType charType) { requireNonNull(charType, "charType is null"); return truncateToLengthAndTrimSpaces(slice, charType.getLength()); }
private static Integer charOctetLength(Type type) { if (isVarcharType(type)) { return ((VarcharType) type).getLength().orElse(VarcharType.UNBOUNDED_LENGTH); } if (isCharType(type)) { return ((CharType) type).getLength(); } if (type.equals(VARBINARY)) { return Integer.MAX_VALUE; } return null; }
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; }
public static Slice charPartitionKey(String value, String name, Type columnType) { Slice partitionKey = trimTrailingSpaces(Slices.utf8Slice(value)); CharType charType = (CharType) columnType; if (SliceUtf8.countCodePoints(partitionKey) > charType.getLength()) { throw new PrestoException(HIVE_INVALID_PARTITION_VALUE, format("Invalid partition value '%s' for %s partition key: %s", value, columnType.toString(), name)); } return partitionKey; }
return ((CharType) type).getLength();
return ((CharType) 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; }
protected String toSqlType(Type type) { if (isVarcharType(type)) { VarcharType varcharType = (VarcharType) type; if (varcharType.isUnbounded()) { return "varchar"; } return "varchar(" + varcharType.getLengthSafe() + ")"; } if (type instanceof CharType) { if (((CharType) type).getLength() == CharType.MAX_LENGTH) { return "char"; } return "char(" + ((CharType) type).getLength() + ")"; } if (type instanceof DecimalType) { return format("decimal(%s, %s)", ((DecimalType) type).getPrecision(), ((DecimalType) type).getScale()); } String sqlType = SQL_TYPES.get(type); if (sqlType != null) { return sqlType; } throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName()); }
protected String toSqlType(Type type) { if (isVarcharType(type)) { VarcharType varcharType = (VarcharType) type; if (varcharType.isUnbounded()) { return "varchar"; } return "varchar(" + varcharType.getBoundedLength() + ")"; } if (type instanceof CharType) { if (((CharType) type).getLength() == CharType.MAX_LENGTH) { return "char"; } return "char(" + ((CharType) type).getLength() + ")"; } if (type instanceof DecimalType) { return format("decimal(%s, %s)", ((DecimalType) type).getPrecision(), ((DecimalType) type).getScale()); } String sqlType = SQL_TYPES.get(type); if (sqlType != null) { return sqlType; } throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName()); }
private boolean evaluateLikePredicate(LikePredicate node, Slice value, Regex regex) { if (type(node.getValue()) instanceof VarcharType) { return LikeFunctions.likeVarchar(value, regex); } Type type = type(node.getValue()); checkState(type instanceof CharType, "LIKE value is neither VARCHAR or CHAR"); return LikeFunctions.likeChar((long) ((CharType) type).getLength(), value, regex); }
private boolean evaluateLikePredicate(LikePredicate node, Slice value, Regex regex) { if (type(node.getValue()) instanceof VarcharType) { return LikeFunctions.likeVarchar(value, regex); } Type type = type(node.getValue()); checkState(type instanceof CharType, "LIKE value is neither VARCHAR or CHAR"); return LikeFunctions.likeChar((long) ((CharType) type).getLength(), value, regex); }
public static int getMaxCodePointCount(Type type) { if (isVarcharType(type)) { VarcharType varcharType = (VarcharType) type; return varcharType.isUnbounded() ? -1 : varcharType.getBoundedLength(); } if (isCharType(type)) { return ((CharType) type).getLength(); } if (isVarbinaryType(type)) { return -1; } throw new IllegalArgumentException("Unsupported encoding " + type.getDisplayName()); }
public static int getMaxCodePointCount(Type type) { if (isVarcharType(type)) { VarcharType varcharType = (VarcharType) type; return varcharType.isUnbounded() ? -1 : varcharType.getLengthSafe(); } if (isCharType(type)) { return ((CharType) type).getLength(); } if (isVarbinaryType(type)) { return -1; } throw new IllegalArgumentException("Unsupported encoding " + type.getDisplayName()); }
int charLength = charType.getLength(); return getPrimitiveWritableObjectInspector(getCharTypeInfo(charLength));
return ImmutableList.of(new OrcType(OrcTypeKind.CHAR, ((CharType) type).getLength()));
assertEquals(actualValue, padEnd((String) expectedValue, ((CharType) type).getLength(), ' '), "Wrong value for column " + testColumn.getName());
CharType charType = (CharType) type; HiveChar hiveChar = ((HiveCharObjectInspector) inspector).getPrimitiveJavaObject(object); type.writeSlice(builder, truncateToLengthAndTrimSpaces(Slices.utf8Slice(hiveChar.getValue()), charType.getLength())); return; case DATE: