use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class ArrayConcatUtils method prependElement.
@UsedByGeneratedCode
public static Block prependElement(Type elementType, double value, Block block) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
elementType.writeDouble(blockBuilder, value);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
return blockBuilder.build();
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class ArrayConcatUtils method prependElement.
@UsedByGeneratedCode
public static Block prependElement(Type elementType, Object value, Block block) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
elementType.writeObject(blockBuilder, value);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
return blockBuilder.build();
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class DecimalCasts method jsonToLongDecimal.
@UsedByGeneratedCode
public static Int128 jsonToLongDecimal(Slice json, long precision, long scale, Int128 tenToScale) {
try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
parser.nextToken();
Int128 result = currentTokenAsLongDecimal(parser, intPrecision(precision), DecimalConversions.intScale(scale));
// check no trailing token
checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to DECIMAL(%s,%s)", precision, scale);
return result;
} catch (IOException | NumberFormatException | JsonCastException e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to DECIMAL(%s,%s)", json.toStringUtf8(), precision, scale), e);
}
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class DecimalCasts method jsonToShortDecimal.
@UsedByGeneratedCode
public static Long jsonToShortDecimal(Slice json, long precision, long scale, long tenToScale) {
try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
parser.nextToken();
Long result = currentTokenAsShortDecimal(parser, intPrecision(precision), DecimalConversions.intScale(scale));
// check no trailing token
checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to DECIMAL(%s,%s)", precision, scale);
return result;
} catch (IOException | NumberFormatException | JsonCastException e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to DECIMAL(%s,%s)", json.toStringUtf8(), precision, scale), e);
}
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class DecimalCasts method varcharToShortDecimal.
@UsedByGeneratedCode
public static long varcharToShortDecimal(Slice value, long precision, long scale, long tenToScale) {
BigDecimal result;
String stringValue = value.toString(UTF_8);
try {
result = new BigDecimal(stringValue).setScale(DecimalConversions.intScale(scale), HALF_UP);
} catch (NumberFormatException e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value is not a number.", stringValue, precision, scale));
}
if (overflows(result, precision)) {
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value too large.", stringValue, precision, scale));
}
return result.unscaledValue().longValue();
}
Aggregations