private static boolean convertibleToDoubleWithCast(Type type) { return type instanceof DecimalType || DoubleType.DOUBLE.equals(type) || RealType.REAL.equals(type) || BigintType.BIGINT.equals(type) || IntegerType.INTEGER.equals(type) || SmallintType.SMALLINT.equals(type) || TinyintType.TINYINT.equals(type) || BooleanType.BOOLEAN.equals(type); } }
private boolean satisfiesCoercion(boolean allowCoercion, Type fromType, TypeSignature toTypeSignature) { if (allowCoercion) { return typeManager.canCoerce(fromType, typeManager.getType(toTypeSignature)); } else { return fromType.getTypeSignature().equals(toTypeSignature); } }
@Override public String getDisplayName() { if (length == UNBOUNDED_LENGTH) { return getTypeSignature().getBase(); } return getTypeSignature().toString(); }
@Override protected Type _deserialize(String value, DeserializationContext context) { return typeManager.getType(parseTypeSignature(value)); } }
protected static SqlDecimal decimal(String decimalString) { DecimalParseResult parseResult = Decimals.parseIncludeLeadingZerosInPrecision(decimalString); BigInteger unscaledValue; if (parseResult.getType().isShort()) { unscaledValue = BigInteger.valueOf((Long) parseResult.getObject()); } else { unscaledValue = Decimals.decodeUnscaledValue((Slice) parseResult.getObject()); } return new SqlDecimal(unscaledValue, parseResult.getType().getPrecision(), parseResult.getType().getScale()); }
@Override protected String formatOneLine() { return type.getTypeSignature().toString(); }
@Override protected Object getGreaterValue(Object value) { // time zone doesn't matter for ordering return packDateTimeWithZone(unpackMillisUtc((Long) value) + 10, getTimeZoneKeyForOffset(33)); } }
@Override protected void writeDecimalToBlock(BigDecimal decimal, BlockBuilder blockBuilder) { longDecimalType.writeSlice(blockBuilder, encodeScaledValue(decimal)); }
DecimalType(int precision, int scale, Class<?> javaType) { super(new TypeSignature(StandardTypes.DECIMAL, buildTypeParameters(precision, scale)), javaType); this.precision = precision; this.scale = scale; }
@Override public String toString() { return getTypeSignature().toString(); }
@Override public String getDisplayName() { return getTypeSignature().toString(); }
@Override public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters) { return getType(new TypeSignature(baseTypeName, typeParameters)); }
public static int byteCountWithoutTrailingSpace(Slice slice, int offset, int length, int codePointCount) { int truncatedLength = byteCount(slice, offset, length, codePointCount); return byteCountWithoutTrailingSpace(slice, offset, truncatedLength); }
public static DecimalType createDecimalType(int precision, int scale) { if (precision <= MAX_SHORT_PRECISION) { return new ShortDecimalType(precision, scale); } else { return new LongDecimalType(precision, scale); } }
@Override protected Type _deserialize(String value, DeserializationContext context) { return typeManager.getType(parseTypeSignature(value)); } }
@Override protected Object getGreaterValue(Object value) { // time zone doesn't matter for ordering return packDateTimeWithZone(unpackMillisUtc((Long) value) + 10, getTimeZoneKeyForOffset(33)); } }
@Override protected void writeDecimalToBlock(BigDecimal decimal, BlockBuilder blockBuilder) { LONG_DECIMAL_TYPE.writeSlice(blockBuilder, encodeScaledValue(decimal)); }
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 protected Type _deserialize(String value, DeserializationContext context) { return typeManager.getType(parseTypeSignature(value)); } }
@Override protected Type _deserialize(String value, DeserializationContext context) { return typeManager.getType(parseTypeSignature(value)); } }