Search in sources :

Example 11 with RepeatedValueVector

use of org.apache.drill.exec.vector.complex.RepeatedValueVector in project drill by apache.

the class TestOutputBatchSize method testSizerRepeatedRepeatedList.

@Test
public void testSizerRepeatedRepeatedList() throws Exception {
    List<String> inputJsonBatches = Lists.newArrayList();
    StringBuilder batchString = new StringBuilder();
    StringBuilder newString = new StringBuilder();
    newString.append("[ [[1,2,3,4], [5,6,7,8]], [[1,2,3,4], [5,6,7,8]] ]");
    numRows = 9;
    batchString.append("[");
    for (int i = 0; i < numRows; i++) {
        batchString.append("{\"c\" : " + newString);
        batchString.append("},");
    }
    batchString.append("{\"c\" : " + newString);
    batchString.append("}");
    batchString.append("]");
    inputJsonBatches.add(batchString.toString());
    // Create a dummy scanBatch to figure out the size.
    RecordBatch scanBatch = new ScanBatch(new MockPhysicalOperator(), fragContext, getReaderListForJsonBatches(inputJsonBatches, fragContext));
    VectorAccessible va = new BatchIterator(scanBatch).iterator().next();
    RecordBatchSizer sizer = new RecordBatchSizer(va);
    assertEquals(1, sizer.columns().size());
    RecordBatchSizer.ColumnSize column = sizer.columns().get("c");
    assertNotNull(column);
    /**
     * stdDataSize:8*5*5*5, stdNetSize:8*5*5*5 + 8*5*5 + 8*5 + 4,
     * dataSizePerEntry:16*8, netSizePerEntry:16*8 + 16*4 + 4*2 + 4*2,
     * totalDataSize:16*8*10, totalNetSize:netSizePerEntry*10, valueCount:10,
     * elementCount:10, estElementCountPerArray:1, isVariableWidth:false
     */
    assertEquals(1000, column.getStdDataSizePerEntry());
    assertEquals(1244, column.getStdNetSizePerEntry());
    assertEquals(128, column.getDataSizePerEntry());
    assertEquals(156, column.getNetSizePerEntry());
    assertEquals(1280, column.getTotalDataSize());
    assertEquals(1560, column.getTotalNetSize());
    assertEquals(10, column.getValueCount());
    assertEquals(20, column.getElementCount());
    assertEquals(2, column.getCardinality(), 0.01);
    assertEquals(false, column.isVariableWidth());
    final int testRowCount = 1000;
    final int testRowCountPowerTwo = 2048;
    for (VectorWrapper<?> vw : va) {
        ValueVector v = vw.getValueVector();
        v.clear();
        RecordBatchSizer.ColumnSize colSize = sizer.getColumn(v.getField().getName());
        // Allocates to nearest power of two
        colSize.allocateVector(v, testRowCount);
        // offset vector of delegate vector i.e. outer array should have row count number of values.
        UInt4Vector offsetVector = ((RepeatedListVector) v).getOffsetVector();
        assertEquals((Integer.highestOneBit(testRowCount) << 1), offsetVector.getValueCapacity());
        // Get data vector of delegate vector. This is repeated list again
        ValueVector dataVector = ((RepeatedListVector) v).getDataVector();
        // offset vector of delegate vector of the inner repeated list
        // This should have row count * 2 number of values.
        offsetVector = ((RepeatedListVector) dataVector).getOffsetVector();
        assertEquals((Integer.highestOneBit(testRowCount * 2) << 1), offsetVector.getValueCapacity());
        // Data vector of inner vector should have row count * 2 number of values - 1 (for offset vector adjustment).
        ValueVector innerDataVector = ((RepeatedValueVector) dataVector).getDataVector();
        assertEquals((Integer.highestOneBit((testRowCount * 2) << 1) - 1), dataVector.getValueCapacity());
        // offset vector of inner vector should have
        // 2 (outer array cardinality) * 2 (inner array cardinality) * row count number of values.
        offsetVector = ((RepeatedValueVector) innerDataVector).getOffsetVector();
        assertEquals((Integer.highestOneBit(testRowCount * 4) << 1), offsetVector.getValueCapacity());
        // Data vector of inner vector should
        // have 2 (outer array cardinality) * 2 (inner array cardinality)  * row count number of values.
        dataVector = ((RepeatedValueVector) innerDataVector).getDataVector();
        assertEquals(Integer.highestOneBit(testRowCount << 1) * 16, dataVector.getValueCapacity());
        v.clear();
        // Allocates the same as value passed since it is already power of two.
        // -1 is done for adjustment needed for offset vector.
        colSize.allocateVector(v, testRowCountPowerTwo - 1);
        // offset vector of delegate vector i.e. outer array should have row count number of values.
        offsetVector = ((RepeatedListVector) v).getOffsetVector();
        assertEquals(testRowCountPowerTwo, offsetVector.getValueCapacity());
        // Get data vector of delegate vector. This is repeated list again
        dataVector = ((RepeatedListVector) v).getDataVector();
        // offset vector of delegate vector of the inner repeated list
        // This should have row count * 2 number of values.
        offsetVector = ((RepeatedListVector) dataVector).getOffsetVector();
        assertEquals(testRowCountPowerTwo * 2, offsetVector.getValueCapacity());
        // Data vector of inner vector should have row count * 2 number of values - 1 (for offset vector adjustment).
        innerDataVector = ((RepeatedValueVector) dataVector).getDataVector();
        assertEquals(testRowCountPowerTwo * 2 - 1, dataVector.getValueCapacity());
        // offset vector of inner vector should have
        // 2 (outer array cardinality) * 2 (inner array cardinality) * row count number of values.
        offsetVector = ((RepeatedValueVector) innerDataVector).getOffsetVector();
        assertEquals(testRowCountPowerTwo * 4, offsetVector.getValueCapacity());
        // Data vector of inner vector should
        // have 2 (outer array cardinality) * 2 (inner array cardinality)  * row count number of values.
        dataVector = ((RepeatedValueVector) innerDataVector).getDataVector();
        assertEquals(testRowCountPowerTwo * 16, dataVector.getValueCapacity());
        v.clear();
        // MAX ROW COUNT
        colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT - 1);
        // offset vector of delegate vector i.e. outer array should have row count number of values.
        offsetVector = ((RepeatedListVector) v).getOffsetVector();
        assertEquals(ValueVector.MAX_ROW_COUNT, offsetVector.getValueCapacity());
        // Get data vector of delegate vector. This is repeated list again
        dataVector = ((RepeatedListVector) v).getDataVector();
        // offset vector of delegate vector of the inner repeated list
        // This should have row count * 2 number of values.
        offsetVector = ((RepeatedListVector) dataVector).getOffsetVector();
        assertEquals(ValueVector.MAX_ROW_COUNT * 2, offsetVector.getValueCapacity());
        // Data vector of inner vector should have row count * 2 number of values - 1 (for offset vector adjustment).
        innerDataVector = ((RepeatedValueVector) dataVector).getDataVector();
        assertEquals(ValueVector.MAX_ROW_COUNT * 2 - 1, dataVector.getValueCapacity());
        // offset vector of inner vector should have
        // 2 (outer array cardinality) * 2 (inner array cardinality) * row count number of values.
        offsetVector = ((RepeatedValueVector) innerDataVector).getOffsetVector();
        assertEquals(ValueVector.MAX_ROW_COUNT * 4, offsetVector.getValueCapacity());
        // Data vector of inner vector should
        // have 2 (outer array cardinality) * 2 (inner array cardinality)  * row count number of values.
        dataVector = ((RepeatedValueVector) innerDataVector).getDataVector();
        assertEquals(ValueVector.MAX_ROW_COUNT * 16, dataVector.getValueCapacity());
        v.clear();
        // MIN ROW COUNT
        colSize.allocateVector(v, 0);
        // offset vector of delegate vector i.e. outer array should have 1 value.
        offsetVector = ((RepeatedListVector) v).getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT, offsetVector.getValueCapacity());
        // Get data vector of delegate vector. This is repeated list again
        dataVector = ((RepeatedListVector) v).getDataVector();
        // offset vector of delegate vector of the inner repeated list
        offsetVector = ((RepeatedListVector) dataVector).getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT, offsetVector.getValueCapacity());
        // offset vector of inner vector should have
        // 2 (outer array cardinality) * 1.
        offsetVector = ((RepeatedValueVector) innerDataVector).getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT * 2, offsetVector.getValueCapacity());
        // Data vector of inner vector should 1 value.
        dataVector = ((RepeatedValueVector) innerDataVector).getDataVector();
        assertEquals(ValueVector.MIN_ROW_COUNT, dataVector.getValueCapacity());
        v.clear();
    }
}
Also used : VectorAccessible(org.apache.drill.exec.record.VectorAccessible) RecordBatch(org.apache.drill.exec.record.RecordBatch) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) RecordBatchSizer(org.apache.drill.exec.record.RecordBatchSizer) RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) ScanBatch(org.apache.drill.exec.physical.impl.ScanBatch) Test(org.junit.Test)

