Search in sources :

Example 31 with RowSet

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

the class TestResultSetLoaderUnions method testListofListofScalar.

/**
 * The semantics of the ListVector are such that it allows
 * multi-dimensional lists. In this way, it is like a (slightly
 * more normalized) version of the repeated list vector. This form
 * allows arrays to be null.
 * <p>
 * This test verifies that the (non-repeated) list vector can
 * be used to create multi-dimensional arrays in the result set
 * loader layer. However, the rest of Drill does not support this
 * functionality at present, so this test is more of a proof-of-
 * concept than a necessity.
 */
@Test
public void testListofListofScalar() {
    // JSON equivalent: {a: [[1, 2], [3, 4]]}
    final ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator());
    final RowSetLoader writer = rsLoader.writer();
    // Can write a batch as if this was a repeated Varchar, except
    // that any value can also be null.
    rsLoader.startBatch();
    writer.addColumn(MaterializedField.create("a", Types.optional(MinorType.LIST)));
    final ArrayWriter outerArray = writer.array("a");
    final VariantWriter outerVariant = outerArray.variant();
    outerVariant.addMember(MinorType.LIST);
    final ArrayWriter innerArray = outerVariant.array();
    final VariantWriter innerVariant = innerArray.variant();
    innerVariant.addMember(MinorType.INT);
    writer.addSingleCol(listValue(listValue(1, 2), listValue(3, 4)));
    final RowSet results = fixture.wrap(rsLoader.harvest());
    // Verify metadata
    final ListVector outer = (ListVector) results.container().getValueVector(0).getValueVector();
    final MajorType outerType = outer.getField().getType();
    assertEquals(1, outerType.getSubTypeCount());
    assertEquals(MinorType.LIST, outerType.getSubType(0));
    assertEquals(1, outer.getField().getChildren().size());
    final ListVector inner = (ListVector) outer.getDataVector();
    assertSame(inner.getField(), outer.getField().getChildren().iterator().next());
    final MajorType innerType = inner.getField().getType();
    assertEquals(1, innerType.getSubTypeCount());
    assertEquals(MinorType.INT, innerType.getSubType(0));
    assertEquals(1, inner.getField().getChildren().size());
    final ValueVector data = inner.getDataVector();
    assertSame(data.getField(), inner.getField().getChildren().iterator().next());
    assertEquals(MinorType.INT, data.getField().getType().getMinorType());
    assertEquals(DataMode.OPTIONAL, data.getField().getType().getMode());
    assertTrue(data instanceof NullableIntVector);
    // Note use of TupleMetadata: BatchSchema can't hold the
    // structure of a list.
    final TupleMetadata expectedSchema = new SchemaBuilder().addList("a").addList().addType(MinorType.INT).resumeUnion().resumeSchema().buildSchema();
    final RowSet expected = new RowSetBuilder(fixture.allocator(), expectedSchema).addSingleCol(listValue(listValue(1, 2), listValue(3, 4))).build();
    RowSetUtilities.verify(expected, results);
}
Also used : VariantWriter(org.apache.drill.exec.vector.accessor.VariantWriter) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) ValueVector(org.apache.drill.exec.vector.ValueVector) NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) ListVector(org.apache.drill.exec.vector.complex.ListVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) ArrayWriter(org.apache.drill.exec.vector.accessor.ArrayWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 32 with RowSet

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

the class TestResultSetLoaderDictArray method testDictValue.

@Test
public void testDictValue() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addDictArray("d", MinorType.VARCHAR).dictValue().key(MinorType.VARCHAR).value(MinorType.VARCHAR).resumeDict().resumeSchema().buildSchema();
    ResultSetLoaderImpl.ResultSetOptions options = new ResultSetOptionBuilder().readerSchema(schema).build();
    ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
    RowSetLoader rootWriter = rsLoader.writer();
    // Write a couple of rows
    rsLoader.startBatch();
    rootWriter.addRow(10, objArray(map("a", map("a", "a1", "b", "a2", "c", "a3"), "b", map("d", "a4"), "c", map()), map("b", map("b", "a2")))).addRow(20, objArray()).addRow(30, objArray(map("a", map("a", "b1", "b", "b1")), map("b", map("e", "b2"), "a", map("h", "b1", "g", "b3"), "c", map("a", "b4")), map("b", map("a", "b3", "c", "c3"), "a", map())));
    // Verify the batch
    RowSet actual = fixture.wrap(rsLoader.harvest());
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, objArray(map("a", map("a", "a1", "b", "a2", "c", "a3"), "b", map("d", "a4"), "c", map()), map("b", map("b", "a2")))).addRow(20, objArray()).addRow(30, objArray(map("a", map("a", "b1", "b", "b1")), map("b", map("e", "b2"), "a", map("h", "b1", "g", "b3"), "c", map("a", "b4")), map("b", map("a", "b3", "c", "c3"), "a", map()))).build();
    RowSetUtilities.verify(expected, actual);
    rsLoader.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) 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) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 33 with RowSet

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

