本文整理汇总了Java中com.facebook.presto.spi.type.Type.writeSlice方法的典型用法代码示例。如果您正苦于以下问题:Java Type.writeSlice方法的具体用法?Java Type.writeSlice怎么用?Java Type.writeSlice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.presto.spi.type.Type
的用法示例。
在下文中一共展示了Type.writeSlice方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializePrimitive
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
private static void serializePrimitive(Type type, BlockBuilder builder, Object object) {
requireNonNull(builder, "parent builder is null");
if (object == null) {
builder.appendNull();
return;
}
if (BOOLEAN.equals(type)) {
BOOLEAN.writeBoolean(builder, (Boolean) object);
} else if (BIGINT.equals(type) || INTEGER.equals(type) || SMALLINT.equals(type) || TINYINT.equals(type)
|| REAL.equals(type) || DATE.equals(type) || TIMESTAMP.equals(type)) {
type.writeLong(builder, getLongExpressedValue(object));
} else if (DOUBLE.equals(type)) {
DOUBLE.writeDouble(builder, ((Number) object).doubleValue());
} else if (isVarcharType(type) || VARBINARY.equals(type) || isCharType(type)) {
type.writeSlice(builder, getSliceExpressedValue(object, type));
} else {
throw new UnsupportedOperationException("Unsupported primitive type: " + type);
}
}
示例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: 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();
}
示例4: 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();
}
示例5: write
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
static void write(Type type, SliceState state, BlockBuilder out)
{
if (state.getSlice() == null) {
out.appendNull();
}
else {
type.writeSlice(out, state.getSlice());
}
}
示例6: appendElement
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, Slice value)
{
BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() + 1);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
elementType.writeSlice(blockBuilder, value);
return blockBuilder.build();
}
示例7: prependElement
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
@UsedByGeneratedCode
public static Block prependElement(Type elementType, Slice value, Block block)
{
BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() + 1);
elementType.writeSlice(blockBuilder, value);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
return blockBuilder.build();
}
示例8: 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();
}
示例9: getOutput
import com.facebook.presto.spi.type.Type; //导入方法依赖的package包/类
@Override
public Page getOutput()
{
if (!finishing) {
int i;
for (i = 0; i < ROWS_PER_REQUEST; i++) {
if (pageBuilder.isFull()) {
break;
}
if (!cursor.advanceNextPosition()) {
finishing = 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 = getTypes().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 {
throw new AssertionError("Unimplemented type: " + javaType.getName());
}
}
}
}
long endCompletedBytes = cursor.getCompletedBytes();
long endReadTimeNanos = cursor.getReadTimeNanos();
operatorContext.recordGeneratedInput(endCompletedBytes - completedBytes, i, endReadTimeNanos - readTimeNanos);
completedBytes = endCompletedBytes;
readTimeNanos = endReadTimeNanos;
}
// only return a full page is buffer is full or we are finishing
if (pageBuilder.isEmpty() || (!finishing && !pageBuilder.isFull())) {
return null;
}
Page page = pageBuilder.build();
pageBuilder.reset();
return page;
}
示例10: 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;
}