use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.
the class ArrayJoin method arrayJoin.
@UsedByGeneratedCode
public static Slice arrayJoin(MethodHandle castFunction, Object state, ConnectorSession session, Block arrayBlock, Slice delimiter, Slice nullReplacement) {
PageBuilder pageBuilder = (PageBuilder) state;
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
int numElements = arrayBlock.getPositionCount();
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
for (int i = 0; i < numElements; i++) {
if (arrayBlock.isNull(i)) {
if (nullReplacement != null) {
blockBuilder.writeBytes(nullReplacement, 0, nullReplacement.length());
} else {
continue;
}
} else {
try {
Slice slice = (Slice) castFunction.invokeExact(arrayBlock, i, session);
blockBuilder.writeBytes(slice, 0, slice.length());
} catch (Throwable throwable) {
// Restore pageBuilder into a consistent state
blockBuilder.closeEntry();
pageBuilder.declarePosition();
throw new PrestoException(GENERIC_INTERNAL_ERROR, "Error casting array element to VARCHAR", throwable);
}
}
if (i != numElements - 1) {
blockBuilder.writeBytes(delimiter, 0, delimiter.length());
}
}
blockBuilder.closeEntry();
pageBuilder.declarePosition();
return VARCHAR.getSlice(blockBuilder, blockBuilder.getPositionCount() - 1);
}
use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.
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 PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to DECIMAL(%s,%s)", json.toStringUtf8(), precision, scale), e);
}
}
use of io.prestosql.spi.annotation.UsedByGeneratedCode in project hetu-core by openlookeng.
the class DecimalOperators method multiplyLongLongLong.
@UsedByGeneratedCode
public static Slice multiplyLongLongLong(Slice a, Slice b) {
try {
Slice result = UnscaledDecimal128Arithmetic.multiply(a, b);
throwIfOverflows(result);
return result;
} catch (ArithmeticException e) {
throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, "Decimal overflow", e);
}
}
Aggregations