Search in sources :

Example 1 with ResultSetOptionBuilder

use of org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder in project drill by apache.

the class ReaderLifecycle method buildLoader.

public ResultSetLoader buildLoader() {
    Preconditions.checkState(state == State.START);
    ScanLifecycleBuilder scanOptions = scanOptions();
    ResultSetOptionBuilder options = new ResultSetOptionBuilder().rowCountLimit(Math.min(schemaNegotiator.batchSize, scanOptions.scanBatchRecordLimit())).vectorCache(scanLifecycle.vectorCache()).batchSizeLimit(scanOptions.scanBatchByteLimit()).errorContext(errorContext()).projectionFilter(schemaTracker().projectionFilter(errorContext())).readerSchema(schemaNegotiator.readerSchema).limit(limit);
    // Resolve the scan schema if possible.
    applyEarlySchema();
    // Create the table loader
    tableLoader = new ResultSetLoaderImpl(scanLifecycle.allocator(), options.build());
    state = State.DATA;
    return tableLoader;
}
Also used : ResultSetOptionBuilder(org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder) ResultSetLoaderImpl(org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl) ScanLifecycleBuilder(org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)

Example 2 with ResultSetOptionBuilder

use of org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder in project drill by apache.

the class MetadataHandlerBatch method getResultSetLoaderForMetadata.

private ResultSetLoader getResultSetLoaderForMetadata(BaseMetadata baseMetadata) {
    SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable(MetastoreAnalyzeConstants.LOCATION_FIELD, MinorType.VARCHAR);
    for (String segmentColumn : popConfig.getContext().segmentColumns()) {
        schemaBuilder.addNullable(segmentColumn, MinorType.VARCHAR);
    }
    baseMetadata.getColumnsStatistics().entrySet().stream().sorted(Comparator.comparing(e -> e.getKey().getRootSegmentPath())).forEach(entry -> {
        for (StatisticsKind<?> statisticsKind : AnalyzeColumnUtils.COLUMN_STATISTICS_FUNCTIONS.keySet()) {
            MinorType type = AnalyzeColumnUtils.COLUMN_STATISTICS_TYPES.get(statisticsKind);
            type = type != null ? type : entry.getValue().getComparatorType();
            schemaBuilder.addNullable(AnalyzeColumnUtils.getColumnStatisticsFieldName(entry.getKey().getRootSegmentPath(), statisticsKind), type);
        }
    });
    for (StatisticsKind<?> statisticsKind : AnalyzeColumnUtils.META_STATISTICS_FUNCTIONS.keySet()) {
        schemaBuilder.addNullable(AnalyzeColumnUtils.getMetadataStatisticsFieldName(statisticsKind), AnalyzeColumnUtils.COLUMN_STATISTICS_TYPES.get(statisticsKind));
    }
    schemaBuilder.addMapArray(MetastoreAnalyzeConstants.COLLECTED_MAP_FIELD).resumeSchema();
    if (metadataType == MetadataType.SEGMENT) {
        schemaBuilder.addArray(MetastoreAnalyzeConstants.LOCATIONS_FIELD, MinorType.VARCHAR);
    }
    if (metadataType == MetadataType.ROW_GROUP) {
        schemaBuilder.addNullable(columnNamesOptions.rowGroupIndex(), MinorType.VARCHAR);
        schemaBuilder.addNullable(columnNamesOptions.rowGroupStart(), MinorType.VARCHAR);
        schemaBuilder.addNullable(columnNamesOptions.rowGroupLength(), MinorType.VARCHAR);
    }
    schemaBuilder.addNullable(MetastoreAnalyzeConstants.SCHEMA_FIELD, MinorType.VARCHAR).addNullable(columnNamesOptions.lastModifiedTime(), MinorType.VARCHAR).add(MetastoreAnalyzeConstants.METADATA_TYPE, MinorType.VARCHAR);
    ResultSetLoaderImpl.ResultSetOptions options = new ResultSetOptionBuilder().readerSchema(schemaBuilder.buildSchema()).build();
    return new ResultSetLoaderImpl(container.getAllocator(), options);
}
Also used : ResultSetOptionBuilder(org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder) ResultSetLoaderImpl(org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 3 with ResultSetOptionBuilder

use of org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder in project drill by apache.

the class TestLoad method testLoadValueVectorEmptyVarCharArray.

@Test
public void testLoadValueVectorEmptyVarCharArray() throws Exception {
    try (BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConfig)) {
        TupleMetadata schema = new SchemaBuilder().addArray("chars", MinorType.VARCHAR).build();
        ResultSetLoaderImpl.ResultSetOptions options = new ResultSetOptionBuilder().readerSchema(schema).build();
        ResultSetLoader resultSetLoader = new ResultSetLoaderImpl(allocator, options);
        resultSetLoader.startBatch();
        RowSetLoader rowWriter = resultSetLoader.writer();
        rowWriter.addRow(new Object[] { null });
        VectorContainer harvest = resultSetLoader.harvest();
        // Create vectors
        List<ValueVector> vectors = StreamSupport.stream(harvest.spliterator(), false).map(VectorWrapper::getValueVector).collect(Collectors.toList());
        // Writeable batch now owns vector buffers
        WritableBatch writableBatch = WritableBatch.getBatchNoHV(1, vectors, false);
        // Serialize the vectors
        DrillBuf byteBuf = serializeBatch(allocator, writableBatch);
        // Batch loader does NOT take ownership of the serialized buffer
        RecordBatchLoader batchLoader = new RecordBatchLoader(allocator);
        batchLoader.load(writableBatch.getDef(), byteBuf);
        // Release the serialized buffer.
        byteBuf.release();
        assertEquals(1, batchLoader.getRecordCount());
        // Free the original vectors
        writableBatch.clear();
        // Free the deserialized vectors
        batchLoader.clear();
    }
}
Also used : ResultSetLoaderImpl(org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) VectorContainer(org.apache.drill.exec.record.VectorContainer) ResultSetOptionBuilder(org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder) ValueVector(org.apache.drill.exec.vector.ValueVector) ResultSetLoader(org.apache.drill.exec.physical.resultSet.ResultSetLoader) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) WritableBatch(org.apache.drill.exec.record.WritableBatch) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) DrillBuf(io.netty.buffer.DrillBuf) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest)

