Search in sources :

Example 1 with RowSetComparison

use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.

the class RowSetTest method TestTopScalarArray.

@Test
public void TestTopScalarArray() {
    BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).addArray("a", MinorType.INT).build();
    ExtendableRowSet rs1 = fixture.rowSet(batchSchema);
    RowSetWriter writer = rs1.writer();
    writer.column(0).setInt(10);
    ArrayWriter array = writer.column(1).array();
    array.setInt(100);
    array.setInt(110);
    writer.save();
    writer.column(0).setInt(20);
    array = writer.column(1).array();
    array.setInt(200);
    array.setInt(120);
    array.setInt(220);
    writer.save();
    writer.column(0).setInt(30);
    writer.save();
    writer.done();
    RowSetReader reader = rs1.reader();
    assertTrue(reader.next());
    assertEquals(10, reader.column(0).getInt());
    ArrayReader arrayReader = reader.column(1).array();
    assertEquals(2, arrayReader.size());
    assertEquals(100, arrayReader.getInt(0));
    assertEquals(110, arrayReader.getInt(1));
    assertTrue(reader.next());
    assertEquals(20, reader.column(0).getInt());
    arrayReader = reader.column(1).array();
    assertEquals(3, arrayReader.size());
    assertEquals(200, arrayReader.getInt(0));
    assertEquals(120, arrayReader.getInt(1));
    assertEquals(220, arrayReader.getInt(2));
    assertTrue(reader.next());
    assertEquals(30, reader.column(0).getInt());
    arrayReader = reader.column(1).array();
    assertEquals(0, arrayReader.size());
    assertFalse(reader.next());
    SingleRowSet rs2 = fixture.rowSetBuilder(batchSchema).add(10, new int[] { 100, 110 }).add(20, new int[] { 200, 120, 220 }).add(30, null).build();
    new RowSetComparison(rs1).verifyAndClear(rs2);
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSet.RowSetWriter) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) ArrayWriter(org.apache.drill.exec.vector.accessor.ArrayWriter) RowSetReader(org.apache.drill.test.rowSet.RowSet.RowSetReader) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) Test(org.junit.Test)

Example 2 with RowSetComparison

use of org.apache.drill.test.rowSet.RowSetComparison in project drill by axbaretto.

the class TestBatchSerialization method verifySerialize.

/**
 * Verify serialize and deserialize. Need to pass both the
 * input and expected (even though the expected should be the same
 * data as the input) because the act of serializing clears the
 * input for obscure historical reasons.
 *
 * @param rowSet
 * @param expected
 * @throws IOException
 */
private void verifySerialize(SingleRowSet rowSet, SingleRowSet expected) throws IOException {
    File dir = DirTestWatcher.createTempDir(dirTestWatcher.getDir());
    FileChannel channel = FileChannel.open(new File(dir, "serialize.dat").toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
    VectorSerializer.Writer writer = VectorSerializer.writer(channel);
    VectorContainer container = rowSet.container();
    SelectionVector2 sv2 = rowSet.getSv2();
    writer.write(container, sv2);
    container.clear();
    if (sv2 != null) {
        sv2.clear();
    }
    writer.close();
    File outFile = new File(dir, "serialize.dat");
    assertTrue(outFile.exists());
    assertTrue(outFile.isFile());
    RowSet result;
    try (InputStream in = new BufferedInputStream(new FileInputStream(outFile))) {
        Reader reader = VectorSerializer.reader(fixture.allocator(), in);
        result = fixture.wrap(reader.read(), reader.sv2());
    }
    new RowSetComparison(expected).verifyAndClearAll(result);
    outFile.delete();
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BufferedInputStream(java.io.BufferedInputStream) FileChannel(java.nio.channels.FileChannel) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) RowSet(org.apache.drill.test.rowSet.RowSet) SelectionVector2(org.apache.drill.exec.record.selection.SelectionVector2) Reader(org.apache.drill.exec.cache.VectorSerializer.Reader) File(java.io.File) FileInputStream(java.io.FileInputStream) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 3 with RowSetComparison

use of org.apache.drill.test.rowSet.RowSetComparison 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 4 with RowSetComparison

use of org.apache.drill.test.rowSet.RowSetComparison 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 5 with RowSetComparison

use of org.apache.drill.test.rowSet.RowSetComparison in project drill by axbaretto.

the class TestSorter method runSorterTest.

public void runSorterTest(Sort popConfig, SingleRowSet rowSet, SingleRowSet expected) throws Exception {
    OperatorContext opContext = fixture.newOperatorContext(popConfig);
    SorterWrapper sorter = new SorterWrapper(opContext);
    try {
        sorter.sortBatch(rowSet.container(), rowSet.getSv2());
        new RowSetComparison(expected).verifyAndClearAll(rowSet);
        sorter.close();
    } finally {
        opContext.close();
    }
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) OperatorContext(org.apache.drill.exec.ops.OperatorContext)

Aggregations

RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)289 Test (org.junit.Test)271 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)232 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)211 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)191 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)142 ClusterTest (org.apache.drill.test.ClusterTest)138 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)54 SubOperatorTest (org.apache.drill.test.SubOperatorTest)53 QueryBuilder (org.apache.drill.test.QueryBuilder)48 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)42 OperatorTest (org.apache.drill.categories.OperatorTest)38 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)29 RowSet (org.apache.drill.test.rowSet.RowSet)26 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)26 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)25 StreamingAggregate (org.apache.drill.exec.physical.config.StreamingAggregate)19 StreamingAggBatch (org.apache.drill.exec.physical.impl.aggregate.StreamingAggBatch)19 RowSetLoader (org.apache.drill.exec.physical.rowSet.RowSetLoader)18 BatchSchema (org.apache.drill.exec.record.BatchSchema)18