the class TestResultSetLoaderMapArray method testBasics.

@Test
public void testBasics() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).add("d", MinorType.VARCHAR).resumeSchema().buildSchema();
    ResultSetLoaderImpl.ResultSetOptions options = new ResultSetOptionBuilder().readerSchema(schema).build();
    ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
    RowSetLoader rootWriter = rsLoader.writer();
    // Verify structure and schema
    TupleMetadata actualSchema = rootWriter.tupleSchema();
    assertEquals(2, actualSchema.size());
    assertTrue(actualSchema.metadata(1).isArray());
    assertTrue(actualSchema.metadata(1).isMap());
    assertEquals(2, actualSchema.metadata("m").tupleSchema().size());
    assertEquals(2, actualSchema.column("m").getChildren().size());
    TupleWriter mapWriter = rootWriter.array("m").tuple();
    assertSame(actualSchema.metadata("m").tupleSchema(), mapWriter.schema().tupleSchema());
    assertSame(mapWriter.tupleSchema(), mapWriter.schema().tupleSchema());
    assertSame(mapWriter.tupleSchema().metadata(0), mapWriter.scalar(0).schema());
    assertSame(mapWriter.tupleSchema().metadata(1), mapWriter.scalar(1).schema());
    // Write a couple of rows with arrays.
    rsLoader.startBatch();
    rootWriter.addRow(10, mapArray(mapValue(110, "d1.1"), mapValue(120, "d2.2"))).addRow(20, mapArray()).addRow(30, mapArray(mapValue(310, "d3.1"), mapValue(320, "d3.2"), mapValue(330, "d3.3")));
    // Verify the first batch
    RowSet actual = fixture.wrap(rsLoader.harvest());
    RepeatedMapVector mapVector = (RepeatedMapVector) actual.container().getValueVector(1).getValueVector();
    MaterializedField mapField = mapVector.getField();
    assertEquals(2, mapField.getChildren().size());
    Iterator<MaterializedField> iter = mapField.getChildren().iterator();
    assertTrue(mapWriter.scalar(0).schema().schema().isEquivalent(iter.next()));
    assertTrue(mapWriter.scalar(1).schema().schema().isEquivalent(iter.next()));
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, mapArray(mapValue(110, "d1.1"), mapValue(120, "d2.2"))).addRow(20, mapArray()).addRow(30, mapArray(mapValue(310, "d3.1"), mapValue(320, "d3.2"), mapValue(330, "d3.3"))).build();
    RowSetUtilities.verify(expected, actual);
    // In the second, create a row, then add a map member.
    // Should be back-filled to empty for the first row.
    rsLoader.startBatch();
    rootWriter.addRow(40, mapArray(mapValue(410, "d4.1"), mapValue(420, "d4.2")));
    mapWriter.addColumn(SchemaBuilder.columnSchema("e", MinorType.VARCHAR, DataMode.OPTIONAL));
    rootWriter.addRow(50, mapArray(mapValue(510, "d5.1", "e5.1"), mapValue(520, "d5.2", null))).addRow(60, mapArray(mapValue(610, "d6.1", "e6.1"), mapValue(620, "d6.2", null), mapValue(630, "d6.3", "e6.3")));
    // Verify the second batch
    actual = fixture.wrap(rsLoader.harvest());
    mapVector = (RepeatedMapVector) actual.container().getValueVector(1).getValueVector();
    mapField = mapVector.getField();
    assertEquals(3, mapField.getChildren().size());
    TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).add("d", MinorType.VARCHAR).addNullable("e", MinorType.VARCHAR).resumeSchema().buildSchema();
    expected = fixture.rowSetBuilder(expectedSchema).addRow(40, mapArray(mapValue(410, "d4.1", null), mapValue(420, "d4.2", null))).addRow(50, mapArray(mapValue(510, "d5.1", "e5.1"), mapValue(520, "d5.2", null))).addRow(60, mapArray(mapValue(610, "d6.1", "e6.1"), mapValue(620, "d6.2", null), mapValue(630, "d6.3", "e6.3"))).build();
    RowSetUtilities.verify(expected, actual);
    rsLoader.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) MaterializedField(org.apache.drill.exec.record.MaterializedField) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) TupleWriter(org.apache.drill.exec.vector.accessor.TupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 34 with RowSet

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

the class TestResultSetLoaderMapArray method testOmittedValues.

/**
 * Check that the "fill-empties" logic descends down into
 * a repeated map.
 */
@Test
public void testOmittedValues() {
    TupleMetadata schema = new SchemaBuilder().add("id", MinorType.INT).addMapArray("m").addNullable("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).resumeSchema().buildSchema();
    ResultSetLoaderImpl.ResultSetOptions options = new ResultSetOptionBuilder().readerSchema(schema).rowCountLimit(ValueVector.MAX_ROW_COUNT).build();
    ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
    RowSetLoader rootWriter = rsLoader.writer();
    int mapSkip = 5;
    int entrySkip = 3;
    int rowCount = 1000;
    int entryCount = 10;
    rsLoader.startBatch();
    ArrayWriter maWriter = rootWriter.array("m");
    TupleWriter mWriter = maWriter.tuple();
    for (int i = 0; i < rowCount; i++) {
        rootWriter.start();
        rootWriter.scalar(0).setInt(i);
        if (i % mapSkip != 0) {
            for (int j = 0; j < entryCount; j++) {
                if (j % entrySkip != 0) {
                    mWriter.scalar(0).setInt(i * entryCount + j);
                    mWriter.scalar(1).setString("b-" + i + "." + j);
                }
                maWriter.save();
            }
        }
        rootWriter.save();
    }
    RowSet result = fixture.wrap(rsLoader.harvest());
    assertEquals(rowCount, result.rowCount());
    RowSetReader reader = result.reader();
    ArrayReader maReader = reader.array("m");
    TupleReader mReader = maReader.tuple();
    for (int i = 0; i < rowCount; i++) {
        assertTrue(reader.next());
        assertEquals(i, reader.scalar(0).getInt());
        if (i % mapSkip == 0) {
            assertEquals(0, maReader.size());
            continue;
        }
        assertEquals(entryCount, maReader.size());
        for (int j = 0; j < entryCount; j++) {
            assertTrue(maReader.next());
            if (j % entrySkip == 0) {
                assertTrue(mReader.scalar(0).isNull());
                assertTrue(mReader.scalar(1).isNull());
            } else {
                assertFalse(mReader.scalar(0).isNull());
                assertFalse(mReader.scalar(1).isNull());
                assertEquals(i * entryCount + j, mReader.scalar(0).getInt());
                assertEquals("b-" + i + "." + j, mReader.scalar(1).getString());
            }
        }
    }
    result.clear();
    rsLoader.close();
}
Also used : TupleReader(org.apache.drill.exec.vector.accessor.TupleReader) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) TupleWriter(org.apache.drill.exec.vector.accessor.TupleWriter) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) ArrayWriter(org.apache.drill.exec.vector.accessor.ArrayWriter) RowSetReader(org.apache.drill.exec.physical.rowSet.RowSetReader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 35 with RowSet

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

the class TestResultSetLoaderMapArray method testNestedArray.

@Test
public void testNestedArray() {
    TupleMetadata schema = new SchemaBuilder().add("a", MinorType.INT).addMapArray("m").add("c", MinorType.INT).addArray("d", MinorType.VARCHAR).resumeSchema().buildSchema();
    ResultSetLoaderImpl.ResultSetOptions options = new ResultSetOptionBuilder().readerSchema(schema).build();
    ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator(), options);
    RowSetLoader rootWriter = rsLoader.writer();
    // Write a couple of rows with arrays within arrays.
    // (And, of course, the Varchar is actually an array of
    // bytes, so that's three array levels.)
    rsLoader.startBatch();
    rootWriter.addRow(10, mapArray(mapValue(110, strArray("d1.1.1", "d1.1.2")), mapValue(120, strArray("d1.2.1", "d1.2.2")))).addRow(20, mapArray()).addRow(30, mapArray(mapValue(310, strArray("d3.1.1", "d3.2.2")), mapValue(320, strArray()), mapValue(330, strArray("d3.3.1", "d1.2.2"))));
    // Verify the batch
    RowSet actual = fixture.wrap(rsLoader.harvest());
    SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(10, mapArray(mapValue(110, strArray("d1.1.1", "d1.1.2")), mapValue(120, strArray("d1.2.1", "d1.2.2")))).addRow(20, mapArray()).addRow(30, mapArray(mapValue(310, strArray("d3.1.1", "d3.2.2")), mapValue(320, strArray()), mapValue(330, strArray("d3.3.1", "d1.2.2")))).build();
    RowSetUtilities.verify(expected, actual);
    rsLoader.close();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) 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) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) SubOperatorTest(org.apache.drill.test.SubOperatorTest) 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