Search in sources :

Example 6 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestDirectConverter method testDecimalFromString.

@Test
public void testDecimalFromString() {
    TupleMetadata outputSchema = new SchemaBuilder().add("id", MinorType.INT).add("dec", MinorType.VARDECIMAL, 4, 2).buildSchema();
    TupleMetadata inputSchema = new SchemaBuilder().add("id", MinorType.INT).add("dec", MinorType.VARCHAR).buildSchema();
    ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
    testFixture.createConvertersFor(inputSchema);
    RowSet actual = testFixture.addRow(1, "0").addRow(2, "-0").addRow(3, "0.12").addRow(4, "1.23").addRow(5, "12.34").addRow(6, "23.456").addRow(7, "-99.99").build();
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(1, dec("0")).addRow(2, dec("-0")).addRow(3, dec("0.12")).addRow(4, dec("1.23")).addRow(5, dec("12.34")).addRow(6, dec("23.46")).addRow(7, dec("-99.99")).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 7 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestDirectConverter method testNumberToStringConversion.

/**
 * Test the standard string-to-type conversion using an ad-hoc conversion
 * from the input type (the type used by the row set builder) to the output
 * (vector) type.
 */
@Test
public void testNumberToStringConversion() {
    // Create the schema
    TupleMetadata outputSchema = new SchemaBuilder().add("ti", MinorType.VARCHAR).add("si", MinorType.VARCHAR).add("int", MinorType.VARCHAR).add("bi", MinorType.VARCHAR).add("fl", MinorType.VARCHAR).add("db", MinorType.VARCHAR).buildSchema();
    TupleMetadata inputSchema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).add("int", MinorType.INT).add("bi", MinorType.BIGINT).add("fl", MinorType.FLOAT4).add("db", MinorType.FLOAT8).buildSchema();
    // The setObject() method won't do the Float to Double conversion,
    // so values before are provided as doubles in the float case.
    ConversionTestFixture testFixture = new ConversionTestFixture(fixture.allocator(), outputSchema);
    testFixture.createConvertersFor(inputSchema);
    RowSet actual = testFixture.addRow(11, 12, 13, 14L, 15.5D, 16.25D).addRow(127, 32757, Integer.MAX_VALUE, Long.MAX_VALUE, 10E6D, 10E200D).build();
    // Build the expected vector without a type converter.
    final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow("11", "12", "13", "14", "15.5", "16.25").addRow("127", "32757", Integer.toString(Integer.MAX_VALUE), Long.toString(Long.MAX_VALUE), "1.0E7", "1.0E201").build();
    // Compare
    RowSetUtilities.verify(expected, actual);
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 8 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestScanBatchWriters method sanityTest.

@Test
public void sanityTest() throws Exception {
    Scan scanConfig = new AbstractSubScan("bob") {

        @Override
        public String getOperatorType() {
            return "";
        }
    };
    OperatorContext opContext = fixture.newOperatorContext(scanConfig);
    // Setup: normally done by ScanBatch
    VectorContainer container = new VectorContainer(fixture.allocator());
    OutputMutator output = new ScanBatch.Mutator(opContext, fixture.allocator(), container);
    DrillBuf buffer = opContext.getManagedBuffer();
    try (VectorContainerWriter writer = new VectorContainerWriter(output)) {
        // Per-batch
        writer.allocate();
        writer.reset();
        BaseWriter.MapWriter map = writer.rootAsMap();
        // Write one record (10, "Fred", [100, 110, 120] )
        map.integer("a").writeInt(10);
        byte[] bytes = "Fred".getBytes("UTF-8");
        buffer.setBytes(0, bytes, 0, bytes.length);
        map.varChar("b").writeVarChar(0, bytes.length, buffer);
        try (ListWriter list = map.list("c")) {
            list.startList();
            list.integer().writeInt(100);
            list.integer().writeInt(110);
            list.integer().writeInt(120);
            list.endList();
            // Write another record: (20, "Wilma", [])
            writer.setPosition(1);
            map.integer("a").writeInt(20);
            bytes = "Wilma".getBytes("UTF-8");
            buffer.setBytes(0, bytes, 0, bytes.length);
            map.varChar("b").writeVarChar(0, bytes.length, buffer);
            writer.setValueCount(2);
            // Wrap-up done by ScanBatch
            container.setRecordCount(2);
            container.buildSchema(SelectionVectorMode.NONE);
            RowSet rowSet = fixture.wrap(container);
            // Expected
            TupleMetadata schema = new SchemaBuilder().addNullable("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).addArray("c", MinorType.INT).buildSchema();
            RowSet expected = fixture.rowSetBuilder(schema).addRow(10, "Fred", new int[] { 100, 110, 120 }).addRow(20, "Wilma", null).build();
            new RowSetComparison(expected).verifyAndClearAll(rowSet);
        }
    } finally {
        opContext.close();
    }
}
Also used : AbstractSubScan(org.apache.drill.exec.physical.base.AbstractSubScan) VectorContainerWriter(org.apache.drill.exec.vector.complex.impl.VectorContainerWriter) BaseWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) OutputMutator(org.apache.drill.exec.physical.impl.OutputMutator) VectorContainer(org.apache.drill.exec.record.VectorContainer) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) OutputMutator(org.apache.drill.exec.physical.impl.OutputMutator) OperatorContext(org.apache.drill.exec.ops.OperatorContext) ListWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Scan(org.apache.drill.exec.physical.base.Scan) AbstractSubScan(org.apache.drill.exec.physical.base.AbstractSubScan) DrillBuf(io.netty.buffer.DrillBuf) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 9 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestSequenceFileReader method testLimitPushdown.

@Test
public void testLimitPushdown() throws Exception {
    String sql = "select * from cp.`sequencefiles/simple.seq` limit 1 offset 1";
    QueryBuilder builder = client.queryBuilder().sql(sql);
    RowSet sets = builder.rowSet();
    assertEquals(1, sets.rowCount());
    sets.clear();
}
Also used : RowSet(org.apache.drill.exec.physical.rowSet.RowSet) QueryBuilder(org.apache.drill.test.QueryBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 10 with RowSet

use of org.apache.drill.exec.physical.rowSet.RowSet in project drill by apache.

the class TestSequenceFileReader method testExplicitQuery.

@Test
public void testExplicitQuery() throws Exception {
    String sql = "select convert_from(binary_key, 'UTF8') as binary_key from cp.`sequencefiles/simple.seq`";
    QueryBuilder builder = client.queryBuilder().sql(sql);
    RowSet sets = builder.rowSet();
    TupleMetadata schema = new SchemaBuilder().addNullable(SequenceFileBatchReader.KEY_SCHEMA, MinorType.VARCHAR).build();
    RowSet expected = new RowSetBuilder(client.allocator(), schema).addRow(byteWritableString("key0")).addRow(byteWritableString("key1")).build();
    assertEquals(2, 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)

Aggregations

RowSet (org.apache.drill.exec.physical.rowSet.RowSet)725 Test (org.junit.Test)690 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)583 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)574 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)297 ClusterTest (org.apache.drill.test.ClusterTest)253 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)233 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)137 SubOperatorTest (org.apache.drill.test.SubOperatorTest)128 JsonTest (org.apache.drill.categories.JsonTest)112 EvfTest (org.apache.drill.categories.EvfTest)107 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)97 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)63 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)61 QueryBuilder (org.apache.drill.test.QueryBuilder)61 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)60 OperatorTest (org.apache.drill.categories.OperatorTest)53 VectorContainer (org.apache.drill.exec.record.VectorContainer)31 RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)28 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)27