private static boolean hasDataSize(Type type) { return isVarcharType(type) || isCharType(type); }
public static Slice truncateToLengthAndTrimSpaces(Slice slice, Type type) { requireNonNull(type, "type is null"); if (!isCharType(type)) { throw new IllegalArgumentException("type must be the instance of CharType"); } return truncateToLengthAndTrimSpaces(slice, CharType.class.cast(type)); }
public static Slice truncateToLengthAndTrimSpaces(Slice slice, int maxLength) { requireNonNull(slice, "slice is null"); if (maxLength < 0) { throw new IllegalArgumentException("Max length must be greater or equal than zero"); } return trimTrailingSpaces(truncateToLength(slice, maxLength)); }
public static Slice padSpaces(Slice slice, Type type) { requireNonNull(type, "type is null"); if (!isCharType(type)) { throw new IllegalArgumentException("type must be the instance of CharType"); } return padSpaces(slice, CharType.class.cast(type)); }
public static Slice truncateToLengthAndTrimSpaces(Slice slice, CharType charType) { requireNonNull(charType, "charType is null"); return truncateToLengthAndTrimSpaces(slice, charType.getLength()); }
public static Slice padSpaces(Slice slice, CharType charType) { requireNonNull(charType, "charType is null"); return padSpaces(slice, charType.getLength()); }
public static int computeTruncatedLength(Slice slice, int offset, int length, int maxCodePointCount, boolean isCharType) { if (isCharType) { // truncate the characters and then remove the trailing white spaces return byteCountWithoutTrailingSpace(slice, offset, length, maxCodePointCount); } if (maxCodePointCount >= 0 && length > maxCodePointCount) { return byteCount(slice, offset, length, maxCodePointCount); } return length; }
@LiteralParameters("x") @ScalarOperator(BETWEEN) @SqlType(StandardTypes.BOOLEAN) public static boolean between(@SqlType("char(x)") Slice value, @SqlType("char(x)") Slice min, @SqlType("char(x)") Slice max) { return compareChars(min, value) <= 0 && compareChars(value, max) <= 0; }
@ScalarOperator(OperatorType.CAST) @SqlType("char(y)") @LiteralParameters({"x", "y"}) public static Slice varcharToCharCast(@LiteralParameter("y") Long y, @SqlType("varchar(x)") Slice slice) { return truncateToLengthAndTrimSpaces(slice, y.intValue()); }
@ScalarOperator(OperatorType.CAST) @SqlType("varchar(y)") @LiteralParameters({"x", "y"}) public static Slice charToVarcharCast(@LiteralParameter("x") Long x, @LiteralParameter("y") Long y, @SqlType("char(x)") Slice slice) { if (x.intValue() <= y.intValue()) { return padSpaces(slice, x.intValue()); } return padSpaces(truncateToLength(slice, y.intValue()), y.intValue()); }
public static int byteCountWithoutTrailingSpace(Slice slice, int offset, int length, int codePointCount) { int truncatedLength = byteCount(slice, offset, length, codePointCount); return byteCountWithoutTrailingSpace(slice, offset, truncatedLength); }
@LiteralParameters("x") @ScalarOperator(BETWEEN) @SqlType(StandardTypes.BOOLEAN) public static boolean between(@SqlType("char(x)") Slice value, @SqlType("char(x)") Slice min, @SqlType("char(x)") Slice max) { return compareChars(min, value) <= 0 && compareChars(value, max) <= 0; }
public static Set<ColumnStatisticType> getSupportedColumnStatistics(Type type) { if (type.equals(BOOLEAN)) { return ImmutableSet.of(NUMBER_OF_NON_NULL_VALUES, NUMBER_OF_TRUE_VALUES); } if (isNumericType(type) || type.equals(DATE) || type.equals(TIMESTAMP)) { // TODO https://github.com/prestodb/presto/issues/7122 support non-legacy TIMESTAMP return ImmutableSet.of(MIN_VALUE, MAX_VALUE, NUMBER_OF_DISTINCT_VALUES, NUMBER_OF_NON_NULL_VALUES); } if (isVarcharType(type) || isCharType(type)) { // TODO Collect MIN,MAX once it is used by the optimizer return ImmutableSet.of(NUMBER_OF_NON_NULL_VALUES, NUMBER_OF_DISTINCT_VALUES, TOTAL_SIZE_IN_BYTES, MAX_VALUE_SIZE_IN_BYTES); } if (type.equals(VARBINARY)) { return ImmutableSet.of(NUMBER_OF_NON_NULL_VALUES, TOTAL_SIZE_IN_BYTES, MAX_VALUE_SIZE_IN_BYTES); } if (type instanceof ArrayType || type instanceof RowType || type instanceof MapType) { return ImmutableSet.of(); } // Throwing here to make sure this method is updated when a new type is added in Hive connector throw new IllegalArgumentException("Unsupported type: " + type); }
value = truncateToLength(value, type); if (isCharType(type)) { value = truncateToLengthAndTrimSpaces(value, type);
@ScalarOperator(OperatorType.CAST) @SqlType("char(y)") @LiteralParameters({"x", "y"}) public static Slice varcharToCharCast(@LiteralParameter("y") Long y, @SqlType("varchar(x)") Slice slice) { return truncateToLengthAndTrimSpaces(slice, y.intValue()); }
public static Re2JRegexp castToRegexp(int dfaStatesLimit, int dfaRetries, boolean padSpaces, long typeLength, Slice pattern) { try { if (padSpaces) { pattern = padSpaces(pattern, (int) typeLength); } return new Re2JRegexp(dfaStatesLimit, dfaRetries, pattern); } catch (Exception e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } } }
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; }
public static int computeTruncatedLength(Slice slice, int offset, int length, int maxCodePointCount, boolean isCharType) { if (isCharType) { // truncate the characters and then remove the trailing white spaces return byteCountWithoutTrailingSpace(slice, offset, length, maxCodePointCount); } if (maxCodePointCount >= 0 && length > maxCodePointCount) { return byteCount(slice, offset, length, maxCodePointCount); } return length; }
@Override public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) { Slice leftSlice = leftBlock.getSlice(leftPosition, 0, leftBlock.getSliceLength(leftPosition)); Slice rightSlice = rightBlock.getSlice(rightPosition, 0, rightBlock.getSliceLength(rightPosition)); return compareChars(leftSlice, rightSlice); }
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; }