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, CharType charType) { requireNonNull(charType, "charType is null"); return truncateToLengthAndTrimSpaces(slice, charType.getLength()); }
@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()); }
@Test public void testTruncateToLengthAndTrimSpaces() { assertEquals(utf8Slice("a"), truncateToLengthAndTrimSpaces(utf8Slice("a c"), 1)); assertEquals(utf8Slice("a"), truncateToLengthAndTrimSpaces(utf8Slice("a "), 1)); assertEquals(utf8Slice("a"), truncateToLengthAndTrimSpaces(utf8Slice("abc"), 1)); assertEquals(utf8Slice(""), truncateToLengthAndTrimSpaces(utf8Slice("a c"), 0)); assertEquals(utf8Slice("a c"), truncateToLengthAndTrimSpaces(utf8Slice("a c "), 3)); assertEquals(utf8Slice("a c"), truncateToLengthAndTrimSpaces(utf8Slice("a c "), 4)); assertEquals(utf8Slice("a c"), truncateToLengthAndTrimSpaces(utf8Slice("a c "), 5)); assertEquals(utf8Slice("a c"), truncateToLengthAndTrimSpaces(utf8Slice("a c"), 3)); assertEquals(utf8Slice("a c"), truncateToLengthAndTrimSpaces(utf8Slice("a c"), 4)); assertEquals(utf8Slice("a c"), truncateToLengthAndTrimSpaces(utf8Slice("a c"), 5)); assertEquals(utf8Slice(""), truncateToLengthAndTrimSpaces(utf8Slice(" "), 1)); assertEquals(utf8Slice(""), truncateToLengthAndTrimSpaces(utf8Slice(""), 1)); }
value = truncateToLengthAndTrimSpaces(value, type);
@Override protected void readValue(BlockBuilder blockBuilder, Type type) { if (definitionLevel == columnDescriptor.getMaxDefinitionLevel()) { Binary binary = valuesReader.readBytes(); Slice value; if (binary.length() == 0) { value = EMPTY_SLICE; } else { value = wrappedBuffer(binary.getBytes()); } if (isVarcharType(type)) { value = truncateToLength(value, type); } if (isCharType(type)) { value = truncateToLengthAndTrimSpaces(value, type); } type.writeSlice(blockBuilder, value); } else if (isValueNull()) { blockBuilder.appendNull(); } }
return createDomain(type, hasNullValue, columnStatistics.getStringStatistics(), value -> truncateToLengthAndTrimSpaces(value, type));
Slice slice = truncateToLengthAndTrimSpaces(utf8Slice((String) value), type); type.writeSlice(blockBuilder, slice);
CharType charType = (CharType) type; HiveChar hiveChar = ((HiveCharObjectInspector) inspector).getPrimitiveJavaObject(object); type.writeSlice(builder, truncateToLengthAndTrimSpaces(Slices.utf8Slice(hiveChar.getValue()), charType.getLength())); return; case DATE:
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, CharType charType) { requireNonNull(charType, "charType is null"); return truncateToLengthAndTrimSpaces(slice, charType.getLength()); }
private static Slice getSliceExpressedValue(Object value, Type type) { Slice sliceValue; if (value instanceof String) { sliceValue = Slices.utf8Slice((String) value); } else if (value instanceof byte[]) { sliceValue = Slices.wrappedBuffer((byte[]) value); } else if (value instanceof Integer) { sliceValue = Slices.utf8Slice(value.toString()); } else { throw new IllegalStateException("unsupported string field type: " + value.getClass().getName()); } if (isVarcharType(type)) { sliceValue = truncateToLength(sliceValue, type); } if (isCharType(type)) { sliceValue = truncateToLengthAndTrimSpaces(sliceValue, type); } return sliceValue; }
Slice slice = truncateToLengthAndTrimSpaces(utf8Slice((String) value), type); type.writeSlice(blockBuilder, slice);
return createDomain(type, hasNullValue, columnStatistics.getStringStatistics(), value -> truncateToLengthAndTrimSpaces(value, type));