Search in sources :

Example 1 with SelectionOperatorService

use of com.linkedin.pinot.core.query.selection.SelectionOperatorService in project pinot by linkedin.

the class BrokerReduceService method setSelectionResults.

/**
   * Reduce selection results from multiple servers and set them into BrokerResponseNative passed in.
   *
   * @param brokerResponseNative broker response.
   * @param selection selection information.
   * @param dataTableMap map from server to data table.
   * @param dataSchema data schema.
   */
private void setSelectionResults(@Nonnull BrokerResponseNative brokerResponseNative, @Nonnull Selection selection, @Nonnull Map<ServerInstance, DataTable> dataTableMap, @Nonnull DataSchema dataSchema) {
    // Reduce the selection results.
    SelectionResults selectionResults;
    int selectionSize = selection.getSize();
    if (selection.isSetSelectionSortSequence() && selectionSize != 0) {
        // Selection order-by.
        SelectionOperatorService selectionService = new SelectionOperatorService(selection, dataSchema);
        selectionService.reduceWithOrdering(dataTableMap);
        selectionResults = selectionService.renderSelectionResultsWithOrdering();
    } else {
        // Selection only.
        selectionResults = SelectionOperatorUtils.renderSelectionResultsWithoutOrdering(SelectionOperatorUtils.reduceWithoutOrdering(dataTableMap, selectionSize), dataSchema, SelectionOperatorUtils.getSelectionColumns(selection.getSelectionColumns(), dataSchema));
    }
    brokerResponseNative.setSelectionResults(selectionResults);
}
Also used : SelectionOperatorService(com.linkedin.pinot.core.query.selection.SelectionOperatorService) SelectionResults(com.linkedin.pinot.common.response.broker.SelectionResults)

Example 2 with SelectionOperatorService

use of com.linkedin.pinot.core.query.selection.SelectionOperatorService in project pinot by linkedin.

the class SelectionOperatorServiceTest method testCompatibleRowsRenderSelectionResultsWithOrdering.

@Test
public void testCompatibleRowsRenderSelectionResultsWithOrdering() {
    SelectionOperatorService selectionOperatorService = new SelectionOperatorService(_selectionOrderBy, _upgradedDataSchema);
    PriorityQueue<Serializable[]> rows = selectionOperatorService.getRows();
    rows.offer(_row1.clone());
    rows.offer(_compatibleRow1.clone());
    rows.offer(_compatibleRow2.clone());
    SelectionResults selectionResults = selectionOperatorService.renderSelectionResultsWithOrdering();
    List<Serializable[]> formattedRows = selectionResults.getRows();
    Serializable[] expectedFormattedRow1 = { "1", "2.0", "3.0", "4.0", "5", new String[] { "6" }, new String[] { "7.0" }, new String[] { "8.0" }, new String[] { "9.0" }, new String[] { "10" } };
    Serializable[] expectedFormattedRow2 = { "0", "1.0", "2.0", "3.0", "4", new String[] { "5" }, new String[] { "6.0" }, new String[] { "7.0" }, new String[] { "8.0" }, new String[] { "9" } };
    Assert.assertEquals(formattedRows.get(0), expectedFormattedRow1);
    Assert.assertEquals(formattedRows.get(1), expectedFormattedRow2);
}
Also used : Serializable(java.io.Serializable) SelectionOperatorService(com.linkedin.pinot.core.query.selection.SelectionOperatorService) SelectionResults(com.linkedin.pinot.common.response.broker.SelectionResults) Test(org.testng.annotations.Test)

Example 3 with SelectionOperatorService

use of com.linkedin.pinot.core.query.selection.SelectionOperatorService in project pinot by linkedin.

the class SelectionOperatorServiceTest method testCompatibleRowsMergeWithOrdering.

@Test
public void testCompatibleRowsMergeWithOrdering() {
    SelectionOperatorService selectionOperatorService = new SelectionOperatorService(_selectionOrderBy, _dataSchema);
    PriorityQueue<Serializable[]> mergedRows = selectionOperatorService.getRows();
    Collection<Serializable[]> rowsToMerge1 = new ArrayList<>(2);
    rowsToMerge1.add(_row1.clone());
    rowsToMerge1.add(_row2.clone());
    Collection<Serializable[]> rowsToMerge2 = new ArrayList<>(2);
    rowsToMerge2.add(_compatibleRow1.clone());
    rowsToMerge2.add(_compatibleRow2.clone());
    int maxNumRows = _selectionOrderBy.getOffset() + _selectionOrderBy.getSize();
    SelectionOperatorUtils.mergeWithOrdering(mergedRows, rowsToMerge1, maxNumRows);
    SelectionOperatorUtils.mergeWithOrdering(mergedRows, rowsToMerge2, maxNumRows);
    Assert.assertEquals(mergedRows.size(), 3);
    Assert.assertEquals(mergedRows.poll(), _compatibleRow1);
    Assert.assertEquals(mergedRows.poll(), _row2);
    Assert.assertEquals(mergedRows.poll(), _compatibleRow2);
}
Also used : SelectionOperatorService(com.linkedin.pinot.core.query.selection.SelectionOperatorService) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Aggregations

SelectionOperatorService (com.linkedin.pinot.core.query.selection.SelectionOperatorService)3 SelectionResults (com.linkedin.pinot.common.response.broker.SelectionResults)2 Test (org.testng.annotations.Test)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1