当前位置: 首页>>代码示例>>Java>>正文


Java Type.writeObject方法代码示例

本文整理汇总了Java中com.facebook.presto.spi.type.Type.writeObject方法的典型用法代码示例。如果您正苦于以下问题:Java Type.writeObject方法的具体用法?Java Type.writeObject怎么用?Java Type.writeObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.facebook.presto.spi.type.Type的用法示例。


在下文中一共展示了Type.writeObject方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:27,代码来源:AbstractTestType.java

示例2: output

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public static void output(Type outputType, ArrayAggregationState state, BlockBuilder out)
{
    BlockBuilder stateBlockBuilder = state.getBlockBuilder();
    if (stateBlockBuilder == null || stateBlockBuilder.getPositionCount() == 0) {
        out.appendNull();
    }
    else {
        outputType.writeObject(out, stateBlockBuilder.build());
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:11,代码来源:ArrayAggregationFunction.java

示例3: toMultimapNativeEncoding

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
/**
 * Serialize as a multimap: map<key, array<value>>, each key can be associated with multiple values
 */
public Block toMultimapNativeEncoding()
{
    if (!isMultiValue) {
        throw new PrestoException(INTERNAL_ERROR, "This KeyValuePairs is not multimap.");
    }

    Block keys = keyBlockBuilder.build();
    Block values = valueBlockBuilder.build();

    // Merge values of the same key into an array
    BlockBuilder distinctKeyBlockBuilder = keyType.createBlockBuilder(new BlockBuilderStatus(), keys.getPositionCount(), expectedValueSize(keyType, EXPECTED_ENTRY_SIZE));
    ObjectBigArray<BlockBuilder> valueArrayBlockBuilders = new ObjectBigArray<>();
    valueArrayBlockBuilders.ensureCapacity(keys.getPositionCount());
    TypedSet keySet = new TypedSet(keyType, keys.getPositionCount());
    for (int keyValueIndex = 0; keyValueIndex < keys.getPositionCount(); keyValueIndex++) {
        if (!keySet.contains(keys, keyValueIndex)) {
            keySet.add(keys, keyValueIndex);
            keyType.appendTo(keys, keyValueIndex, distinctKeyBlockBuilder);
            BlockBuilder valueArrayBuilder = valueType.createBlockBuilder(new BlockBuilderStatus(), 10, expectedValueSize(valueType, EXPECTED_ENTRY_SIZE));
            valueArrayBlockBuilders.set(keySet.positionOf(keys, keyValueIndex), valueArrayBuilder);
        }
        valueType.appendTo(values, keyValueIndex, valueArrayBlockBuilders.get(keySet.positionOf(keys, keyValueIndex)));
    }

    // Write keys and value arrays into one Block
    Block distinctKeys = distinctKeyBlockBuilder.build();
    Type valueArrayType = new ArrayType(valueType);
    BlockBuilder multimapBlockBuilder = new InterleavedBlockBuilder(ImmutableList.of(keyType, valueArrayType), new BlockBuilderStatus(), distinctKeyBlockBuilder.getPositionCount());
    for (int i = 0; i < distinctKeys.getPositionCount(); i++) {
        keyType.appendTo(distinctKeys, i, multimapBlockBuilder);
        valueArrayType.writeObject(multimapBlockBuilder, valueArrayBlockBuilders.get(i).build());
    }

    return multimapBlockBuilder.build();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:39,代码来源:KeyValuePairs.java

示例4: write

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
static void write(Type type, BlockState state, BlockBuilder out)
{
    if (state.getBlock() == null) {
        out.appendNull();
    }
    else {
        type.writeObject(out, state.getBlock());
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:10,代码来源:BlockState.java

示例5: output

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public static void output(Type type, HistogramState state, BlockBuilder out)
{
    TypedHistogram typedHistogram = state.get();
    if (typedHistogram == null) {
        out.appendNull();
    }
    else {
        Block block = typedHistogram.serialize();
        type.writeObject(out, block);
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:12,代码来源:Histogram.java

示例6: appendElement

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, Object value)
{
    BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }

    elementType.writeObject(blockBuilder, value);

    return blockBuilder.build();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:13,代码来源:ArrayConcatUtils.java

示例7: 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();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:13,代码来源:ArrayConcatUtils.java

示例8: equals

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public static boolean equals(Type rowType, Block leftRow, Block rightRow)
{
    // TODO: Fix this. It feels very inefficient and unnecessary to wrap and unwrap with Block
    BlockBuilder leftBlockBuilder = rowType.createBlockBuilder(new BlockBuilderStatus(), 1);
    BlockBuilder rightBlockBuilder = rowType.createBlockBuilder(new BlockBuilderStatus(), 1);
    rowType.writeObject(leftBlockBuilder, leftRow);
    rowType.writeObject(rightBlockBuilder, rightRow);
    return rowType.equalTo(leftBlockBuilder.build(), 0, rightBlockBuilder.build(), 0);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:10,代码来源:RowEqualOperator.java

示例9: createTestBlock

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public static Block createTestBlock(Type arrayType)
{
    BlockBuilder blockBuilder = arrayType.createBlockBuilder(new BlockBuilderStatus(), 4);
    arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2));
    arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2, 3));
    arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 1, 2, 3));
    arrayType.writeObject(blockBuilder, arrayBlockOf(BIGINT, 100, 200, 300));
    return blockBuilder.build();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:10,代码来源:TestBigintArrayType.java

示例10: createTestBlock

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
public static Block createTestBlock(Type arrayType)
{
    BlockBuilder blockBuilder = arrayType.createBlockBuilder(new BlockBuilderStatus(), 4);
    arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2));
    arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2, 3));
    arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 1, 2, 3));
    arrayType.writeObject(blockBuilder, arrayBlockOf(COLOR, 100, 200, 300));
    return blockBuilder.build();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:10,代码来源:TestColorArrayType.java

