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, long key) {
SingleMapBlock mapBlock = (SingleMapBlock) map;
int valuePosition = mapBlock.seekKeyExact(key);
if (valuePosition == -1) {
return null;
}
return readNativeValue(valueType, mapBlock, valuePosition);
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class JsonToArrayCast method toArray.
@UsedByGeneratedCode
public static Block toArray(ArrayType arrayType, BlockBuilderAppender arrayAppender, ConnectorSession connectorSession, Slice json) {
try (JsonParser jsonParser = createJsonParser(JSON_FACTORY, json)) {
jsonParser.nextToken();
if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
return null;
}
BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 1);
arrayAppender.append(jsonParser, blockBuilder);
if (jsonParser.nextToken() != null) {
throw new JsonCastException(format("Unexpected trailing token: %s", jsonParser.getText()));
}
return arrayType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1);
} catch (TrinoException | JsonCastException e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Cannot cast to %s. %s\n%s", arrayType, e.getMessage(), truncateIfNecessaryForErrorMessage(json)), e);
} catch (Exception e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Cannot cast to %s.\n%s", arrayType, truncateIfNecessaryForErrorMessage(json)), e);
}
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class JsonToMapCast method toMap.
@UsedByGeneratedCode
public static Block toMap(MapType mapType, BlockBuilderAppender mapAppender, ConnectorSession connectorSession, Slice json) {
try (JsonParser jsonParser = createJsonParser(JSON_FACTORY, json)) {
jsonParser.nextToken();
if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
return null;
}
BlockBuilder blockBuilder = mapType.createBlockBuilder(null, 1);
mapAppender.append(jsonParser, blockBuilder);
if (jsonParser.nextToken() != null) {
throw new JsonCastException(format("Unexpected trailing token: %s", jsonParser.getText()));
}
return mapType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1);
} catch (TrinoException | JsonCastException e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Cannot cast to %s. %s\n%s", mapType, e.getMessage(), truncateIfNecessaryForErrorMessage(json)), e);
} catch (Exception e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, format("Cannot cast to %s.\n%s", mapType, truncateIfNecessaryForErrorMessage(json)), e);
}
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class ZipFunction method zip.
@UsedByGeneratedCode
public static Block zip(List<Type> types, Block... arrays) {
int biggestCardinality = 0;
for (Block array : arrays) {
biggestCardinality = Math.max(biggestCardinality, array.getPositionCount());
}
RowType rowType = RowType.anonymous(types);
BlockBuilder outputBuilder = rowType.createBlockBuilder(null, biggestCardinality);
for (int outputPosition = 0; outputPosition < biggestCardinality; outputPosition++) {
BlockBuilder rowBuilder = outputBuilder.beginBlockEntry();
for (int fieldIndex = 0; fieldIndex < arrays.length; fieldIndex++) {
if (arrays[fieldIndex].getPositionCount() <= outputPosition) {
rowBuilder.appendNull();
} else {
types.get(fieldIndex).appendTo(arrays[fieldIndex], outputPosition, rowBuilder);
}
}
outputBuilder.closeEntry();
}
return outputBuilder.build();
}
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, Object key) {
SingleMapBlock mapBlock = (SingleMapBlock) map;
int valuePosition = mapBlock.seekKeyExact(key);
if (valuePosition == -1) {
return null;
}
return readNativeValue(valueType, mapBlock, valuePosition);
}
Aggregations