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 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; }
@Override public Slice getSlice(int field) { checkState(row != null, "No current row"); Column column = columns.get(field); if (column.getType().getBase() == ColumnType.Base.DECIMAL) { return (Slice) Decimals.parse(row.get(column.getPosition())).getObject(); } Slice characters = Slices.utf8Slice(row.get(columns.get(field).getPosition())); if (column.getType().getBase() == ColumnType.Base.CHAR) { characters = trimTrailingSpaces(characters); } return characters; }
@Description("remove the longest string containing only given characters from the beginning and end of a string") @ScalarFunction("trim") @LiteralParameters("x") @SqlType("char(x)") public static Slice charTrim(@SqlType("char(x)") Slice slice, @SqlType(CodePointsType.NAME) int[] codePointsToTrim) { return trimTrailingSpaces(trim(slice, codePointsToTrim)); }
@Description("remove the longest string containing only given characters from the end of a string") @ScalarFunction("rtrim") @LiteralParameters("x") @SqlType("char(x)") public static Slice charRightTrim(@SqlType("char(x)") Slice slice, @SqlType(CodePointsType.NAME) int[] codePointsToTrim) { return trimTrailingSpaces(rightTrim(slice, codePointsToTrim)); }
@Description("substring of given length starting at an index") @ScalarFunction("substr") @LiteralParameters("x") @SqlType("char(x)") public static Slice charSubstr(@SqlType("char(x)") Slice utf8, @SqlType(StandardTypes.BIGINT) long start, @SqlType(StandardTypes.BIGINT) long length) { return trimTrailingSpaces(substr(utf8, start, length)); }
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)); }
@Override public Slice getSlice(int field) { checkState(row != null, "No current row"); Column column = columns.get(field); if (column.getType().getBase() == ColumnType.Base.DECIMAL) { return (Slice) Decimals.parse(row.get(column.getPosition())).getObject(); } Slice characters = Slices.utf8Slice(row.get(columns.get(field).getPosition())); if (column.getType().getBase() == ColumnType.Base.CHAR) { characters = trimTrailingSpaces(characters); } return characters; }