Search in sources :

Example 1 with RootAllocator

use of org.apache.drill.exec.memory.RootAllocator in project drill by axbaretto.

the class TopNBatchTest method priorityQueueOrderingTest.

/**
 * Priority queue unit test.
 * @throws Exception
 */
@Test
public void priorityQueueOrderingTest() throws Exception {
    Properties properties = new Properties();
    DrillConfig drillConfig = DrillConfig.create(properties);
    FieldReference expr = FieldReference.getWithQuotedRef("colA");
    Order.Ordering ordering = new Order.Ordering(Order.Ordering.ORDER_DESC, expr, Order.Ordering.NULLS_FIRST);
    List<Order.Ordering> orderings = Lists.newArrayList(ordering);
    MaterializedField colA = MaterializedField.create("colA", Types.required(TypeProtos.MinorType.INT));
    MaterializedField colB = MaterializedField.create("colB", Types.required(TypeProtos.MinorType.INT));
    List<MaterializedField> cols = Lists.newArrayList(colA, colB);
    BatchSchema batchSchema = new BatchSchema(BatchSchema.SelectionVectorMode.NONE, cols);
    RowSet expectedRowSet;
    try (RootAllocator allocator = new RootAllocator(100_000_000)) {
        expectedRowSet = new RowSetBuilder(allocator, batchSchema).addRow(110, 10).addRow(109, 9).addRow(108, 8).addRow(107, 7).addRow(106, 6).addRow(105, 5).addRow(104, 4).addRow(103, 3).addRow(102, 2).addRow(101, 1).build();
        PriorityQueue queue;
        ExpandableHyperContainer hyperContainer;
        {
            VectorContainer container = new RowSetBuilder(allocator, batchSchema).build().container();
            hyperContainer = new ExpandableHyperContainer(container);
            queue = TopNBatch.createNewPriorityQueue(TopNBatch.createMainMappingSet(), TopNBatch.createLeftMappingSet(), TopNBatch.createRightMappingSet(), optionManager, new FunctionImplementationRegistry(drillConfig), new CodeCompiler(drillConfig, optionManager), orderings, hyperContainer, false, true, 10, allocator, batchSchema.getSelectionVectorMode());
        }
        List<RecordBatchData> testBatches = Lists.newArrayList();
        try {
            final Random random = new Random();
            final int bound = 100;
            final int numBatches = 11;
            final int numRecordsPerBatch = 100;
            for (int batchCounter = 0; batchCounter < numBatches; batchCounter++) {
                RowSetBuilder rowSetBuilder = new RowSetBuilder(allocator, batchSchema);
                rowSetBuilder.addRow((batchCounter + bound), batchCounter);
                for (int recordCounter = 0; recordCounter < numRecordsPerBatch; recordCounter++) {
                    rowSetBuilder.addRow(random.nextInt(bound), random.nextInt(bound));
                }
                VectorContainer vectorContainer = rowSetBuilder.build().container();
                queue.add(new RecordBatchData(vectorContainer, allocator));
            }
            queue.generate();
            VectorContainer resultContainer = queue.getHyperBatch();
            resultContainer.buildSchema(BatchSchema.SelectionVectorMode.NONE);
            RowSet.HyperRowSet actualHyperSet = HyperRowSetImpl.fromContainer(resultContainer, queue.getFinalSv4());
            new RowSetComparison(expectedRowSet).verify(actualHyperSet);
        } finally {
            if (expectedRowSet != null) {
                expectedRowSet.clear();
            }
            queue.cleanup();
            hyperContainer.clear();
            for (RecordBatchData testBatch : testBatches) {
                testBatch.clear();
            }
        }
    }
}
Also used : Order(org.apache.drill.common.logical.data.Order) ExpandableHyperContainer(org.apache.drill.exec.record.ExpandableHyperContainer) FieldReference(org.apache.drill.common.expression.FieldReference) RecordBatchData(org.apache.drill.exec.physical.impl.sort.RecordBatchData) RowSet(org.apache.drill.test.rowSet.RowSet) MaterializedField(org.apache.drill.exec.record.MaterializedField) Properties(java.util.Properties) VectorContainer(org.apache.drill.exec.record.VectorContainer) RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) RootAllocator(org.apache.drill.exec.memory.RootAllocator) DrillConfig(org.apache.drill.common.config.DrillConfig) Random(java.util.Random) BatchSchema(org.apache.drill.exec.record.BatchSchema) CodeCompiler(org.apache.drill.exec.compile.CodeCompiler) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 2 with RootAllocator

