Search in sources :

Example 11 with RowSetComparison

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

the class TestCsv method testCsvHeadersCaseInsensitive.

// Test fix for DRILL-5590
@Test
public void testCsvHeadersCaseInsensitive() throws IOException {
    String fileName = "case2.csv";
    buildFile(fileName, validHeaders);
    String sql = "SELECT A, b, C FROM `dfs.data`.`%s`";
    RowSet actual = client.queryBuilder().sql(sql, fileName).rowSet();
    BatchSchema expectedSchema = new SchemaBuilder().add("A", MinorType.VARCHAR).add("b", MinorType.VARCHAR).add("C", MinorType.VARCHAR).build();
    assertTrue(expectedSchema.isEquivalent(actual.batchSchema()));
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("10", "foo", "bar").build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BatchSchema(org.apache.drill.exec.record.BatchSchema) RowSet(org.apache.drill.test.rowSet.RowSet) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 12 with RowSetComparison

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

the class TestCsv method testValidCsvHeaders.

@Test
public void testValidCsvHeaders() throws IOException {
    String fileName = "case2.csv";
    buildFile(fileName, validHeaders);
    RowSet actual = client.queryBuilder().sql(makeStatement(fileName)).rowSet();
    BatchSchema expectedSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).add("b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).build();
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("10", "foo", "bar").build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
}
Also used : RowSetBuilder(org.apache.drill.test.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BatchSchema(org.apache.drill.exec.record.BatchSchema) RowSet(org.apache.drill.test.rowSet.RowSet) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 13 with RowSetComparison

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

the class RowSetTest method testMapStructure.

/**
 * Test a simple map structure at the top level of a row.
 *
 * @throws VectorOverflowException should never occur
 */
@Test
public void testMapStructure() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMap("m").addArray("b", MinorType.INT).resumeSchema().buildSchema();
    ExtendableRowSet rowSet = fixture.rowSet(schema);
    RowSetWriter writer = rowSet.writer();
    // Map and Int
    // Test Invariants
    assertEquals(ObjectType.SCALAR, writer.column("a").type());
    assertEquals(ObjectType.SCALAR, writer.column(0).type());
    assertEquals(ObjectType.TUPLE, writer.column("m").type());
    assertEquals(ObjectType.TUPLE, writer.column(1).type());
    assertSame(writer.column(1).tuple(), writer.tuple(1));
    TupleWriter mapWriter = writer.column(1).tuple();
    assertEquals(ObjectType.SCALAR, mapWriter.column("b").array().entry().type());
    assertEquals(ObjectType.SCALAR, mapWriter.column("b").array().entryType());
    ScalarWriter aWriter = writer.column("a").scalar();
    ScalarWriter bWriter = writer.column("m").tuple().column("b").array().entry().scalar();
    assertSame(bWriter, writer.tuple(1).array(0).scalar());
    assertEquals(ValueType.INTEGER, bWriter.valueType());
    try {
        writer.column(1).scalar();
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    try {
        writer.column(1).array();
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    // Write data
    aWriter.setInt(10);
    bWriter.setInt(11);
    bWriter.setInt(12);
    writer.save();
    aWriter.setInt(20);
    bWriter.setInt(21);
    bWriter.setInt(22);
    writer.save();
    aWriter.setInt(30);
    bWriter.setInt(31);
    bWriter.setInt(32);
    writer.save();
    // Finish the row set and get a reader.
    SingleRowSet actual = writer.done();
    RowSetReader reader = actual.reader();
    assertEquals(ObjectType.SCALAR, reader.column("a").type());
    assertEquals(ObjectType.SCALAR, reader.column(0).type());
    assertEquals(ObjectType.TUPLE, reader.column("m").type());
    assertEquals(ObjectType.TUPLE, reader.column(1).type());
    assertSame(reader.column(1).tuple(), reader.tuple(1));
    ScalarReader aReader = reader.column(0).scalar();
    TupleReader mReader = reader.column(1).tuple();
    assertEquals(ObjectType.SCALAR, mReader.column("b").array().entryType());
    ScalarElementReader bReader = mReader.column(0).elements();
    assertEquals(ValueType.INTEGER, bReader.valueType());
    assertTrue(reader.next());
    assertEquals(10, aReader.getInt());
    assertEquals(11, bReader.getInt(0));
    assertEquals(12, bReader.getInt(1));
    assertTrue(reader.next());
    assertEquals(20, aReader.getInt());
    assertEquals(21, bReader.getInt(0));
    assertEquals(22, bReader.getInt(1));
    assertTrue(reader.next());
    assertEquals(30, aReader.getInt());
    assertEquals(31, bReader.getInt(0));
    assertEquals(32, bReader.getInt(1));
    assertFalse(reader.next());
    // Verify that the map accessor's value count was set.
    @SuppressWarnings("resource") MapVector mapVector = (MapVector) actual.container().getValueVector(1).getValueVector();
    assertEquals(actual.rowCount(), mapVector.getAccessor().getValueCount());
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray(intArray(11, 12))).addRow(20, objArray(intArray(21, 22))).addRow(30, objArray(intArray(31, 32))).build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) TupleReader(org.apache.drill.exec.vector.accessor.TupleReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) ScalarElementReader(org.apache.drill.exec.vector.accessor.ScalarElementReader) ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) TupleWriter(org.apache.drill.exec.vector.accessor.TupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) MapVector(org.apache.drill.exec.vector.complex.MapVector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 14 with RowSetComparison

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

the class RowSetTest method testRepeatedMapStructure.

@Test
public void testRepeatedMapStructure() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("b", MinorType.INT).add("c", MinorType.INT).resumeSchema().buildSchema();
    ExtendableRowSet rowSet = fixture.rowSet(schema);
    RowSetWriter writer = rowSet.writer();
    // Map and Int
    // Pick out components and lightly test. (Assumes structure
    // tested earlier is still valid, so no need to exhaustively
    // test again.)
    assertEquals(ObjectType.SCALAR, writer.column("a").type());
    assertEquals(ObjectType.ARRAY, writer.column("m").type());
    ArrayWriter maWriter = writer.column(1).array();
    assertEquals(ObjectType.TUPLE, maWriter.entryType());
    TupleWriter mapWriter = maWriter.tuple();
    assertEquals(ObjectType.SCALAR, mapWriter.column("b").type());
    assertEquals(ObjectType.SCALAR, mapWriter.column("c").type());
    ScalarWriter aWriter = writer.column("a").scalar();
    ScalarWriter bWriter = mapWriter.scalar("b");
    ScalarWriter cWriter = mapWriter.scalar("c");
    assertEquals(ValueType.INTEGER, aWriter.valueType());
    assertEquals(ValueType.INTEGER, bWriter.valueType());
    assertEquals(ValueType.INTEGER, cWriter.valueType());
    // Write data
    aWriter.setInt(10);
    bWriter.setInt(101);
    cWriter.setInt(102);
    // Advance to next array position
    maWriter.save();
    bWriter.setInt(111);
    cWriter.setInt(112);
    maWriter.save();
    writer.save();
    aWriter.setInt(20);
    bWriter.setInt(201);
    cWriter.setInt(202);
    maWriter.save();
    bWriter.setInt(211);
    cWriter.setInt(212);
    maWriter.save();
    writer.save();
    aWriter.setInt(30);
    bWriter.setInt(301);
    cWriter.setInt(302);
    maWriter.save();
    bWriter.setInt(311);
    cWriter.setInt(312);
    maWriter.save();
    writer.save();
    // Finish the row set and get a reader.
    SingleRowSet actual = writer.done();
    RowSetReader reader = actual.reader();
    // Verify reader structure
    assertEquals(ObjectType.SCALAR, reader.column("a").type());
    assertEquals(ObjectType.ARRAY, reader.column("m").type());
    ArrayReader maReader = reader.column(1).array();
    assertEquals(ObjectType.TUPLE, maReader.entryType());
    TupleReader mapReader = maReader.tuple();
    assertEquals(ObjectType.SCALAR, mapReader.column("b").type());
    assertEquals(ObjectType.SCALAR, mapReader.column("c").type());
    ScalarReader aReader = reader.column("a").scalar();
    ScalarReader bReader = mapReader.scalar("b");
    ScalarReader cReader = mapReader.scalar("c");
    assertEquals(ValueType.INTEGER, aReader.valueType());
    assertEquals(ValueType.INTEGER, bReader.valueType());
    assertEquals(ValueType.INTEGER, cReader.valueType());
    // Row 1: use index accessors
    assertTrue(reader.next());
    assertEquals(10, aReader.getInt());
    TupleReader ixReader = maReader.tuple(0);
    assertEquals(101, ixReader.scalar(0).getInt());
    assertEquals(102, ixReader.scalar(1).getInt());
    ixReader = maReader.tuple(1);
    assertEquals(111, ixReader.scalar(0).getInt());
    assertEquals(112, ixReader.scalar(1).getInt());
    // Row 2: use common accessor with explicit positioning,
    // but access scalars through the map reader.
    assertTrue(reader.next());
    assertEquals(20, aReader.getInt());
    maReader.setPosn(0);
    assertEquals(201, mapReader.scalar(0).getInt());
    assertEquals(202, mapReader.scalar(1).getInt());
    maReader.setPosn(1);
    assertEquals(211, mapReader.scalar(0).getInt());
    assertEquals(212, mapReader.scalar(1).getInt());
    // Row 3: use common accessor for scalars
    assertTrue(reader.next());
    assertEquals(30, aReader.getInt());
    maReader.setPosn(0);
    assertEquals(301, bReader.getInt());
    assertEquals(302, cReader.getInt());
    maReader.setPosn(1);
    assertEquals(311, bReader.getInt());
    assertEquals(312, cReader.getInt());
    assertFalse(reader.next());
    // Verify that the map accessor's value count was set.
    @SuppressWarnings("resource") RepeatedMapVector mapVector = (RepeatedMapVector) actual.container().getValueVector(1).getValueVector();
    assertEquals(3, mapVector.getAccessor().getValueCount());
    // Verify the readers and writers again using the testing tools.
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray(objArray(101, 102), objArray(111, 112))).addRow(20, objArray(objArray(201, 202), objArray(211, 212))).addRow(30, objArray(objArray(301, 302), objArray(311, 312))).build();
    new RowSetComparison(expected).verifyAndClearAll(actual);
}
Also used : RowSetWriter(org.apache.drill.test.rowSet.RowSetWriter) TupleReader(org.apache.drill.exec.vector.accessor.TupleReader) SingleRowSet(org.apache.drill.test.rowSet.RowSet.SingleRowSet) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) TupleWriter(org.apache.drill.exec.vector.accessor.TupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) ArrayWriter(org.apache.drill.exec.vector.accessor.ArrayWriter) RowSetReader(org.apache.drill.test.rowSet.RowSetReader) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.test.rowSet.RowSet.ExtendableRowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 15 with RowSetComparison

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

