Search in sources :

Example 71 with RowSetComparison

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

the class TestLateralJoinCorrectnessBatchProcessing method testLeftAndRightWithMissingRows_LeftJoin_SingleBatch.

@Test
public void testLeftAndRightWithMissingRows_LeftJoin_SingleBatch() throws Exception {
    leftContainer.add(nonEmptyLeftRowSet.container());
    // Get the left IterOutcomes for Lateral Join
    leftOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    // Create Left MockRecordBatch
    final CloseableRecordBatch leftMockBatch = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, leftContainer, leftOutcomes, leftContainer.get(0).getSchema());
    // Get the right container with dummy data
    final RowSet.SingleRowSet nonEmptyRightRowSet2 = fixture.rowSetBuilder(rightSchema).addRow(1, 11, 110, "item11").addRow(4, 44, 440, "item44").build();
    final RowSet.SingleRowSet expectedRowSet = fixture.rowSetBuilder(expectedSchemaLeftJoin).addRow(1, 10, "item1", 11, 110, "item11").addRow(2, 20, "item2", null, null, null).addRow(3, 30, "item3", null, null, null).addRow(4, 40, "item4", 44, 440, "item44").build();
    rightContainer.add(emptyRightRowSet.container());
    rightContainer.add(nonEmptyRightRowSet2.container());
    rightOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    rightOutcomes.add(RecordBatch.IterOutcome.EMIT);
    final CloseableRecordBatch rightMockBatch = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, rightContainer, rightOutcomes, rightContainer.get(0).getSchema());
    LateralJoinPOP ljPopConfig = new LateralJoinPOP(null, null, JoinRelType.LEFT, DrillLateralJoinRelBase.IMPLICIT_COLUMN, Lists.newArrayList());
    final LateralJoinBatch ljBatch = new LateralJoinBatch(ljPopConfig, fixture.getFragmentContext(), leftMockBatch, rightMockBatch);
    try {
        assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == ljBatch.next());
        assertTrue(RecordBatch.IterOutcome.OK == ljBatch.next());
        assertTrue(ljBatch.getRecordCount() == nonEmptyLeftRowSet.rowCount());
        // verify results
        RowSet actualRowSet = DirectRowSet.fromContainer(ljBatch.getContainer());
        new RowSetComparison(expectedRowSet).verify(actualRowSet);
        assertTrue(RecordBatch.IterOutcome.NONE == ljBatch.next());
    } finally {
        // Close all the resources for this test case
        ljBatch.close();
        leftMockBatch.close();
        rightMockBatch.close();
        nonEmptyRightRowSet2.clear();
        expectedRowSet.clear();
    }
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) CloseableRecordBatch(org.apache.drill.exec.record.CloseableRecordBatch) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) LateralJoinPOP(org.apache.drill.exec.physical.config.LateralJoinPOP) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 72 with RowSetComparison

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

the class TestLateralJoinCorrectnessBatchProcessing method testLeftAndRightWithInitialMissingRows_MultipleBatch.

@Test
public void testLeftAndRightWithInitialMissingRows_MultipleBatch() throws Exception {
    leftContainer.add(nonEmptyLeftRowSet.container());
    // Get the left IterOutcomes for Lateral Join
    leftOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    // Create Left MockRecordBatch
    final CloseableRecordBatch leftMockBatch = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, leftContainer, leftOutcomes, leftContainer.get(0).getSchema());
    // Get the right container with dummy data
    final RowSet.SingleRowSet nonEmptyRightRowSet2 = fixture.rowSetBuilder(rightSchema).addRow(2, 22, 220, "item22").addRow(3, 33, 330, "item33").build();
    final RowSet.SingleRowSet nonEmptyRightRowSet3 = fixture.rowSetBuilder(rightSchema).addRow(4, 44, 440, "item44_1").addRow(4, 44, 440, "item44_2").build();
    final RowSet.SingleRowSet expectedRowSet = fixture.rowSetBuilder(expectedSchema).addRow(2, 20, "item2", 22, 220, "item22").addRow(3, 30, "item3", 33, 330, "item33").addRow(4, 40, "item4", 44, 440, "item44_1").addRow(4, 40, "item4", 44, 440, "item44_2").build();
    rightContainer.add(emptyRightRowSet.container());
    rightContainer.add(nonEmptyRightRowSet2.container());
    rightContainer.add(nonEmptyRightRowSet3.container());
    rightOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    rightOutcomes.add(RecordBatch.IterOutcome.OK);
    rightOutcomes.add(RecordBatch.IterOutcome.EMIT);
    final CloseableRecordBatch rightMockBatch = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, rightContainer, rightOutcomes, rightContainer.get(0).getSchema());
    final LateralJoinBatch ljBatch = new LateralJoinBatch(ljPopConfig, fixture.getFragmentContext(), leftMockBatch, rightMockBatch);
    try {
        assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == ljBatch.next());
        assertTrue(RecordBatch.IterOutcome.OK == ljBatch.next());
        assertTrue(ljBatch.getRecordCount() == (nonEmptyRightRowSet2.rowCount() + nonEmptyRightRowSet3.rowCount()));
        // verify results
        RowSet actualRowSet = DirectRowSet.fromContainer(ljBatch.getContainer());
        new RowSetComparison(expectedRowSet).verify(actualRowSet);
        assertTrue(RecordBatch.IterOutcome.NONE == ljBatch.next());
    } finally {
        // Close all the resources for this test case
        ljBatch.close();
        leftMockBatch.close();
        rightMockBatch.close();
        nonEmptyRightRowSet2.clear();
        expectedRowSet.clear();
    }
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) CloseableRecordBatch(org.apache.drill.exec.record.CloseableRecordBatch) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 73 with RowSetComparison

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