use of org.apache.drill.exec.memory.RootAllocator in project drill by axbaretto.

the class AbstractGenericCopierTest method testCopyRecords.

@Test
public void testCopyRecords() throws SchemaChangeException {
    try (RootAllocator allocator = new RootAllocator(10_000_000)) {
        final BatchSchema batchSchema = createTestSchema(BatchSchema.SelectionVectorMode.NONE);
        final RowSet srcRowSet = createSrcRowSet(allocator);
        final RowSet destRowSet = new RowSetBuilder(allocator, batchSchema).build();
        final VectorContainer destContainer = destRowSet.container();
        final Copier copier = createCopier();
        final RowSet expectedRowSet = createExpectedRowset(allocator);
        copier.setup(new RowSetBatch(srcRowSet), destContainer);
        copier.copyRecords(0, 3);
        try {
            new RowSetComparison(expectedRowSet).verify(destRowSet);
        } finally {
            srcRowSet.clear();
            if (srcRowSet instanceof RowSet.HyperRowSet) {
                ((RowSet.HyperRowSet) srcRowSet).getSv4().clear();
            }
            destRowSet.clear();
            expectedRowSet.clear();
        }
    }
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) RootAllocator(org.apache.drill.exec.memory.RootAllocator) RowSetBatch(org.apache.drill.test.rowSet.RowSetBatch) BatchSchema(org.apache.drill.exec.record.BatchSchema) RowSet(org.apache.drill.test.rowSet.RowSet) VectorContainer(org.apache.drill.exec.record.VectorContainer) Test(org.junit.Test)

Example 3 with RootAllocator

use of org.apache.drill.exec.memory.RootAllocator in project drill by axbaretto.

the class ExampleTest method secondTest.

/**
 * <p>
 *   Example that uses the fixture builder to build a cluster fixture. Lets
 *   you set configuration (boot-time) options, session options, system options
 *   and more.
 * </p>
 * <p>
 *   You can write test files to the {@link BaseDirTestWatcher#getRootDir()} and query them in the test.
 * </p>
 * <p>
 *   Also shows how to display the plan JSON and just run a query silently,
 *   getting just the row count, batch count and run time.
 * </p>
 * @throws Exception if anything goes wrong
 */
@Test
public void secondTest() throws Exception {
    try (RootAllocator allocator = new RootAllocator(100_000_000)) {
        final File tableFile = dirTestWatcher.getRootDir().toPath().resolve("employee.json").toFile();
        final BatchSchema schema = new SchemaBuilder().add("id", Types.required(TypeProtos.MinorType.VARCHAR)).add("name", Types.required(TypeProtos.MinorType.VARCHAR)).build();
        final RowSet rowSet = new RowSetBuilder(allocator, schema).addRow("1", "kiwi").addRow("2", "watermelon").build();
        new JsonFileBuilder(rowSet).build(tableFile);
        rowSet.clear();
        ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher).configProperty(ExecConstants.SLICE_TARGET, 10);
        try (ClusterFixture cluster = builder.build();
            ClientFixture client = cluster.clientFixture()) {
            String sql = "SELECT * FROM `dfs`.`test/employee.json`";
            System.out.println(client.queryBuilder().sql(sql).explainJson());
            QuerySummary results = client.queryBuilder().sql(sql).run();
            System.out.println(String.format("Read %d rows", results.recordCount()));
            // Usually we want to test something. Here, just test that we got
            // the 2 records.
            assertEquals(2, results.recordCount());
        }
    }
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RootAllocator(org.apache.drill.exec.memory.RootAllocator) BatchSchema(org.apache.drill.exec.record.BatchSchema) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSet(org.apache.drill.test.rowSet.RowSet) JsonFileBuilder(org.apache.drill.test.rowSet.file.JsonFileBuilder) File(java.io.File) Test(org.junit.Test)

