本文整理汇总了Java中com.facebook.presto.spi.block.BlockBuilder.beginBlockEntry方法的典型用法代码示例。如果您正苦于以下问题:Java BlockBuilder.beginBlockEntry方法的具体用法?Java BlockBuilder.beginBlockEntry怎么用?Java BlockBuilder.beginBlockEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.presto.spi.block.BlockBuilder
的用法示例。
在下文中一共展示了BlockBuilder.beginBlockEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseAgent
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
@ScalarFunction("parse_agent")
@Description("Returns Map, which has keys such as 'category', 'name', 'os', 'version', 'vendor' and 'os_version'")
@SqlType("map<varchar,varchar>")
public Block parseAgent(@TypeParameter("map<varchar,varchar>") Type mapType, @SqlType(StandardTypes.VARCHAR) Slice slice) {
String argument = slice.toStringUtf8();
Map<String, String> stringMap = Classifier.parse(argument);
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
BlockBuilder singleMapBlockBuilder = blockBuilder.beginBlockEntry();
for (Map.Entry<String, String> entry : stringMap.entrySet()) {
VARCHAR.writeSlice(singleMapBlockBuilder, Slices.utf8Slice(entry.getKey()));
VARCHAR.writeSlice(singleMapBlockBuilder, Slices.utf8Slice(entry.getValue()));
}
blockBuilder.closeEntry();
pageBuilder.declarePosition();
return (Block) mapType.getObject(blockBuilder, blockBuilder.getPositionCount() - 1);
}
示例2: output
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
@OutputFunction("array<bigint>")
public static void output(DigestAndPercentileArrayState state, BlockBuilder out)
{
QuantileDigest digest = state.getDigest();
List<Double> percentiles = state.getPercentiles();
if (percentiles == null || digest == null) {
out.appendNull();
return;
}
BlockBuilder blockBuilder = out.beginBlockEntry();
for (int i = 0; i < percentiles.size(); i++) {
Double percentile = percentiles.get(i);
BIGINT.writeLong(blockBuilder, digest.getQuantile(percentile));
}
out.closeEntry();
}
示例3: output
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
public static void output(ArrayType outputType, MinMaxByNState state, BlockBuilder out)
{
TypedKeyValueHeap heap = state.getTypedKeyValueHeap();
if (heap == null || heap.isEmpty()) {
out.appendNull();
return;
}
Type elementType = outputType.getElementType();
BlockBuilder arrayBlockBuilder = out.beginBlockEntry();
BlockBuilder reversedBlockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), heap.getCapacity());
long startSize = heap.getEstimatedSize();
heap.popAll(reversedBlockBuilder);
state.addMemoryUsage(heap.getEstimatedSize() - startSize);
for (int i = reversedBlockBuilder.getPositionCount() - 1; i >= 0; i--) {
elementType.appendTo(reversedBlockBuilder, i, arrayBlockBuilder);
}
out.closeEntry();
}
示例4: output
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
@OutputFunction("array<double>")
public static void output(DigestAndPercentileArrayState state, BlockBuilder out)
{
QuantileDigest digest = state.getDigest();
List<Double> percentiles = state.getPercentiles();
if (percentiles == null || digest == null) {
out.appendNull();
return;
}
BlockBuilder blockBuilder = out.beginBlockEntry();
for (int i = 0; i < percentiles.size(); i++) {
Double percentile = percentiles.get(i);
DOUBLE.writeDouble(blockBuilder, sortableLongToDouble(digest.getQuantile(percentile)));
}
out.closeEntry();
}
示例5: serialize
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
@Override
public void serialize(MaxOrMinByState state, BlockBuilder out)
{
Block keyState = state.getKey();
Block valueState = state.getValue();
checkState((keyState == null) == (valueState == null), "(keyState == null) != (valueState == null)");
if (keyState == null) {
out.appendNull();
return;
}
BlockBuilder blockBuilder = out.beginBlockEntry();
keyType.appendTo(keyState, 0, blockBuilder);
valueType.appendTo(valueState, 0, blockBuilder);
out.closeEntry();
}
示例6: serialize
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
@Override
public void serialize(MinMaxNState state, BlockBuilder out)
{
TypedHeap heap = state.getTypedHeap();
if (heap == null) {
out.appendNull();
return;
}
BlockBuilder blockBuilder = out.beginBlockEntry();
BIGINT.writeLong(blockBuilder, heap.getCapacity());
BlockBuilder elements = blockBuilder.beginBlockEntry();
heap.writeAll(elements);
blockBuilder.closeEntry();
out.closeEntry();
}
示例7: output
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
public static void output(ArrayType outputType, MinMaxNState state, BlockBuilder out)
{
TypedHeap heap = state.getTypedHeap();
if (heap == null || heap.isEmpty()) {
out.appendNull();
return;
}
Type elementType = outputType.getElementType();
BlockBuilder reversedBlockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), heap.getCapacity());
long startSize = heap.getEstimatedSize();
heap.popAll(reversedBlockBuilder);
state.addMemoryUsage(heap.getEstimatedSize() - startSize);
BlockBuilder arrayBlockBuilder = out.beginBlockEntry();
for (int i = reversedBlockBuilder.getPositionCount() - 1; i >= 0; i--) {
elementType.appendTo(reversedBlockBuilder, i, arrayBlockBuilder);
}
out.closeEntry();
}
示例8: serialize
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
public void serialize(BlockBuilder out)
{
BlockBuilder blockBuilder = out.beginBlockEntry();
BIGINT.writeLong(blockBuilder, getCapacity());
BlockBuilder keyElements = blockBuilder.beginBlockEntry();
for (int i = 0; i < positionCount; i++) {
keyType.appendTo(keyBlockBuilder, heapIndex[i], keyElements);
}
blockBuilder.closeEntry();
BlockBuilder valueElements = blockBuilder.beginBlockEntry();
for (int i = 0; i < positionCount; i++) {
valueType.appendTo(valueBlockBuilder, heapIndex[i], valueElements);
}
blockBuilder.closeEntry();
out.closeEntry();
}
示例9: createLongArraysBlock
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
public Block createLongArraysBlock(Long[] values)
{
ArrayType arrayType = new ArrayType(BIGINT);
BlockBuilder blockBuilder = arrayType.createBlockBuilder(new BlockBuilderStatus(), values.length);
for (Long value : values) {
if (value == null) {
blockBuilder.appendNull();
}
else {
BlockBuilder elementBlockBuilder = blockBuilder.beginBlockEntry();
BIGINT.writeLong(elementBlockBuilder, value);
blockBuilder.closeEntry();
}
}
return blockBuilder.build();
}
示例10: createChannel
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
private static Block createChannel(int positionCount, int arraySize, ArrayType arrayType)
{
BlockBuilder blockBuilder = arrayType.createBlockBuilder(new BlockBuilderStatus(), positionCount);
for (int position = 0; position < positionCount; position++) {
BlockBuilder entryBuilder = blockBuilder.beginBlockEntry();
for (int i = 0; i < arraySize; i++) {
if (arrayType.getElementType().getJavaType() == long.class) {
arrayType.getElementType().writeLong(entryBuilder, ThreadLocalRandom.current().nextLong());
}
else if (arrayType.getElementType().equals(VARCHAR)) {
arrayType.getElementType().writeSlice(entryBuilder, Slices.utf8Slice("test_string"));
}
else {
throw new UnsupportedOperationException();
}
}
blockBuilder.closeEntry();
}
return blockBuilder.build();
}
示例11: serializeList
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
private static Block serializeList(Type type, BlockBuilder builder, Object object) {
List<?> list = (List) object;
if (list == null) {
requireNonNull(builder, "parent builder is null").appendNull();
return null;
}
List<Type> typeParameters = type.getTypeParameters();
checkArgument(typeParameters.size() == 1, "list must have exactly 1 type parameter");
Type elementType = typeParameters.get(0);
BlockBuilder currentBuilder;
if (builder != null) {
currentBuilder = builder.beginBlockEntry();
} else {
currentBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), list.size());
}
for (Object element : list) {
serializeObject(elementType, currentBuilder, element);
}
if (builder != null) {
builder.closeEntry();
return null;
} else {
Block resultBlock = currentBuilder.build();
return resultBlock;
}
}
示例12: serializeMap
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
private static Block serializeMap(Type type, BlockBuilder builder, Object object) {
Map<?, ?> map = (Map) object;
if (map == null) {
requireNonNull(builder, "parent builder is null").appendNull();
return null;
}
List<Type> typeParameters = type.getTypeParameters();
checkArgument(typeParameters.size() == 2, "map must have exactly 2 type parameter");
Type keyType = typeParameters.get(0);
Type valueType = typeParameters.get(1);
BlockBuilder currentBuilder;
if (builder != null) {
currentBuilder = builder.beginBlockEntry();
} else {
currentBuilder = new InterleavedBlockBuilder(typeParameters, new BlockBuilderStatus(), map.size());
}
for (Map.Entry<?, ?> entry : map.entrySet()) {
// Hive skips map entries with null keys
if (entry.getKey() != null) {
serializeObject(keyType, currentBuilder, entry.getKey());
serializeObject(valueType, currentBuilder, entry.getValue());
}
}
if (builder != null) {
builder.closeEntry();
return null;
} else {
Block resultBlock = currentBuilder.build();
return resultBlock;
}
}
示例13: createRLEBlock
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
private static RunLengthEncodedBlock createRLEBlock(Iterable<Double> percentiles, int positionCount)
{
BlockBuilder rleBlockBuilder = new ArrayType(DOUBLE).createBlockBuilder(new BlockBuilderStatus(), 1);
BlockBuilder arrayBlockBuilder = rleBlockBuilder.beginBlockEntry();
for (double percentile : percentiles) {
DOUBLE.writeDouble(arrayBlockBuilder, percentile);
}
rleBlockBuilder.closeEntry();
return new RunLengthEncodedBlock(rleBlockBuilder.build(), positionCount);
}
示例14: serializeList
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
private static Block serializeList(Type type, BlockBuilder builder, Object object, ListObjectInspector inspector)
{
List<?> list = inspector.getList(object);
if (list == null) {
requireNonNull(builder, "parent builder is null").appendNull();
return null;
}
List<Type> typeParameters = type.getTypeParameters();
checkArgument(typeParameters.size() == 1, "list must have exactly 1 type parameter");
Type elementType = typeParameters.get(0);
ObjectInspector elementInspector = inspector.getListElementObjectInspector();
BlockBuilder currentBuilder;
if (builder != null) {
currentBuilder = builder.beginBlockEntry();
}
else {
currentBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), list.size());
}
for (Object element : list) {
serializeObject(elementType, currentBuilder, element, elementInspector);
}
if (builder != null) {
builder.closeEntry();
return null;
}
else {
Block resultBlock = currentBuilder.build();
return resultBlock;
}
}
示例15: serializeMap
import com.facebook.presto.spi.block.BlockBuilder; //导入方法依赖的package包/类
private static Block serializeMap(Type type, BlockBuilder builder, Object object, MapObjectInspector inspector)
{
Map<?, ?> map = inspector.getMap(object);
if (map == null) {
requireNonNull(builder, "parent builder is null").appendNull();
return null;
}
List<Type> typeParameters = type.getTypeParameters();
checkArgument(typeParameters.size() == 2, "map must have exactly 2 type parameter");
Type keyType = typeParameters.get(0);
Type valueType = typeParameters.get(1);
ObjectInspector keyInspector = inspector.getMapKeyObjectInspector();
ObjectInspector valueInspector = inspector.getMapValueObjectInspector();
BlockBuilder currentBuilder;
if (builder != null) {
currentBuilder = builder.beginBlockEntry();
}
else {
currentBuilder = new InterleavedBlockBuilder(typeParameters, new BlockBuilderStatus(), map.size());
}
for (Map.Entry<?, ?> entry : map.entrySet()) {
// Hive skips map entries with null keys
if (entry.getKey() != null) {
serializeObject(keyType, currentBuilder, entry.getKey(), keyInspector);
serializeObject(valueType, currentBuilder, entry.getValue(), valueInspector);
}
}
if (builder != null) {
builder.closeEntry();
return null;
}
else {
Block resultBlock = currentBuilder.build();
return resultBlock;
}
}