the class TestScanOrchestratorLateSchema method testLateSchemaSelectDisjoint.

/**
 * Test SELECT a, c FROM table(a, b)
 */
@Test
public void testLateSchemaSelectDisjoint() {
    ScanOrchestratorBuilder builder = new MockScanBuilder();
    // SELECT a, c ...
    builder.projection(RowSetTestUtils.projectList("a", "c"));
    ScanSchemaOrchestrator orchestrator = new ScanSchemaOrchestrator(fixture.allocator(), builder);
    // ... FROM file
    ReaderSchemaOrchestrator reader = orchestrator.startReader();
    // Create the table loader
    ResultSetLoader loader = reader.makeTableLoader(null);
    // file schema (a, b)
    reader.startBatch();
    RowSetLoader writer = loader.writer();
    writer.addColumn(SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.REQUIRED));
    writer.addColumn(SchemaBuilder.columnSchema("b", MinorType.VARCHAR, DataMode.REQUIRED));
    // Create a batch of data.
    writer.addRow(1, "fred").addRow(2, "wilma");
    reader.endBatch();
    // Verify
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addNullable("c", MinorType.INT).buildSchema();
    SingleRowSet expected = fixture.rowSetBuilder(expectedSchema).addRow(1, null).addRow(2, null).build();
    new RowSetComparison(expected).verifyAndClearAll(fixture.wrap(orchestrator.output()));
    orchestrator.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) ScanOrchestratorBuilder(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator.ScanOrchestratorBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) MockScanBuilder(org.apache.drill.exec.physical.impl.scan.ScanTestUtils.MockScanBuilder) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) ScanSchemaOrchestrator(org.apache.drill.exec.physical.impl.scan.project.ScanSchemaOrchestrator) ReaderSchemaOrchestrator(org.apache.drill.exec.physical.impl.scan.project.ReaderSchemaOrchestrator) SubOperatorTest(org.apache.drill.test.SubOperatorTest) 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