Search in sources :

Example 1 with ExtendableRowSet

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

the class TestFillEmpties method testBitDefaultValue.

@Test
public void testBitDefaultValue() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.BIT).buildSchema();
    ExtendableRowSet rs = fixture.rowSet(schema);
    RowSetWriter writer = rs.writer();
    ScalarWriter colWriter = writer.scalar(0);
    colWriter.setDefaultValue(true);
    for (int i = 0; i < ROW_COUNT; i++) {
        if (i % 43 == 0) {
            colWriter.setInt(0);
        }
        writer.save();
    }
    SingleRowSet result = writer.done();
    RowSetReader reader = result.reader();
    ScalarReader colReader = reader.scalar(0);
    for (int i = 0; i < ROW_COUNT; i++) {
        assertTrue(reader.next());
        assertEquals(i % 43 == 0 ? 0 : 1, colReader.getInt());
    }
    result.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) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 2 with ExtendableRowSet

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

the class TestFillEmpties method testDefaultInSchema.

/**
 * Test the more typical case in which the default value is set in the
 * column metadata. The reader mechanism will automatically set the default
 * for the column writer from the (properly formed) default value in the
 * column metadata.
 */
@Test
public void testDefaultInSchema() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
    schema.metadata("a").setDefaultValue("11");
    ExtendableRowSet rs = fixture.rowSet(schema);
    RowSetWriter writer = rs.writer();
    ScalarWriter colWriter = writer.scalar(0);
    ValueType valueType = colWriter.extendedType();
    for (int i = 0; i < ROW_COUNT; i++) {
        if (i % 5 == 0) {
            colWriter.setInt(i);
        }
        writer.save();
    }
    SingleRowSet result = writer.done();
    RowSetReader reader = result.reader();
    ScalarReader colReader = reader.scalar(0);
    Object defaultValue = schema.metadata("a").decodeDefaultValue();
    assertNotNull(defaultValue);
    for (int i = 0; i < ROW_COUNT; i++) {
        assertTrue(reader.next());
        Object actual = colReader.getValue();
        Object expected = i % 5 == 0 ? i : defaultValue;
        RowSetUtilities.assertEqualValues(MinorType.INT.toString() + "[" + i + "]", valueType, expected, actual);
    }
    result.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ValueType(org.apache.drill.exec.vector.accessor.ValueType) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 3 with ExtendableRowSet

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

the class TestFillEmpties method dofillEmptiesRepeated.

private void dofillEmptiesRepeated(MajorType majorType) {
    TupleMetadata schema = new SchemaBuilder().add("a", majorType).buildSchema();
    ExtendableRowSet rs = fixture.rowSet(schema);
    RowSetWriter writer = rs.writer();
    ScalarWriter colWriter = writer.array(0).scalar();
    ValueType valueType = colWriter.valueType();
    for (int i = 0; i < ROW_COUNT; i++) {
        if (i % 5 == 0) {
            // Write two values so we can exercise a bit of the array logic.
            colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i));
            colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i + 1));
        }
        writer.save();
    }
    SingleRowSet result = writer.done();
    RowSetReader reader = result.reader();
    ArrayReader aReader = reader.array(0);
    ScalarReader colReader = aReader.scalar();
    for (int i = 0; i < ROW_COUNT; i++) {
        assertTrue(reader.next());
        if (i % 5 != 0) {
            // Empty arrays are defined to be the same as a zero-length array.
            assertEquals(0, aReader.size());
        } else {
            for (int j = 0; j < 2; j++) {
                assertTrue(aReader.next());
                Object actual = colReader.getObject();
                Object expected = RowSetUtilities.testDataFromInt(valueType, majorType, i + j);
                RowSetUtilities.assertEqualValues(majorType.toString().replace('\n', ' ') + "[" + i + "][" + j + "]", valueType, expected, actual);
            }
        }
    }
    result.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ValueType(org.apache.drill.exec.vector.accessor.ValueType) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)

Example 4 with ExtendableRowSet

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

the class TestFillEmpties method testInvalidDefault.

@Test
public void testInvalidDefault() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).buildSchema();
    schema.metadata("a").setDefaultValue("bogus");
    ExtendableRowSet rs = fixture.rowSet(schema);
    try {
        rs.writer();
        fail();
    } catch (IllegalArgumentException e) {
    // Expected
    }
    rs.clear();
}
Also used : TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 5 with ExtendableRowSet

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

the class TestFillEmpties method doTestDefaultValue.

private void doTestDefaultValue(MajorType majorType) {
    TupleMetadata schema = new SchemaBuilder().add("a", majorType).buildSchema();
    ExtendableRowSet rs = fixture.rowSet(schema);
    RowSetWriter writer = rs.writer();
    ScalarWriter colWriter = writer.scalar(0);
    ValueType valueType = colWriter.extendedType();
    Object defaultValue = RowSetUtilities.testDataFromInt(valueType, majorType, 100);
    colWriter.setDefaultValue(defaultValue);
    for (int i = 0; i < ROW_COUNT; i++) {
        if (i % 5 == 0) {
            colWriter.setObject(RowSetUtilities.testDataFromInt(valueType, majorType, i));
        }
        writer.save();
    }
    SingleRowSet result = writer.done();
    RowSetReader reader = result.reader();
    ScalarReader colReader = reader.scalar(0);
    for (int i = 0; i < ROW_COUNT; i++) {
        assertTrue(reader.next());
        Object actual = colReader.getValue();
        Object expected = i % 5 == 0 ? RowSetUtilities.testDataFromInt(valueType, majorType, i) : defaultValue;
        RowSetUtilities.assertEqualValues(majorType.toString().replace('\n', ' ') + "[" + i + "]", valueType, expected, actual);
    }
    result.clear();
}
Also used : ScalarReader(org.apache.drill.exec.vector.accessor.ScalarReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ValueType(org.apache.drill.exec.vector.accessor.ValueType) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) ExtendableRowSet(org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)

Aggregations

ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)34 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)31 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)31 SubOperatorTest (org.apache.drill.test.SubOperatorTest)27 Test (org.junit.Test)27 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)24 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)19 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)19 ArrayReader (org.apache.drill.exec.vector.accessor.ArrayReader)11 ArrayWriter (org.apache.drill.exec.vector.accessor.ArrayWriter)7 ObjectReader (org.apache.drill.exec.vector.accessor.ObjectReader)6 ObjectWriter (org.apache.drill.exec.vector.accessor.ObjectWriter)6 TupleReader (org.apache.drill.exec.vector.accessor.TupleReader)5 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)5 VariantReader (org.apache.drill.exec.vector.accessor.VariantReader)5 VariantWriter (org.apache.drill.exec.vector.accessor.VariantWriter)5 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)4 RowSetWriter (org.apache.drill.exec.physical.rowSet.RowSetWriter)4 ValueType (org.apache.drill.exec.vector.accessor.ValueType)4 VectorContainer (org.apache.drill.exec.record.VectorContainer)3