Example 12 with RepeatedValueVector

use of org.apache.drill.exec.vector.complex.RepeatedValueVector in project drill by apache.

the class TestRecordBatchSizer method testEmptyBatchRepeatedVariableWidth.

@Test
public void testEmptyBatchRepeatedVariableWidth() {
    TupleMetadata schema = new SchemaBuilder().addArray("b", MinorType.VARCHAR).buildSchema();
    RowSetBuilder builder = fixture.rowSetBuilder(schema);
    RowSet rows = builder.build();
    // Run the record batch sizer on the resulting batch.
    RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
    assertEquals(1, sizer.columns().size());
    ColumnSize bColumn = sizer.columns().get("b");
    /**
     * stdDataSize:50*5, stdNetSize:50*5+4*10+4, dataSizePerEntry:0, netSizePerEntry:0,
     * totalDataSize:0, totalNetSize:0, valueCount:0,
     * elementCount:0, cardinality:0, isVariableWidth:true
     */
    verifyColumnValues(bColumn, 250, 274, 0, 0, 0, 0, 0, 0, 0, true);
    // Verify memory allocation is done correctly based on std size for empty batch.
    SingleRowSet empty = fixture.rowSet(schema);
    VectorAccessible accessible = empty.vectorAccessible();
    for (VectorWrapper<?> vw : accessible) {
        ValueVector v = vw.getValueVector();
        RecordBatchSizer.ColumnSize colSize = sizer.getColumn(v.getField().getName());
        // Allocates to nearest power of two
        colSize.allocateVector(v, testRowCount - 1);
        UInt4Vector offsetVector = ((RepeatedValueVector) v).getOffsetVector();
        assertEquals(Integer.highestOneBit(testRowCount) << 1, offsetVector.getValueCapacity());
        VariableWidthVector vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
        offsetVector = vwVector.getOffsetVector();
        assertEquals((Integer.highestOneBit((testRowCount - 1) * STD_REPETITION_FACTOR) << 1), offsetVector.getValueCapacity());
        assertEquals(Integer.highestOneBit((testRowCount - 1) * STD_REPETITION_FACTOR << 1) - 1, vwVector.getValueCapacity());
        v.clear();
        // Allocates the same as value passed since it is already power of two.
        colSize.allocateVector(v, testRowCountPowerTwo);
        offsetVector = ((RepeatedValueVector) v).getOffsetVector();
        assertEquals((Integer.highestOneBit(testRowCountPowerTwo) << 1), offsetVector.getValueCapacity());
        vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
        offsetVector = vwVector.getOffsetVector();
        assertEquals((Integer.highestOneBit((int) (testRowCountPowerTwo * STD_REPETITION_FACTOR)) << 1), offsetVector.getValueCapacity());
        assertEquals(Integer.highestOneBit(testRowCountPowerTwo * STD_REPETITION_FACTOR << 1) - 1, vwVector.getValueCapacity());
        v.clear();
        // Allocate for max rows.
        colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT);
        offsetVector = ((RepeatedValueVector) v).getOffsetVector();
        assertEquals(ValueVector.MAX_ROW_COUNT << 1, offsetVector.getValueCapacity());
        vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
        offsetVector = vwVector.getOffsetVector();
        assertEquals((Integer.highestOneBit((int) (ValueVector.MAX_ROW_COUNT * STD_REPETITION_FACTOR)) << 1), offsetVector.getValueCapacity());
        assertEquals(Integer.highestOneBit(ValueVector.MAX_ROW_COUNT * STD_REPETITION_FACTOR << 1) - 1, vwVector.getValueCapacity());
        v.clear();
        // Allocate for 0 rows. should atleast do allocation for 1 row.
        colSize.allocateVector(v, 0);
        offsetVector = ((RepeatedValueVector) v).getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
        vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
        offsetVector = vwVector.getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
        assertEquals(ValueVector.MIN_ROW_COUNT, vwVector.getValueCapacity());
        v.clear();
    }
    empty.clear();
    rows.clear();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) VariableWidthVector(org.apache.drill.exec.vector.VariableWidthVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) ValueVector(org.apache.drill.exec.vector.ValueVector) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) 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 13 with RepeatedValueVector

