Search in sources :

Example 1 with ExternalSort

use of org.apache.drill.exec.physical.config.ExternalSort in project drill by apache.

the class MemoryAllocationUtilities method setupSortMemoryAllocations.

/**
   * Helper method to setup SortMemoryAllocations
   * since this method can be used in multiple places adding it in this class
   * rather than keeping it in Foreman
   * @param plan
   * @param queryContext
   */
public static void setupSortMemoryAllocations(final PhysicalPlan plan, final QueryContext queryContext) {
    if (plan.getProperties().hasResourcePlan) {
        return;
    }
    // look for external sorts
    final List<ExternalSort> sortList = new LinkedList<>();
    for (final PhysicalOperator op : plan.getSortedOperators()) {
        if (op instanceof ExternalSort) {
            sortList.add((ExternalSort) op);
        }
    }
    // if there are any sorts, compute the maximum allocation, and set it on them
    if (sortList.size() > 0) {
        final OptionManager optionManager = queryContext.getOptions();
        final long maxWidthPerNode = optionManager.getOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY).num_val;
        long maxAllocPerNode = Math.min(DrillConfig.getMaxDirectMemory(), queryContext.getConfig().getLong(RootAllocatorFactory.TOP_LEVEL_MAX_ALLOC));
        maxAllocPerNode = Math.min(maxAllocPerNode, optionManager.getOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY).num_val);
        final long maxSortAlloc = maxAllocPerNode / (sortList.size() * maxWidthPerNode);
        logger.debug("Max sort alloc: {}", maxSortAlloc);
        for (final ExternalSort externalSort : sortList) {
            // Ensure that the sort receives the minimum memory needed to make progress.
            // Without this, the math might work out to allocate too little memory.
            long alloc = Math.max(maxSortAlloc, externalSort.getInitialAllocation());
            externalSort.setMaxAllocation(alloc);
        }
    }
    plan.getProperties().hasResourcePlan = true;
}
Also used : ExternalSort(org.apache.drill.exec.physical.config.ExternalSort) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) LinkedList(java.util.LinkedList) OptionManager(org.apache.drill.exec.server.options.OptionManager)

Example 2 with ExternalSort

use of org.apache.drill.exec.physical.config.ExternalSort in project drill by axbaretto.

the class BasicPhysicalOpUnitTest method testExternalSort.

@Test
public void testExternalSort() {
    ExternalSort sortConf = new ExternalSort(null, Lists.newArrayList(ordering("b", RelFieldCollation.Direction.ASCENDING, RelFieldCollation.NullDirection.FIRST)), false);
    List<String> inputJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : 1 }]", "[{\"a\": 5, \"b\" : 5},{\"a\": 3, \"b\" : 8}]", "[{\"a\": 40, \"b\" : 3},{\"a\": 13, \"b\" : 100}]");
    opTestBuilder().physicalOperator(sortConf).maxAllocation(15_000_000L).inputDataStreamJson(inputJsonBatches).baselineColumns("a", "b").baselineValues(5l, 1l).baselineValues(40l, 3l).baselineValues(5l, 5l).baselineValues(3l, 8l).baselineValues(13l, 100l).go();
}
Also used : ExternalSort(org.apache.drill.exec.physical.config.ExternalSort) Test(org.junit.Test)

Example 3 with ExternalSort

use of org.apache.drill.exec.physical.config.ExternalSort in project drill by axbaretto.

the class BasicPhysicalOpUnitTest method externalSortLowMemoryHelper.

