private static Block toBlock(Type type, SliceInput input, int length) {
    BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), 1, length);
    if (type.getJavaType() == long.class) {
      type.writeLong(builder, input.readLong());
    } else if (type.getJavaType() == double.class) {
      type.writeDouble(builder, input.readDouble());
    } else if (type.getJavaType() == Slice.class) {
      type.writeSlice(builder, input.readSlice(length));
    } else if (type.getJavaType() == boolean.class) {
      type.writeBoolean(builder, input.readByte() != 0);
    } else {
      throw new IllegalArgumentException("Unsupported type: " + type.getJavaType().getSimpleName());
    }

    return builder.build();
  }
  private Block createZeroBlock(Type type, int rowsCount, Slice constantSlice) {
    checkArgument(isSupportedType(type), "Unsupported type [%s]", type);

    Slice slice;
    // do not exceed varchar limit
    if (isVarcharType(type)) {
      slice =
          constantSlice.slice(
              0, Math.min(((VarcharType) type).getLength(), constantSlice.length()));
    } else if (isLongDecimal(type)) {
      slice = encodeScaledValue(ZERO);
    } else {
      slice = constantSlice;
    }

    BlockBuilder builder;
    if (type instanceof FixedWidthType) {
      builder = type.createBlockBuilder(new BlockBuilderStatus(), rowsCount);
    } else {
      builder = type.createBlockBuilder(new BlockBuilderStatus(), rowsCount, slice.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) {
        requireNonNull(slice, "slice is null");
        type.writeSlice(builder, slice, 0, slice.length());
      } else {
        throw new UnsupportedOperationException("Unknown javaType: " + javaType.getName());
      }
    }
    return builder.build();
  }