示例11: 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();
}
 
开发者ID:y-lan,项目名称:presto,代码行数:8,代码来源:TestBigintVarcharMapType.java

示例12: getNextPage

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
@Override
public Page getNextPage()
{
    if (!closed) {
        int i;
        for (i = 0; i < ROWS_PER_REQUEST; i++) {
            if (pageBuilder.isFull()) {
                break;
            }

            if (!cursor.advanceNextPosition()) {
                closed = true;
                break;
            }

            pageBuilder.declarePosition();
            for (int column = 0; column < types.size(); column++) {
                BlockBuilder output = pageBuilder.getBlockBuilder(column);
                if (cursor.isNull(column)) {
                    output.appendNull();
                }
                else {
                    Type type = types.get(column);
                    Class<?> javaType = type.getJavaType();
                    if (javaType == boolean.class) {
                        type.writeBoolean(output, cursor.getBoolean(column));
                    }
                    else if (javaType == long.class) {
                        type.writeLong(output, cursor.getLong(column));
                    }
                    else if (javaType == double.class) {
                        type.writeDouble(output, cursor.getDouble(column));
                    }
                    else if (javaType == Slice.class) {
                        Slice slice = cursor.getSlice(column);
                        type.writeSlice(output, slice, 0, slice.length());
                    }
                    else {
                        type.writeObject(output, cursor.getObject(column));
                    }
                }
            }
        }
    }

    // only return a page if the buffer is full or we are finishing
    if (pageBuilder.isEmpty() || (!closed && !pageBuilder.isFull())) {
        return null;
    }

    Page page = pageBuilder.build();
    pageBuilder.reset();

    return page;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:56,代码来源:RecordPageSource.java

示例13: checkPageSource

import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
protected void checkPageSource(ConnectorPageSource pageSource, List<TestColumn> testColumns, List<Type> types)
        throws IOException
{
    try {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, types);

        for (MaterializedRow row : result) {
            for (int i = 0, testColumnsSize = testColumns.size(); i < testColumnsSize; i++) {
                TestColumn testColumn = testColumns.get(i);
                Type type = types.get(i);

                Object actualValue = row.getField(i);
                Object expectedValue = testColumn.getExpectedValue();
                if (actualValue == null) {
                    assertEquals(null, expectedValue, String.format("Expected non-null for column %d", i));
                }
                else if (testColumn.getObjectInspector().getTypeName().equals("float") ||
                        testColumn.getObjectInspector().getTypeName().equals("double")) {
                    assertEquals((double) actualValue, (double) expectedValue, EPSILON);
                }
                else if (testColumn.getObjectInspector().getTypeName().equals("date")) {
                    SqlDate expectedDate = new SqlDate(((Long) expectedValue).intValue());
                    assertEquals(actualValue, expectedDate);
                }
                else if (testColumn.getObjectInspector().getTypeName().equals("timestamp")) {
                    SqlTimestamp expectedTimestamp = new SqlTimestamp((Long) expectedValue, SESSION.getTimeZoneKey());
                    assertEquals(actualValue, expectedTimestamp);
                }
                else if (testColumn.getObjectInspector().getCategory() == Category.PRIMITIVE) {
                    if (expectedValue instanceof Slice) {
                        expectedValue = ((Slice) expectedValue).toStringUtf8();
                    }

                    if (actualValue instanceof Slice) {
                        actualValue = ((Slice) actualValue).toStringUtf8();
                    }
                    if (actualValue instanceof SqlVarbinary) {
                        actualValue = new String(((SqlVarbinary) actualValue).getBytes(), UTF_8);
                    }
                    assertEquals(actualValue, expectedValue, String.format("Wrong value for column %d", i));
                }
                else {
                    BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), 1);
                    type.writeObject(builder, expectedValue);
                    expectedValue = type.getObjectValue(SESSION, builder.build(), 0);
                    assertEquals(actualValue, expectedValue, String.format("Wrong value for column %s", testColumn.getName()));
                }
            }
        }
    }
    finally {
        pageSource.close();
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:55,代码来源:AbstractTestHiveFileFormats.java


注:本文中的com.facebook.presto.spi.type.Type.writeObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。