private void externalSortLowMemoryHelper(int batchSize, int numberOfBatches, long initReservation, long maxAllocation) {
    ExternalSort sortConf = new ExternalSort(null, Lists.newArrayList(ordering("b", RelFieldCollation.Direction.ASCENDING, RelFieldCollation.NullDirection.FIRST)), false);
    List<String> inputJsonBatches = Lists.newArrayList();
    StringBuilder batchString = new StringBuilder();
    for (int j = 0; j < numberOfBatches; j++) {
        batchString.append("[");
        for (int i = 0; i < batchSize; i++) {
            batchString.append("{\"a\": 5, \"b\" : 5},{\"a\": 3, \"b\" : 8},");
        }
        batchString.append("{\"a\": 5, \"b\" : 1 }");
        batchString.append("]");
        inputJsonBatches.add(batchString.toString());
    }
    OperatorTestBuilder opTestBuilder = opTestBuilder().initReservation(initReservation).maxAllocation(maxAllocation).physicalOperator(sortConf).inputDataStreamJson(inputJsonBatches).baselineColumns("a", "b");
    for (int i = 0; i < numberOfBatches; i++) {
        opTestBuilder.baselineValues(5l, 1l);
    }
    for (int i = 0; i < batchSize * numberOfBatches; i++) {
        opTestBuilder.baselineValues(5l, 5l);
    }
    for (int i = 0; i < batchSize * numberOfBatches; i++) {
        opTestBuilder.baselineValues(3l, 8l);
    }
    opTestBuilder.go();
}
Also used : ExternalSort(org.apache.drill.exec.physical.config.ExternalSort) MinorFragmentEndpoint(org.apache.drill.exec.physical.MinorFragmentEndpoint)

Example 4 with ExternalSort

use of org.apache.drill.exec.physical.config.ExternalSort in project drill by apache.

the class TestExternalSortExec method testSortSpec.

@Test
public void testSortSpec() {
    FieldReference expr = FieldReference.getWithQuotedRef("foo");
    Ordering ordering = new Ordering(Ordering.ORDER_ASC, expr, Ordering.NULLS_FIRST);
    // Basics
    ExternalSort popConfig = new ExternalSort(null, Lists.newArrayList(ordering), false);
    assertSame(ordering, popConfig.getOrderings().get(0));
    assertFalse(popConfig.getReverse());
    assertEquals(SelectionVectorMode.FOUR_BYTE, popConfig.getSVMode());
    assertEquals(ExternalSort.OPERATOR_TYPE, popConfig.getOperatorType());
    assertEquals(ExternalSort.DEFAULT_SORT_ALLOCATION, popConfig.getInitialAllocation());
    assertEquals(AbstractBase.MAX_ALLOCATION, popConfig.getMaxAllocation());
    assertTrue(popConfig.isExecutable());
    // Non-default settings
    popConfig = new ExternalSort(null, Lists.newArrayList(ordering), true);
    assertTrue(popConfig.getReverse());
    long maxAlloc = 50_000_000;
    popConfig.setMaxAllocation(maxAlloc);
    assertEquals(ExternalSort.DEFAULT_SORT_ALLOCATION, popConfig.getInitialAllocation());
    assertEquals(maxAlloc, popConfig.getMaxAllocation());
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) ExternalSort(org.apache.drill.exec.physical.config.ExternalSort) Ordering(org.apache.drill.common.logical.data.Order.Ordering) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 5 with ExternalSort

use of org.apache.drill.exec.physical.config.ExternalSort in project drill by apache.

the class TestNullInputMiniPlan method testSortEmpty.

@Test
public void testSortEmpty() throws Exception {
    final PhysicalOperator sort = new ExternalSort(null, Lists.newArrayList(ordering("b", RelFieldCollation.Direction.ASCENDING, RelFieldCollation.NullDirection.FIRST)), false);
    testSingleInputNullBatchHandling(sort);
}
Also used : PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) ExternalSort(org.apache.drill.exec.physical.config.ExternalSort) Test(org.junit.Test)

Aggregations

ExternalSort (org.apache.drill.exec.physical.config.ExternalSort)12 Test (org.junit.Test)6 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)5 FieldReference (org.apache.drill.common.expression.FieldReference)3 OperatorTest (org.apache.drill.categories.OperatorTest)2 Ordering (org.apache.drill.common.logical.data.Order.Ordering)2 MinorFragmentEndpoint (org.apache.drill.exec.physical.MinorFragmentEndpoint)2 DrillTest (org.apache.drill.test.DrillTest)2 LinkedList (java.util.LinkedList)1 Order (org.apache.drill.common.logical.data.Order)1 OptionManager (org.apache.drill.exec.server.options.OptionManager)1 LegacyOperatorTestBuilder (org.apache.drill.test.LegacyOperatorTestBuilder)1 BeforeClass (org.junit.BeforeClass)1