Search in sources :

Example 31 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestResultSetLoaderOverflow method testSizeLimitOnArray.

/**
 * Test a row with a single array column which overflows. Verifies
 * that all the fiddly bits about offset vectors and so on works
 * correctly. Run this test (the simplest case) if you change anything
 * about the array handling code.
 */
@Test
public void testSizeLimitOnArray() {
    TupleMetadata schema = new SchemaBuilder().addArray("s", MinorType.VARCHAR).buildSchema();
    ResultSetOptions options = new ResultSetOptionBuilder().rowCountLimit(ValueVector.MAX_ROW_COUNT).readerSchema(schema).build();
    ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
    RowSetLoader rootWriter = rsLoader.writer();
    // Fill batch with rows of with a single array, three values each. Tack on
    // a suffix to each so we can be sure the proper data is written and moved
    // to the overflow batch.
    rsLoader.startBatch();
    byte[] value = new byte[473];
    Arrays.fill(value, (byte) 'X');
    String strValue = new String(value, Charsets.UTF_8);
    int valuesPerArray = 13;
    int count = 0;
    {
        int rowSize = 0;
        int totalSize = 0;
        while (rootWriter.start()) {
            totalSize += rowSize;
            rowSize = 0;
            ScalarWriter array = rootWriter.array(0).scalar();
            for (int i = 0; i < valuesPerArray; i++) {
                String cellValue = strValue + (count + 1) + "." + i;
                array.setString(cellValue);
                rowSize += cellValue.length();
            }
            rootWriter.save();
            count++;
        }
        // Row count should include the overflow row.
        int expectedCount = count - 1;
        // Size without overflow row should fit in the vector, size
        // with overflow should not.
        assertTrue(totalSize <= ValueVector.MAX_BUFFER_SIZE);
        assertTrue(totalSize + rowSize > ValueVector.MAX_BUFFER_SIZE);
        // Result should exclude the overflow row. Last row
        // should hold the last full array.
        VectorContainer container = rsLoader.harvest();
        BatchValidator.validate(container);
        RowSet result = fixture.wrap(container);
        assertEquals(expectedCount, result.rowCount());
        RowSetReader reader = result.reader();
        reader.setPosition(expectedCount - 1);
        ArrayReader arrayReader = reader.array(0);
        ScalarReader strReader = arrayReader.scalar();
        assertEquals(valuesPerArray, arrayReader.size());
        for (int i = 0; i < valuesPerArray; i++) {
            assertTrue(arrayReader.next());
            String cellValue = strValue + (count - 1) + "." + i;
            assertEquals(cellValue, strReader.getString());
        }
        result.clear();
    }
    // Next batch should start with the overflow row.
    // The only row in this next batch should be the whole
    // array being written at the time of overflow.
    {
        rsLoader.startBatch();
        assertEquals(1, rootWriter.rowCount());
        assertEquals(count, rsLoader.totalRowCount());
        VectorContainer container = rsLoader.harvest();
        BatchValidator.validate(container);
        RowSet result = fixture.wrap(container);
        assertEquals(1, result.rowCount());
        RowSetReader reader = result.reader();
        reader.next();
        ArrayReader arrayReader = reader.array(0);
        ScalarReader strReader = arrayReader.scalar();
        assertEquals(valuesPerArray, arrayReader.size());
        for (int i = 0; i < valuesPerArray; i++) {
            assertTrue(arrayReader.next());
            String cellValue = strValue + count + "." + i;
            assertEquals(cellValue, strReader.getString());
        }
        result.clear();
    }
    rsLoader.close();
}
Also used : RowSet(org.apache.drill.exec.physical.rowSet.RowSet) ResultSetOptions(org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions) VectorContainer(org.apache.drill.exec.record.VectorContainer) ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) RowSetReader(org.apache.drill.exec.physical.rowSet.RowSetReader) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 32 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestScalarAccessors method testUInt2RW.