use of org.apache.drill.exec.vector.complex.RepeatedValueVector in project drill by apache.

the class TestRecordBatchSizer method testSizerRepeatedVariableWidth.

@Test
public void testSizerRepeatedVariableWidth() {
    TupleMetadata schema = new SchemaBuilder().addArray("b", MinorType.VARCHAR).buildSchema();
    RowSetBuilder builder = fixture.rowSetBuilder(schema);
    // size = (5*6)/2 = 15
    String[] newString = new String[] { "a", "aa", "aaa", "aaaa", "aaaaa" };
    for (long i = 0; i < 10; i++) {
        builder.addRow((Object) (newString));
    }
    RowSet rows = builder.build();
    // Run the record batch sizer on the resulting batch.
    RecordBatchSizer sizer = new RecordBatchSizer(rows.container());
    assertEquals(1, sizer.columns().size());
    ColumnSize bColumn = sizer.columns().get("b");
    /**
     * stdDataSize:50*5, stdNetSize:50*5+4*5+4, dataSizePerEntry:(5*6)/2, netSizePerEntry:(5*6)/2+5*4+4,
     * totalDataSize:(5*6)/2 * 10, totalNetSize: ((5*6)/2+5*4+4)*10, valueCount:10,
     * elementCount:50, cardinality:5, isVariableWidth:true
     */
    verifyColumnValues(bColumn, 250, 274, 15, 39, 150, 390, 10, 50, 5, true);
    SingleRowSet empty = fixture.rowSet(schema);
    VectorAccessible accessible = empty.vectorAccessible();
    for (VectorWrapper<?> vw : accessible) {
        ValueVector v = vw.getValueVector();
        RecordBatchSizer.ColumnSize colSize = sizer.getColumn(v.getField().getName());
        // Allocates to nearest power of two
        colSize.allocateVector(v, testRowCount - 1);
        UInt4Vector offsetVector = ((RepeatedValueVector) v).getOffsetVector();
        assertEquals(Integer.highestOneBit(testRowCount) << 1, offsetVector.getValueCapacity());
        VariableWidthVector vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
        offsetVector = vwVector.getOffsetVector();
        assertEquals((Integer.highestOneBit((testRowCount - 1) * 5) << 1), offsetVector.getValueCapacity());
        assertEquals(Integer.highestOneBit((testRowCount - 1) * 5 << 1) - 1, vwVector.getValueCapacity());
        v.clear();
        // Allocates the same as value passed since it is already power of two.
        colSize.allocateVector(v, testRowCountPowerTwo);
        offsetVector = ((RepeatedValueVector) v).getOffsetVector();
        assertEquals((Integer.highestOneBit(testRowCountPowerTwo) << 1), offsetVector.getValueCapacity());
        vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
        offsetVector = vwVector.getOffsetVector();
        assertEquals((Integer.highestOneBit(testRowCountPowerTwo * 5) << 1), offsetVector.getValueCapacity());
        assertEquals(Integer.highestOneBit(testRowCountPowerTwo * 5 << 1) - 1, vwVector.getValueCapacity());
        v.clear();
        // Allocate for max rows.
        colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT);
        offsetVector = ((RepeatedValueVector) v).getOffsetVector();
        assertEquals(ValueVector.MAX_ROW_COUNT << 1, offsetVector.getValueCapacity());
        vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
        offsetVector = vwVector.getOffsetVector();
        assertEquals((Integer.highestOneBit(ValueVector.MAX_ROW_COUNT * 5) << 1), offsetVector.getValueCapacity());
        assertEquals(Integer.highestOneBit(ValueVector.MAX_ROW_COUNT * 5 << 1) - 1, vwVector.getValueCapacity());
        v.clear();
        // Allocate for 0 rows. should atleast do allocation for 1 row.
        colSize.allocateVector(v, 0);
        offsetVector = ((RepeatedValueVector) v).getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
        vwVector = ((VariableWidthVector) ((RepeatedValueVector) v).getDataVector());
        offsetVector = vwVector.getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT + 1, offsetVector.getValueCapacity());
        assertEquals(ValueVector.MIN_ROW_COUNT, vwVector.getValueCapacity());
        v.clear();
    }
    empty.clear();
    rows.clear();
}
Also used : SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) ColumnSize(org.apache.drill.exec.record.RecordBatchSizer.ColumnSize) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) VariableWidthVector(org.apache.drill.exec.vector.VariableWidthVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) ValueVector(org.apache.drill.exec.vector.ValueVector) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) 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 14 with RepeatedValueVector

