Search in sources :

Example 1 with RepeatedListColumnMetadata

use of org.apache.drill.exec.record.metadata.RepeatedListColumnMetadata in project drill by apache.

the class RepeatedListState method addColumn.

@Override
protected void addColumn(ColumnState colState) {
    // Remember the one and only child column.
    assert childState == null;
    childState = colState;
    // Add the new child schema to the existing repeated list
    // schema.
    ((RepeatedListColumnMetadata) parentColumn.schema()).childSchema(colState.schema());
    // Add the child vector to the existing repeated list
    // vector.
    final RepeatedListVectorState vectorState = (RepeatedListVectorState) parentColumn.vectorState();
    final RepeatedListVector listVector = vectorState.vector;
    listVector.setChildVector(childState.vector());
    // The repeated list's offset vector state needs to know the offset
    // of the inner vector. Bind that information now that we have
    // an inner writer.
    vectorState.updateChildWriter(childState.writer());
}
Also used : RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) RepeatedListColumnMetadata(org.apache.drill.exec.record.metadata.RepeatedListColumnMetadata)

Example 2 with RepeatedListColumnMetadata

use of org.apache.drill.exec.record.metadata.RepeatedListColumnMetadata in project drill by apache.

the class TestResultSetLoaderRepeatedList method do2DTest.

private void do2DTest(TupleMetadata schema, ResultSetLoader rsLoader) {
    final RowSetLoader writer = rsLoader.writer();
    // Sanity check of writer structure
    assertEquals(2, writer.size());
    final ObjectWriter listObj = writer.column("list2");
    assertEquals(ObjectType.ARRAY, listObj.type());
    final ArrayWriter listWriter = listObj.array();
    assertEquals(ObjectType.ARRAY, listWriter.entryType());
    final ArrayWriter innerWriter = listWriter.array();
    assertEquals(ObjectType.SCALAR, innerWriter.entryType());
    final ScalarWriter strWriter = innerWriter.scalar();
    assertEquals(ValueType.STRING, strWriter.valueType());
    // Sanity test of schema
    final TupleMetadata rowSchema = writer.tupleSchema();
    assertEquals(2, rowSchema.size());
    final ColumnMetadata listSchema = rowSchema.metadata(1);
    assertEquals(MinorType.LIST, listSchema.type());
    assertEquals(DataMode.REPEATED, listSchema.mode());
    assertTrue(listSchema instanceof RepeatedListColumnMetadata);
    assertEquals(StructureType.MULTI_ARRAY, listSchema.structureType());
    assertNotNull(listSchema.childSchema());
    final ColumnMetadata elementSchema = listSchema.childSchema();
    assertEquals(listSchema.name(), elementSchema.name());
    assertEquals(MinorType.VARCHAR, elementSchema.type());
    assertEquals(DataMode.REPEATED, elementSchema.mode());
    // Write values
    rsLoader.startBatch();
    writer.addRow(1, objArray(strArray("a", "b"), strArray("c", "d"))).addRow(2, objArray(strArray("e"), strArray(), strArray("f", "g", "h"))).addRow(3, objArray()).addRow(4, objArray(strArray(), strArray("i"), strArray()));
    // Verify the values.
    // (Relies on the row set level repeated list tests having passed.)
    final RowSet expected = fixture.rowSetBuilder(schema).addRow(1, objArray(strArray("a", "b"), strArray("c", "d"))).addRow(2, objArray(strArray("e"), strArray(), strArray("f", "g", "h"))).addRow(3, objArray()).addRow(4, objArray(strArray(), strArray("i"), strArray())).build();
    RowSetUtilities.verify(expected, fixture.wrap(rsLoader.harvest()));
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) RepeatedListColumnMetadata(org.apache.drill.exec.record.metadata.RepeatedListColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) ObjectWriter(org.apache.drill.exec.vector.accessor.ObjectWriter) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) ArrayWriter(org.apache.drill.exec.vector.accessor.ArrayWriter) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) RepeatedListColumnMetadata(org.apache.drill.exec.record.metadata.RepeatedListColumnMetadata)

Aggregations

RepeatedListColumnMetadata (org.apache.drill.exec.record.metadata.RepeatedListColumnMetadata)2 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)1 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)1 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)1 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)1 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)1 ArrayWriter (org.apache.drill.exec.vector.accessor.ArrayWriter)1 ObjectWriter (org.apache.drill.exec.vector.accessor.ObjectWriter)1 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)1 RepeatedListVector (org.apache.drill.exec.vector.complex.RepeatedListVector)1