use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class ArrayConcatUtils method appendElement.
@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, Slice value) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
elementType.writeSlice(blockBuilder, value);
return blockBuilder.build();
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class RowToJsonCast method toJsonArray.
@UsedByGeneratedCode
public static Slice toJsonArray(List<JsonGeneratorWriter> fieldWriters, Block block) {
try {
SliceOutput output = new DynamicSliceOutput(40);
try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, output)) {
jsonGenerator.writeStartArray();
for (int i = 0; i < block.getPositionCount(); i++) {
fieldWriters.get(i).writeJsonValue(jsonGenerator, block, i);
}
jsonGenerator.writeEndArray();
}
return output.slice();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class RowToJsonCast method toJsonObject.
@UsedByGeneratedCode
public static Slice toJsonObject(List<String> fieldNames, List<JsonGeneratorWriter> fieldWriters, Block block) {
try {
SliceOutput output = new DynamicSliceOutput(40);
try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, output)) {
jsonGenerator.writeStartObject();
for (int i = 0; i < block.getPositionCount(); i++) {
jsonGenerator.writeFieldName(fieldNames.get(i));
fieldWriters.get(i).writeJsonValue(jsonGenerator, block, i);
}
jsonGenerator.writeEndObject();
}
return output.slice();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class DecimalCasts method varcharToLongDecimal.
@UsedByGeneratedCode
public static Int128 varcharToLongDecimal(Slice value, long precision, long scale, Int128 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 Int128.valueOf(result.unscaledValue());
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class MapElementAtFunction method elementAt.
@UsedByGeneratedCode
public static Object elementAt(Type valueType, Block map, boolean key) {
SingleMapBlock mapBlock = (SingleMapBlock) map;
int valuePosition = mapBlock.seekKeyExact(key);
if (valuePosition == -1) {
return null;
}
return readNativeValue(valueType, mapBlock, valuePosition);
}
Aggregations