本文整理汇总了Java中com.facebook.presto.spi.type.Type.createBlockBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java Type.createBlockBuilder方法的具体用法?Java Type.createBlockBuilder怎么用?Java Type.createBlockBuilder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.presto.spi.type.Type
的用法示例。
在下文中一共展示了Type.createBlockBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAlternatingNullsBlock
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public Block[] createAlternatingNullsBlock(List<Type> types, Block... sequenceBlocks)
{
Block[] alternatingNullsBlocks = new Block[sequenceBlocks.length];
for (int i = 0; i < sequenceBlocks.length; i++) {
int positionCount = sequenceBlocks[i].getPositionCount();
Type type = types.get(i);
BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), positionCount);
for (int position = 0; position < positionCount; position++) {
// append null
blockBuilder.appendNull();
// append value
type.appendTo(sequenceBlocks[i], position, blockBuilder);
}
alternatingNullsBlocks[i] = blockBuilder.build();
}
return alternatingNullsBlocks;
}
示例2: mapKeyToObject
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
private static Object mapKeyToObject(ConnectorSession session, String jsonKey, Type type)
{
BlockBuilder blockBuilder;
if (type instanceof FixedWidthType) {
blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), 1);
}
else {
blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), 1, jsonKey.length());
}
if (type.getJavaType() == boolean.class) {
type.writeBoolean(blockBuilder, Boolean.parseBoolean(jsonKey));
}
else if (type.getJavaType() == long.class) {
type.writeLong(blockBuilder, Long.parseLong(jsonKey));
}
else if (type.getJavaType() == double.class) {
type.writeDouble(blockBuilder, Double.parseDouble(jsonKey));
}
else if (type.getJavaType() == Slice.class) {
type.writeSlice(blockBuilder, Slices.utf8Slice(jsonKey));
}
return type.getObjectValue(session, blockBuilder.build(), 0);
}
示例3: output
import com.facebook.presto.spi.type.Type; //导入方法依赖的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: TypedSet
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public TypedSet(Type elementType, int expectedSize)
{
checkArgument(expectedSize > 0, "expectedSize must be > 0");
this.elementType = requireNonNull(elementType, "elementType must not be null");
this.elementBlock = elementType.createBlockBuilder(new BlockBuilderStatus(), expectedSize);
int hashSize = arraySize(expectedSize, FILL_RATIO);
this.maxFill = calculateMaxFill(hashSize);
this.hashMask = hashSize - 1;
blockPositionByHash.ensureCapacity(hashSize);
for (int i = 0; i < hashSize; i++) {
blockPositionByHash.set(i, EMPTY_SLOT);
}
this.containsNullElement = false;
}
示例5: distinct
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public static Block distinct(Type type, Block array)
{
if (array.getPositionCount() < 2) {
return array;
}
if (array.getPositionCount() == 2) {
if (type.equalTo(array, 0, array, 1)) {
return array.getSingleValueBlock(0);
}
else {
return array;
}
}
TypedSet typedSet = new TypedSet(type, array.getPositionCount());
BlockBuilder distinctElementBlockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), array.getPositionCount());
for (int i = 0; i < array.getPositionCount(); i++) {
if (!typedSet.contains(array, i)) {
typedSet.add(array, i);
type.appendTo(array, i, distinctElementBlockBuilder);
}
}
return distinctElementBlockBuilder.build();
}
示例6: createBlock
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
private static Block createBlock(Type type, Object value)
{
BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), 1);
Class<?> javaType = type.getJavaType();
if (value == null) {
blockBuilder.appendNull();
}
else if (javaType == boolean.class) {
type.writeBoolean(blockBuilder, (Boolean) value);
}
else if (javaType == long.class) {
type.writeLong(blockBuilder, (Long) value);
}
else if (javaType == double.class) {
type.writeDouble(blockBuilder, (Double) value);
}
else if (javaType == Slice.class) {
Slice slice = (Slice) value;
type.writeSlice(blockBuilder, slice, 0, slice.length());
}
else {
type.writeObject(blockBuilder, value);
}
return blockBuilder.build();
}
示例7: serializeList
import com.facebook.presto.spi.type.Type; //导入方法依赖的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;
}
}
示例8: createZeroBlock
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
private Block createZeroBlock(Type type, int rowsCount, Slice constantSlice)
{
checkArgument(SUPPORTED_TYPES.contains(type), "Unsupported type [%s]", type);
BlockBuilder builder;
if (type instanceof FixedWidthType) {
builder = type.createBlockBuilder(new BlockBuilderStatus(), rowsCount);
}
else {
builder = type.createBlockBuilder(new BlockBuilderStatus(), rowsCount, constantSlice.length());
}
for (int i = 0; i < rowsCount; i++) {
Class<?> javaType = type.getJavaType();
if (javaType == boolean.class) {
type.writeBoolean(builder, false);
}
else if (javaType == long.class) {
type.writeLong(builder, 0);
}
else if (javaType == double.class) {
type.writeDouble(builder, 0.0);
}
else if (javaType == Slice.class) {
type.writeSlice(builder, constantSlice, 0, constantSlice.length());
}
else {
throw new UnsupportedOperationException("Unknown javaType: " + javaType.getName());
}
}
return builder.build();
}
示例9: getKeys
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public static Block getKeys(Type keyType, Block block)
{
BlockBuilder blockBuilder = keyType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() / 2);
for (int i = 0; i < block.getPositionCount(); i += 2) {
keyType.appendTo(block, i, blockBuilder);
}
return blockBuilder.build();
}
示例10: prependElement
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
@UsedByGeneratedCode
public static Block prependElement(Type elementType, Object value, Block block)
{
BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() + 1);
elementType.writeObject(blockBuilder, value);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
return blockBuilder.build();
}
示例11: serializeList
import com.facebook.presto.spi.type.Type; //导入方法依赖的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;
}
}
示例12: TypedHeap
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public TypedHeap(BlockComparator comparator, Type type, int capacity)
{
this.comparator = comparator;
this.type = type;
this.capacity = capacity;
this.heapIndex = new int[capacity];
this.heapBlockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), capacity);
}
示例13: createBlock
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
/**
* Produce a block with the given values in the last field.
*/
private static Block createBlock(Type type, List<Object> values)
{
BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), values.size());
for (Object value : values) {
Class<?> javaType = type.getJavaType();
if (value == null) {
blockBuilder.appendNull();
}
else if (javaType == boolean.class) {
type.writeBoolean(blockBuilder, (Boolean) value);
}
else if (javaType == long.class) {
type.writeLong(blockBuilder, (Long) value);
}
else if (javaType == double.class) {
type.writeDouble(blockBuilder, (Double) value);
}
else if (javaType == Slice.class) {
Slice slice = (Slice) value;
type.writeSlice(blockBuilder, slice, 0, slice.length());
}
else {
throw new UnsupportedOperationException("not yet implemented: " + javaType);
}
}
return blockBuilder.build();
}
示例14: createTestBlock
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public static Block createTestBlock(Type mapType)
{
BlockBuilder blockBuilder = mapType.createBlockBuilder(new BlockBuilderStatus(), 2);
mapType.writeObject(blockBuilder, mapBlockOf(BIGINT, VARCHAR, ImmutableMap.of(1, "hi")));
mapType.writeObject(blockBuilder, mapBlockOf(BIGINT, VARCHAR, ImmutableMap.of(1, "2", 2, "hello")));
return blockBuilder.build();
}
示例15: appendElement
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, double value)
{
BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() + 1);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
elementType.writeDouble(blockBuilder, value);
return blockBuilder.build();
}