the class TestLateralJoinCorrectness method testExcludedColumns.

private void testExcludedColumns(List<SchemaPath> excludedCols, CloseableRecordBatch left, CloseableRecordBatch right, RowSet expectedRowSet) throws Exception {
    LateralJoinPOP lateralPop = new LateralJoinPOP(null, null, JoinRelType.INNER, DrillLateralJoinRelBase.IMPLICIT_COLUMN, excludedCols);
    final LateralJoinBatch ljBatch = new LateralJoinBatch(lateralPop, fixture.getFragmentContext(), left, right);
    try {
        assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == ljBatch.next());
        assertTrue(RecordBatch.IterOutcome.OK == ljBatch.next());
        RowSet actualRowSet = DirectRowSet.fromContainer(ljBatch.getContainer());
        new RowSetComparison(expectedRowSet).verify(actualRowSet);
        assertTrue(RecordBatch.IterOutcome.NONE == ljBatch.next());
    } finally {
        ljBatch.close();
        left.close();
        right.close();
        expectedRowSet.clear();
    }
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) LateralJoinPOP(org.apache.drill.exec.physical.config.LateralJoinPOP)

Example 74 with RowSetComparison

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

the class TestImageRecordReader method testExplicitQueryWithCompressedFile.

@Test
public void testExplicitQueryWithCompressedFile() throws Exception {
    cluster.defineFormat("dfs", "image", new ImageFormatConfig(Arrays.asList("jpg"), false, false, null));
    QueryTestUtil.generateCompressedFile("image/LearningApacheDrill.jpg", "zip", "store/image/LearningApacheDrill.jpg.zip");
    String sql = "select Format, PixelWidth, PixelHeight, `FileType` from dfs.`store/image/LearningApacheDrill.jpg.zip`";
    QueryBuilder builder = client.queryBuilder().sql(sql);
    RowSet sets = builder.rowSet();
    TupleMetadata schema = new SchemaBuilder().addNullable("Format", MinorType.VARCHAR).addNullable("PixelWidth", MinorType.INT).addNullable("PixelHeight", MinorType.INT).addMap("FileType").addNullable("DetectedFileTypeName", MinorType.VARCHAR).addNullable("DetectedFileTypeLongName", MinorType.VARCHAR).addNullable("DetectedMIMEType", MinorType.VARCHAR).addNullable("ExpectedFileNameExtension", MinorType.VARCHAR).resumeSchema().buildSchema();
    RowSet expected = new RowSetBuilder(client.allocator(), schema).addRow("JPEG", 800, 800, mapValue("JPEG", "Joint Photographic Experts Group", "image/jpeg", "jpg")).build();
    assertEquals(1, sets.rowCount());
    new RowSetComparison(expected).verifyAndClearAll(sets);
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) QueryBuilder(org.apache.drill.test.QueryBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 75 with RowSetComparison

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

the class TestImageRecordReader method testTimeZoneOption.

@Test
public void testTimeZoneOption() throws Exception {
    cluster.defineFormat("dfs", "image", new ImageFormatConfig(Arrays.asList("psd"), true, false, "UTC"));
    String sql = "select ExifIFD0 from dfs.`image/*.psd`";
    QueryBuilder builder = client.queryBuilder().sql(sql);
    RowSet sets = builder.rowSet();
    TupleMetadata schema = new SchemaBuilder().addMap("ExifIFD0").addNullable("Orientation", MinorType.INT).addNullable("XResolution", MinorType.FLOAT8).addNullable("YResolution", MinorType.FLOAT8).addNullable("ResolutionUnit", MinorType.INT).addNullable("Software", MinorType.VARCHAR).addNullable("DateTime", MinorType.TIMESTAMP).resumeSchema().build();
    RowSet expected = new RowSetBuilder(client.allocator(), schema).addRow(singleMap(mapValue(1, 72.009, 72.009, 2, "Adobe Photoshop CS2 Windows", Instant.ofEpochMilli(1454717337000L)))).build();
    new RowSetComparison(expected).verifyAndClearAll(sets);
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) QueryBuilder(org.apache.drill.test.QueryBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

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