use of org.apache.drill.exec.vector.complex.RepeatedValueVector in project drill by apache.

the class UnnestRecordBatch method getUnnestFieldTransferPair.

/**
 * The data layout is the same for the actual data within a repeated field, as
 * it is in a scalar vector for the same sql type. For example, a repeated int
 * vector has a vector of offsets into a regular int vector to represent the
 * lists. As the data layout for the actual values in the same in the repeated
 * vector as in the scalar vector of the same type, we can avoid making
 * individual copies for the column being unnested, and just use vector copies
 * between the inner vector of the repeated field to the resulting scalar
 * vector from the unnest operation. This is completed after we determine how
 * many records will fit (as we will hit either a batch end, or the end of one
 * of the other vectors while we are copying the data of the other vectors
 * alongside each new unnested value coming out of the repeated field.)
 */
private TransferPair getUnnestFieldTransferPair(FieldReference reference) {
    int[] typeFieldIds = unnestTypedFieldId.getFieldIds();
    Class<?> vectorClass = incoming.getSchema().getColumn(typeFieldIds[0]).getValueClass();
    ValueVector unnestField = incoming.getValueAccessorById(vectorClass, typeFieldIds).getValueVector();
    TransferPair tp = null;
    if (unnestField instanceof RepeatedMapVector) {
        tp = ((RepeatedMapVector) unnestField).getTransferPairToSingleMap(reference.getAsNamePart().getName(), oContext.getAllocator());
    } else if (!(unnestField instanceof RepeatedValueVector)) {
        if (incoming.getRecordCount() != 0) {
            throw UserException.unsupportedError().message("Unnest does not support inputs of non-list values.").build(logger);
        }
        logger.error("Cannot cast {} to RepeatedValueVector", unnestField);
        // when incoming recordCount is 0, don't throw exception since the type being seen here is not solid
        ValueVector vv = new RepeatedMapVector(unnestField.getField(), oContext.getAllocator(), null);
        tp = RepeatedValueVector.class.cast(vv).getTransferPair(reference.getAsNamePart().getName(), oContext.getAllocator());
    } else {
        ValueVector vvIn = RepeatedValueVector.class.cast(unnestField).getDataVector();
        // vvIn may be null because of fast schema return for repeated list vectors
        if (vvIn != null) {
            tp = vvIn.getTransferPair(reference.getAsNamePart().getName(), oContext.getAllocator());
        }
    }
    return tp;
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) TransferPair(org.apache.drill.exec.record.TransferPair) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector)

