public ListenableFuture<?> partitionPage(Page page) {
      requireNonNull(page, "page is null");

      Page partitionFunctionArgs = getPartitionFunctionArguments(page);
      for (int position = 0; position < page.getPositionCount(); position++) {
        if (nullChannel.isPresent() && page.getBlock(nullChannel.getAsInt()).isNull(position)) {
          for (PageBuilder pageBuilder : pageBuilders) {
            pageBuilder.declarePosition();

            for (int channel = 0; channel < sourceTypes.size(); channel++) {
              Type type = sourceTypes.get(channel);
              type.appendTo(page.getBlock(channel), position, pageBuilder.getBlockBuilder(channel));
            }
          }
        } else {
          int partition = partitionFunction.getPartition(partitionFunctionArgs, position);

          PageBuilder pageBuilder = pageBuilders.get(partition);
          pageBuilder.declarePosition();

          for (int channel = 0; channel < sourceTypes.size(); channel++) {
            Type type = sourceTypes.get(channel);
            type.appendTo(page.getBlock(channel), position, pageBuilder.getBlockBuilder(channel));
          }
        }
      }
      return flush(false);
    }
  @Override
  public ConnectorPageSource createPageSource(
      ConnectorTransactionHandle transactionHandle,
      ConnectorSession session,
      ConnectorSplit split,
      List<ColumnHandle> columns) {
    InternalTable table = getInternalTable(transactionHandle, session, split, columns);

    List<Integer> channels = new ArrayList<>();
    for (ColumnHandle column : columns) {
      String columnName =
          checkType(column, InformationSchemaColumnHandle.class, "column").getColumnName();
      int columnIndex = table.getColumnIndex(columnName);
      channels.add(columnIndex);
    }

    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    for (Page page : table.getPages()) {
      Block[] blocks = new Block[channels.size()];
      for (int index = 0; index < blocks.length; index++) {
        blocks[index] = page.getBlock(channels.get(index));
      }
      pages.add(new Page(page.getPositionCount(), blocks));
    }
    return new FixedPageSource(pages.build());
  }
Пример #3
0
 private static Page rearrangePage(Page page, int[] channels) {
   Block[] newBlocks = new Block[channels.length];
   for (int i = 0; i < channels.length; i++) {
     newBlocks[i] = page.getBlock(channels[i]);
   }
   return new Page(page.getPositionCount(), newBlocks);
 }
 private Page getPartitionFunctionArguments(Page page) {
   Block[] blocks = new Block[partitionChannels.size()];
   for (int i = 0; i < blocks.length; i++) {
     Optional<Block> partitionConstant = partitionConstants.get(i);
     if (partitionConstant.isPresent()) {
       blocks[i] = new RunLengthEncodedBlock(partitionConstant.get(), page.getPositionCount());
     } else {
       blocks[i] = page.getBlock(partitionChannels.get(i));
     }
   }
   return new Page(page.getPositionCount(), blocks);
 }
  @Override
  public void addInput(Page page) {
    requireNonNull(page, "page is null");
    checkState(!finishing, "Operator is finishing");
    checkState(channelSet != null, "Set has not been built yet");
    checkState(outputPage == null, "Operator still has pending output");

    // create the block builder for the new boolean column
    // we know the exact size required for the block
    BlockBuilder blockBuilder = BOOLEAN.createFixedSizeBlockBuilder(page.getPositionCount());

    Page probeJoinPage = new Page(page.getBlock(probeJoinChannel));

    // update hashing strategy to use probe cursor
    for (int position = 0; position < page.getPositionCount(); position++) {
      if (probeJoinPage.getBlock(0).isNull(position)) {
        throw new PrestoException(
            NOT_SUPPORTED,
            "NULL values are not allowed on the probe side of SemiJoin operator. See the query plan for details.");
      } else {
        boolean contains = channelSet.contains(position, probeJoinPage);
        if (!contains && channelSet.containsNull()) {
          blockBuilder.appendNull();
        } else {
          BOOLEAN.writeBoolean(blockBuilder, contains);
        }
      }
    }

    // add the new boolean column to the page
    Block[] sourceBlocks = page.getBlocks();
    Block[] outputBlocks =
        new Block[sourceBlocks.length + 1]; // +1 for the single boolean output channel

    System.arraycopy(sourceBlocks, 0, outputBlocks, 0, sourceBlocks.length);
    outputBlocks[sourceBlocks.length] = blockBuilder.build();

    outputPage = new Page(outputBlocks);
  }
Пример #6
0
  private Object selectSingleValue(Operator operator) {
    Page output = getAtMostOnePage(operator, SOURCE_PAGE);

    assertNotNull(output);
    assertEquals(output.getPositionCount(), 1);
    assertEquals(output.getChannelCount(), 1);
    Type type = operator.getTypes().get(0);

    Block block = output.getBlock(0);
    assertEquals(block.getPositionCount(), 1);

    return type.getObjectValue(session.toConnectorSession(), block, 0);
  }
Пример #7
0
  private static boolean executeFilter(Operator operator) {
    Page page = getAtMostOnePage(operator, SOURCE_PAGE);

    boolean value;
    if (page != null) {
      assertEquals(page.getPositionCount(), 1);
      assertEquals(page.getChannelCount(), 1);

      assertTrue(operator.getTypes().get(0).getBoolean(page.getBlock(0), 0));
      value = true;
    } else {
      value = false;
    }
    return value;
  }
Пример #8
0
  public static Row extractRow(Page page, int position, List<Type> types) {
    checkArgument(page.getChannelCount() == types.size(), "channelCount does not match");
    checkArgument(
        position < page.getPositionCount(),
        "Requested position %s from a page with positionCount %s ",
        position,
        page.getPositionCount());

    RowBuilder rowBuilder = new RowBuilder();
    for (int channel = 0; channel < page.getChannelCount(); channel++) {
      Block block = page.getBlock(channel);
      Type type = types.get(channel);
      int size;
      Object value = getNativeContainerValue(type, block, position);
      if (value == null) {
        size = SIZE_OF_BYTE;
      } else if (type.getJavaType() == boolean.class) {
        size = SIZE_OF_BYTE;
      } else if (type.getJavaType() == long.class) {
        size = SIZE_OF_LONG;
      } else if (type.getJavaType() == double.class) {
        size = SIZE_OF_DOUBLE;
      } else if (type.getJavaType() == Slice.class) {
        size = ((Slice) value).length();
      } else if (type.getJavaType() == Block.class) {
        size = ((Block) value).getSizeInBytes();
      } else {
        throw new AssertionError("Unimplemented type: " + type);
      }
      rowBuilder.add(nativeContainerToOrcValue(type, value), size);
    }
    Row row = rowBuilder.build();
    verify(
        row.getColumns().size() == types.size(),
        "Column count in row: %s Expected column count: %s",
        row.getColumns().size(),
        types.size());
    return row;
  }