@Test
public void testUInt2RW() {
    TupleMetadata schema = new SchemaBuilder().add("col", MinorType.UINT2).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(0).addRow(0x7FFF).addRow(0xFFFF).build();
    assertEquals(3, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertEquals(ValueType.INTEGER, colReader.valueType());
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(0, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(0x7FFF, colReader.getInt());
    assertEquals(0x7FFF, colReader.getObject());
    assertEquals(Integer.toString(0x7FFF), colReader.getAsString());
    assertTrue(reader.next());
    assertEquals(0xFFFF, colReader.getInt());
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) 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) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 33 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestScalarAccessors method nullableIntTester.

private void nullableIntTester(MinorType type) {
    TupleMetadata schema = new SchemaBuilder().addNullable("col", type).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(10).addSingleCol(null).addRow(30).build();
    assertEquals(3, rs.rowCount());
    // Verify vector state
    VectorContainer container = rs.container();
    assertEquals(1, container.getNumberOfColumns());
    ValueVector v = container.getValueVector(0).getValueVector();
    assertTrue(v instanceof NullableVector);
    NullableVector nv = (NullableVector) v;
    assertEquals(3, nv.getAccessor().getValueCount());
    assertEquals(3 * BasicTypeHelper.getSize(Types.required(type)), ((BaseDataValueVector) v).getBuffer().writerIndex());
    // Verify bits vector. (Assumes UInt1 implementation.)
    UInt1Vector bv = (UInt1Vector) nv.getBitsVector();
    assertEquals(3, bv.getAccessor().getValueCount());
    assertEquals(3, bv.getBuffer().writerIndex());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(10, colReader.getInt());
    assertTrue(reader.next());
    assertTrue(colReader.isNull());
    assertNull(colReader.getObject());
    assertEquals("null", colReader.getAsString());
    // Data value is undefined, may be garbage
    assertTrue(reader.next());
    assertEquals(30, colReader.getInt());
    assertFalse(reader.next());
    rs.clear();
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) 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) NullableVector(org.apache.drill.exec.vector.NullableVector) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) UInt1Vector(org.apache.drill.exec.vector.UInt1Vector) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 34 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestScalarAccessors method testBitRW.

@Test
public void testBitRW() {
    TupleMetadata schema = new SchemaBuilder().add("col", MinorType.BIT).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addSingleCol(true).addSingleCol(false).addSingleCol(0).addSingleCol(1).addSingleCol(2).addSingleCol(3).build();
    assertEquals(6, rs.rowCount());
    // Verify vector state
    VectorContainer container = rs.container();
    assertEquals(1, container.getNumberOfColumns());
    ValueVector v = container.getValueVector(0).getValueVector();
    assertTrue(v instanceof BitVector);
    BitVector bv = (BitVector) v;
    assertEquals(6, bv.getAccessor().getValueCount());
    assertEquals(1, ((BaseDataValueVector) v).getBuffer().writerIndex());
    // Verify using a reader
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertTrue(reader.next());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(false, colReader.getBoolean());
    assertEquals(0, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(false, colReader.getBoolean());
    assertEquals(0, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    assertTrue(reader.next());
    assertEquals(true, colReader.getBoolean());
    assertEquals(1, colReader.getInt());
    assertFalse(reader.next());
    rs.clear();
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) BitVector(org.apache.drill.exec.vector.BitVector) NullableBitVector(org.apache.drill.exec.vector.NullableBitVector) 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) BaseDataValueVector(org.apache.drill.exec.vector.BaseDataValueVector) VectorContainer(org.apache.drill.exec.record.VectorContainer) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 35 with ScalarReader

use of org.apache.drill.exec.vector.accessor.ScalarReader in project drill by apache.

the class TestScalarAccessors method testFloatRW.

@Test
public void testFloatRW() {
    TupleMetadata schema = new SchemaBuilder().add("col", MinorType.FLOAT4).buildSchema();
    SingleRowSet rs = fixture.rowSetBuilder(schema).addRow(0F).addRow(Float.MAX_VALUE).addRow(Float.MIN_VALUE).addRow(100F).build();
    assertEquals(4, rs.rowCount());
    RowSetReader reader = rs.reader();
    ScalarReader colReader = reader.scalar(0);
    assertEquals(ValueType.FLOAT, colReader.valueType());
    assertTrue(reader.next());
    assertFalse(colReader.isNull());
    assertEquals(0, colReader.getFloat(), 0.000001);
    assertTrue(reader.next());
    assertEquals(Float.MAX_VALUE, colReader.getFloat(), 0.000001);
    assertEquals(Float.MAX_VALUE, (float) colReader.getObject(), 0.000001);
    assertTrue(reader.next());
    assertEquals(Float.MIN_VALUE, colReader.getFloat(), 0.000001);
    assertTrue(reader.next());
    assertEquals(100, colReader.getFloat(), 0.000001);
    assertEquals("100.0", colReader.getAsString());
    assertFalse(reader.next());
    rs.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) 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) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)97 SubOperatorTest (org.apache.drill.test.SubOperatorTest)78 Test (org.junit.Test)78 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)72 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)68 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)65 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)31 ArrayReader (org.apache.drill.exec.vector.accessor.ArrayReader)29 RowSetReader (org.apache.drill.test.rowSet.RowSetReader)27 SingleRowSet (org.apache.drill.test.rowSet.RowSet.SingleRowSet)26 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)26 BatchSchema (org.apache.drill.exec.record.BatchSchema)22 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)19 Period (org.joda.time.Period)15 ArrayWriter (org.apache.drill.exec.vector.accessor.ArrayWriter)13 TupleReader (org.apache.drill.exec.vector.accessor.TupleReader)10 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)10 VectorContainer (org.apache.drill.exec.record.VectorContainer)9 BigDecimal (java.math.BigDecimal)7 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)7