Example 15 with RepeatedValueVector

use of org.apache.drill.exec.vector.complex.RepeatedValueVector in project drill by axbaretto.

the class TestOutputBatchSize method testSizerRepeatedList.

@Test
public void testSizerRepeatedList() throws Exception {
    List<String> inputJsonBatches = Lists.newArrayList();
    StringBuilder batchString = new StringBuilder();
    StringBuilder newString = new StringBuilder();
    newString.append("[ [1,2,3,4], [5,6,7,8] ]");
    numRows = 9;
    batchString.append("[");
    for (int i = 0; i < numRows; i++) {
        batchString.append("{\"c\" : " + newString);
        batchString.append("},");
    }
    batchString.append("{\"c\" : " + newString);
    batchString.append("}");
    batchString.append("]");
    inputJsonBatches.add(batchString.toString());
    // Create a dummy scanBatch to figure out the size.
    RecordBatch scanBatch = new ScanBatch(new MockPhysicalOperator(), fragContext, getReaderListForJsonBatches(inputJsonBatches, fragContext));
    VectorAccessible va = new BatchIterator(scanBatch).iterator().next();
    RecordBatchSizer sizer = new RecordBatchSizer(va);
    assertEquals(1, sizer.columns().size());
    RecordBatchSizer.ColumnSize column = sizer.columns().get("c");
    assertNotNull(column);
    /**
     * stdDataSize:8*10*10, stdNetSize:8*10*10 + 4*10 + 4*10 + 4,
     * dataSizePerEntry:8*8, netSizePerEntry:8*8 + 4*2 + 4,
     * totalDataSize:8*8*10, totalNetSize:netSizePerEntry*10, valueCount:10,
     * elementCount:10, estElementCountPerArray:1, isVariableWidth:false
     */
    assertEquals(800, column.getStdDataSizePerEntry());
    assertEquals(884, column.getStdNetSizePerEntry());
    assertEquals(64, column.getDataSizePerEntry());
    assertEquals(76, column.getNetSizePerEntry());
    assertEquals(640, column.getTotalDataSize());
    assertEquals(760, column.getTotalNetSize());
    assertEquals(10, column.getValueCount());
    assertEquals(20, column.getElementCount());
    assertEquals(2, column.getCardinality(), 0.01);
    assertEquals(false, column.isVariableWidth());
    final int testRowCount = 1000;
    final int testRowCountPowerTwo = 2048;
    for (VectorWrapper<?> vw : va) {
        ValueVector v = vw.getValueVector();
        v.clear();
        RecordBatchSizer.ColumnSize colSize = sizer.getColumn(v.getField().getName());
        // Allocates to nearest power of two
        colSize.allocateVector(v, testRowCount);
        // offset vector of delegate vector i.e. outer array should have row count number of values.
        UInt4Vector offsetVector = ((RepeatedListVector) v).getOffsetVector();
        assertEquals((Integer.highestOneBit(testRowCount) << 1), offsetVector.getValueCapacity());
        // Get inner vector of delegate vector.
        ValueVector vector = ((RepeatedValueVector) v).getDataVector();
        // Data vector of inner vector should
        // have 2 (outer array cardinality) * 4 (inner array cardinality) * row count number of values.
        ValueVector dataVector = ((RepeatedValueVector) vector).getDataVector();
        assertEquals(Integer.highestOneBit((testRowCount * 8) << 1), dataVector.getValueCapacity());
        // offset vector of inner vector should have
        // 2 (outer array cardinality) * row count number of values.
        offsetVector = ((RepeatedValueVector) vector).getOffsetVector();
        assertEquals((Integer.highestOneBit(testRowCount * 2) << 1), offsetVector.getValueCapacity());
        v.clear();
        // Allocates the same as value passed since it is already power of two.
        // -1 is done for adjustment needed for offset vector.
        colSize.allocateVector(v, testRowCountPowerTwo - 1);
        // offset vector of delegate vector i.e. outer array should have row count number of values.
        offsetVector = ((RepeatedListVector) v).getOffsetVector();
        assertEquals(testRowCountPowerTwo, offsetVector.getValueCapacity());
        // Get inner vector of delegate vector.
        vector = ((RepeatedValueVector) v).getDataVector();
        // Data vector of inner vector should
        // have 2 (outer array cardinality) * 4 (inner array cardinality) * row count number of values.
        dataVector = ((RepeatedValueVector) vector).getDataVector();
        assertEquals(testRowCountPowerTwo * 8, dataVector.getValueCapacity());
        // offset vector of inner vector should have
        // 2 (outer array cardinality) * row count number of values.
        offsetVector = ((RepeatedValueVector) vector).getOffsetVector();
        assertEquals(testRowCountPowerTwo * 2, offsetVector.getValueCapacity());
        v.clear();
        // MAX ROW COUNT
        colSize.allocateVector(v, ValueVector.MAX_ROW_COUNT - 1);
        // offset vector of delegate vector i.e. outer array should have row count number of values.
        offsetVector = ((RepeatedListVector) v).getOffsetVector();
        assertEquals(ValueVector.MAX_ROW_COUNT, offsetVector.getValueCapacity());
        // Get inner vector of delegate vector.
        vector = ((RepeatedValueVector) v).getDataVector();
        // Data vector of inner vector should
        // have 2 (outer array cardinality) * 4 (inner array cardinality) * row count number of values.
        dataVector = ((RepeatedValueVector) vector).getDataVector();
        assertEquals(ValueVector.MAX_ROW_COUNT * 8, dataVector.getValueCapacity());
        // offset vector of inner vector should have
        // 2 (outer array cardinality) * row count number of values.
        offsetVector = ((RepeatedValueVector) vector).getOffsetVector();
        assertEquals(ValueVector.MAX_ROW_COUNT * 2, offsetVector.getValueCapacity());
        v.clear();
        // MIN ROW COUNT
        colSize.allocateVector(v, 0);
        // offset vector of delegate vector i.e. outer array should have 1 value.
        offsetVector = ((RepeatedListVector) v).getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT, offsetVector.getValueCapacity());
        // Get inner vector of delegate vector.
        vector = ((RepeatedValueVector) v).getDataVector();
        // Data vector of inner vector should have 1 value
        dataVector = ((RepeatedValueVector) vector).getDataVector();
        assertEquals(ValueVector.MIN_ROW_COUNT, dataVector.getValueCapacity());
        // offset vector of inner vector should have
        // 2 (outer array cardinality) * 1.
        offsetVector = ((RepeatedValueVector) vector).getOffsetVector();
        assertEquals(ValueVector.MIN_ROW_COUNT * 2, offsetVector.getValueCapacity());
        v.clear();
    }
}
Also used : VectorAccessible(org.apache.drill.exec.record.VectorAccessible) RecordBatch(org.apache.drill.exec.record.RecordBatch) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) RecordBatchSizer(org.apache.drill.exec.record.RecordBatchSizer) RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) ScanBatch(org.apache.drill.exec.physical.impl.ScanBatch) Test(org.junit.Test)

Aggregations

RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)26 ValueVector (org.apache.drill.exec.vector.ValueVector)22 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)14 Test (org.junit.Test)13 ColumnSize (org.apache.drill.exec.record.RecordBatchSizer.ColumnSize)9 RepeatedMapVector (org.apache.drill.exec.vector.complex.RepeatedMapVector)9 SubOperatorTest (org.apache.drill.test.SubOperatorTest)9 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)7 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)7 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)7 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)6 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)6 ScanBatch (org.apache.drill.exec.physical.impl.ScanBatch)4 RecordBatch (org.apache.drill.exec.record.RecordBatch)4 RecordBatchSizer (org.apache.drill.exec.record.RecordBatchSizer)4 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)4 VectorAccessible (org.apache.drill.exec.record.VectorAccessible)4 RepeatedListVector (org.apache.drill.exec.vector.complex.RepeatedListVector)4 MaterializedField (org.apache.drill.exec.record.MaterializedField)3 TransferPair (org.apache.drill.exec.record.TransferPair)3