Example 4 with ResultSetOptionBuilder

use of org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder in project drill by apache.

the class MetadataHandlerBatch method getResultSetLoaderWithBatchSchema.

private ResultSetLoader getResultSetLoaderWithBatchSchema() {
    SchemaBuilder schemaBuilder = new SchemaBuilder();
    // adds fields to the schema preserving their order to avoid issues in outcoming batches
    for (VectorWrapper<?> vectorWrapper : container) {
        MaterializedField field = vectorWrapper.getField();
        String fieldName = field.getName();
        if (fieldName.equals(MetastoreAnalyzeConstants.LOCATION_FIELD) || fieldName.equals(MetastoreAnalyzeConstants.SCHEMA_FIELD) || fieldName.equals(columnNamesOptions.lastModifiedTime()) || fieldName.equals(columnNamesOptions.rowGroupIndex()) || fieldName.equals(columnNamesOptions.rowGroupStart()) || fieldName.equals(columnNamesOptions.rowGroupLength()) || fieldName.equals(MetastoreAnalyzeConstants.METADATA_TYPE) || popConfig.getContext().segmentColumns().contains(fieldName)) {
            schemaBuilder.add(fieldName, field.getType().getMinorType(), field.getDataMode());
        } else if (AnalyzeColumnUtils.isColumnStatisticsField(fieldName) || AnalyzeColumnUtils.isMetadataStatisticsField(fieldName)) {
            schemaBuilder.add(fieldName, field.getType().getMinorType(), field.getType().getMode());
        } else if (fieldName.equals(MetastoreAnalyzeConstants.COLLECTED_MAP_FIELD)) {
            schemaBuilder.addMapArray(fieldName).resumeSchema();
        } else if (fieldName.equals(MetastoreAnalyzeConstants.LOCATIONS_FIELD)) {
            schemaBuilder.addArray(fieldName, MinorType.VARCHAR);
        } else {
            throw new UnsupportedOperationException(String.format("Found unexpected field [%s] in incoming batch.", field));
        }
    }
    ResultSetLoaderImpl.ResultSetOptions options = new ResultSetOptionBuilder().readerSchema(schemaBuilder.buildSchema()).build();
    return new ResultSetLoaderImpl(container.getAllocator(), options);
}
Also used : ResultSetOptionBuilder(org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder) ResultSetLoaderImpl(org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Example 5 with ResultSetOptionBuilder

use of org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder in project drill by apache.

the class ReaderSchemaOrchestrator method makeTableLoader.

public ResultSetLoader makeTableLoader(CustomErrorContext errorContext, TupleMetadata readerSchema, long localLimit) {
    ResultSetOptionBuilder options = new ResultSetOptionBuilder();
    options.rowCountLimit(Math.min(readerBatchSize, scanOrchestrator.options.scanBatchRecordLimit));
    options.vectorCache(scanOrchestrator.vectorCache);
    options.batchSizeLimit(scanOrchestrator.options.scanBatchByteLimit);
    options.errorContext(errorContext);
    // Set up a selection list if available and is a subset of
    // table columns. (Only needed for non-wildcard queries.)
    // The projection list includes all candidate table columns
    // whether or not they exist in the up-front schema. Handles
    // the odd case where the reader claims a fixed schema, but
    // adds a column later.
    options.projectionFilter(scanOrchestrator.scanProj.readerProjection);
    options.readerSchema(readerSchema);
    if (limit < 0) {
        limit = localLimit;
    } else if (localLimit >= 0) {
        limit = Math.min(localLimit, limit);
    }
    options.limit(limit);
    // Create the table loader
    tableLoader = new ResultSetLoaderImpl(scanOrchestrator.allocator, options.build());
    return tableLoader;
}
Also used : ResultSetOptionBuilder(org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder) ResultSetLoaderImpl(org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl)

Aggregations

ResultSetLoaderImpl (org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl)5 ResultSetOptionBuilder (org.apache.drill.exec.physical.resultSet.impl.ResultSetOptionBuilder)5 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 DrillBuf (io.netty.buffer.DrillBuf)1 VectorTest (org.apache.drill.categories.VectorTest)1 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 ExecTest (org.apache.drill.exec.ExecTest)1 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)1 ScanLifecycleBuilder (org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)1 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)1 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)1 BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)1 MaterializedField (org.apache.drill.exec.record.MaterializedField)1 RecordBatchLoader (org.apache.drill.exec.record.RecordBatchLoader)1 VectorContainer (org.apache.drill.exec.record.VectorContainer)1 WritableBatch (org.apache.drill.exec.record.WritableBatch)1 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)1 ValueVector (org.apache.drill.exec.vector.ValueVector)1 Test (org.junit.Test)1