Example 4 with RootAllocator

use of org.apache.drill.exec.memory.RootAllocator in project drill by axbaretto.

the class VariableLengthVectorTest method testSetBackTracking.

/**
 * Set 10000 values. Then go back and set new values starting at the 1001 the record.
 */
@Test
public void testSetBackTracking() {
    try (RootAllocator allocator = new RootAllocator(10_000_000)) {
        final MaterializedField field = MaterializedField.create("stringCol", Types.required(TypeProtos.MinorType.VARCHAR));
        final VarCharVector vector = new VarCharVector(field, allocator);
        vector.allocateNew();
        try {
            final int size = 1000;
            final int fluffSize = 10000;
            final VarCharVector.Mutator mutator = vector.getMutator();
            final VarCharVector.Accessor accessor = vector.getAccessor();
            setSafeIndexStrings("", 0, size, mutator);
            setSafeIndexStrings("first cut ", size, fluffSize, mutator);
            setSafeIndexStrings("redone cut ", size, fluffSize, mutator);
            mutator.setValueCount(fluffSize);
            Assert.assertEquals(fluffSize, accessor.getValueCount());
            checkIndexStrings("", 0, size, accessor);
            checkIndexStrings("redone cut ", size, fluffSize, accessor);
        } finally {
            vector.clear();
        }
    }
}
Also used : RootAllocator(org.apache.drill.exec.memory.RootAllocator) MaterializedField(org.apache.drill.exec.record.MaterializedField) Test(org.junit.Test)

Example 5 with RootAllocator

use of org.apache.drill.exec.memory.RootAllocator in project drill by axbaretto.

the class VariableLengthVectorTest method testSettingSameValueCount.

/**
 * If the vector contains 1000 records, setting a value count of 1000 should work.
 */
@Test
public void testSettingSameValueCount() {
    try (RootAllocator allocator = new RootAllocator(10_000_000)) {
        final MaterializedField field = MaterializedField.create("stringCol", Types.required(TypeProtos.MinorType.VARCHAR));
        final VarCharVector vector = new VarCharVector(field, allocator);
        vector.allocateNew();
        try {
            final int size = 1000;
            final VarCharVector.Mutator mutator = vector.getMutator();
            final VarCharVector.Accessor accessor = vector.getAccessor();
            setSafeIndexStrings("", 0, size, mutator);
            mutator.setValueCount(size);
            Assert.assertEquals(size, accessor.getValueCount());
            checkIndexStrings("", 0, size, accessor);
        } finally {
            vector.clear();
        }
    }
}
Also used : RootAllocator(org.apache.drill.exec.memory.RootAllocator) MaterializedField(org.apache.drill.exec.record.MaterializedField) Test(org.junit.Test)

Aggregations

RootAllocator (org.apache.drill.exec.memory.RootAllocator)15 Test (org.junit.Test)14 MaterializedField (org.apache.drill.exec.record.MaterializedField)9 BatchSchema (org.apache.drill.exec.record.BatchSchema)5 VectorContainer (org.apache.drill.exec.record.VectorContainer)4 BaseTest (org.apache.drill.test.BaseTest)4 RowSet (org.apache.drill.test.rowSet.RowSet)4 RowSetBuilder (org.apache.drill.test.rowSet.RowSetBuilder)4 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)4 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)3 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)3 File (java.io.File)2 Properties (java.util.Properties)2 Random (java.util.Random)2 OperatorTest (org.apache.drill.categories.OperatorTest)2 DrillConfig (org.apache.drill.common.config.DrillConfig)2 FieldReference (org.apache.drill.common.expression.FieldReference)2 Order (org.apache.drill.common.logical.data.Order)2 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)2 RecordBatchData (org.apache.drill.exec.physical.impl.sort.RecordBatchData)2