Search in sources :

Example 31 with RowSetReader

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

the class MetadataControllerBatch method getMetadataUnits.

private List<TableMetadataUnit> getMetadataUnits(VectorContainer container) {
    List<TableMetadataUnit> metadataUnits = new ArrayList<>();
    RowSetReader reader = DirectRowSet.fromContainer(container).reader();
    while (reader.next()) {
        metadataUnits.addAll(getMetadataUnits(reader, 0));
    }
    if (metadataToHandle != null) {
        // leaves only table metadata and metadata which belongs to segments to be overridden
        metadataUnits = metadataUnits.stream().filter(tableMetadataUnit -> metadataToHandle.values().stream().map(MetadataInfo::key).anyMatch(s -> s.equals(tableMetadataUnit.metadataKey())) || MetadataType.TABLE.name().equals(tableMetadataUnit.metadataType())).collect(Collectors.toList());
        // leaves only metadata which should be fetched from the Metastore
        metadataUnits.stream().map(TableMetadataUnit::metadataIdentifier).forEach(metadataToHandle::remove);
        List<TableMetadataUnit> metadata = metadataToHandle.isEmpty() ? Collections.emptyList() : tables.basicRequests().metadata(popConfig.getContext().tableInfo(), metadataToHandle.values());
        metadataUnits.addAll(metadata);
    }
    // checks whether metadataUnits contains not only table metadata before adding default segment
    // to avoid case when only table metadata should be updated and / or root segments removed
    boolean insertDefaultSegment = metadataUnits.size() > 1 && metadataUnits.stream().noneMatch(metadataUnit -> metadataUnit.metadataType().equals(MetadataType.SEGMENT.name()));
    if (insertDefaultSegment) {
        TableMetadataUnit defaultSegmentMetadata = getDefaultSegment(metadataUnits);
        metadataUnits.add(defaultSegmentMetadata);
    }
    return metadataUnits;
}
Also used : MetadataType(org.apache.drill.metastore.metadata.MetadataType) BaseStatisticsKind(org.apache.drill.metastore.statistics.BaseStatisticsKind) MetastoreColumn(org.apache.drill.metastore.MetastoreColumn) UserException(org.apache.drill.common.exceptions.UserException) LoggerFactory(org.slf4j.LoggerFactory) Types(org.apache.drill.common.types.Types) MetadataInfo(org.apache.drill.metastore.metadata.MetadataInfo) RowSetReader(org.apache.drill.exec.physical.rowSet.RowSetReader) VectorContainer(org.apache.drill.exec.record.VectorContainer) ColumnStatistics(org.apache.drill.metastore.statistics.ColumnStatistics) ArrayListMultimap(org.apache.drill.shaded.guava.com.google.common.collect.ArrayListMultimap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayReader(org.apache.drill.exec.vector.accessor.ArrayReader) BaseTableMetadata(org.apache.drill.metastore.metadata.BaseTableMetadata) StatisticsRecordWriterImpl(org.apache.drill.exec.store.StatisticsRecordWriterImpl) PartitionMetadata(org.apache.drill.metastore.metadata.PartitionMetadata) Map(java.util.Map) FieldConverter(org.apache.drill.exec.store.EventBasedRecordWriter.FieldConverter) Path(org.apache.hadoop.fs.Path) BatchSchema(org.apache.drill.exec.record.BatchSchema) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) Multimap(org.apache.drill.shaded.guava.com.google.common.collect.Multimap) ColumnStatisticsKind(org.apache.drill.metastore.statistics.ColumnStatisticsKind) Delete(org.apache.drill.metastore.operate.Delete) TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) SegmentMetadata(org.apache.drill.metastore.metadata.SegmentMetadata) SchemaPath(org.apache.drill.common.expression.SchemaPath) RecordBatch(org.apache.drill.exec.record.RecordBatch) Set(java.util.Set) MetastoreAnalyzeConstants(org.apache.drill.exec.metastore.analyze.MetastoreAnalyzeConstants) Collectors(java.util.stream.Collectors) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) FieldReader(org.apache.drill.exec.vector.complex.reader.FieldReader) TypeProtos(org.apache.drill.common.types.TypeProtos) List(java.util.List) AbstractBinaryRecordBatch(org.apache.drill.exec.record.AbstractBinaryRecordBatch) Preconditions(org.apache.drill.shaded.guava.com.google.common.base.Preconditions) ObjectReader(org.apache.drill.exec.vector.accessor.ObjectReader) TableInfo(org.apache.drill.metastore.metadata.TableInfo) MetadataIdentifierUtils(org.apache.drill.exec.metastore.analyze.MetadataIdentifierUtils) TupleReader(org.apache.drill.exec.vector.accessor.TupleReader) Modify(org.apache.drill.metastore.operate.Modify) MetadataControllerContext(org.apache.drill.exec.metastore.analyze.MetadataControllerContext) HashMap(java.util.HashMap) BitVector(org.apache.drill.exec.vector.BitVector) Function(java.util.function.Function) VectorWrapper(org.apache.drill.exec.record.VectorWrapper) ArrayList(java.util.ArrayList) ColumnNamesOptions(org.apache.drill.exec.metastore.ColumnNamesOptions) HashSet(java.util.HashSet) OutOfMemoryException(org.apache.drill.exec.exception.OutOfMemoryException) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) DrillStatsTable(org.apache.drill.exec.planner.common.DrillStatsTable) WriterPrel(org.apache.drill.exec.planner.physical.WriterPrel) TableStatisticsKind(org.apache.drill.metastore.statistics.TableStatisticsKind) FragmentContext(org.apache.drill.exec.ops.FragmentContext) FileMetadata(org.apache.drill.metastore.metadata.FileMetadata) StatisticsRecordCollector(org.apache.drill.exec.store.StatisticsRecordCollector) BaseMetadata(org.apache.drill.metastore.metadata.BaseMetadata) Logger(org.slf4j.Logger) ExactStatisticsConstants(org.apache.drill.metastore.statistics.ExactStatisticsConstants) RowGroupMetadata(org.apache.drill.metastore.metadata.RowGroupMetadata) StatisticsKind(org.apache.drill.metastore.statistics.StatisticsKind) IOException(java.io.IOException) FilterExpression(org.apache.drill.metastore.expressions.FilterExpression) StatisticsCollectorImpl(org.apache.drill.exec.store.easy.json.StatisticsCollectorImpl) PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) ParquetTableMetadataUtils(org.apache.drill.exec.store.parquet.ParquetTableMetadataUtils) VarCharVector(org.apache.drill.exec.vector.VarCharVector) StatisticsHolder(org.apache.drill.metastore.statistics.StatisticsHolder) MetadataControllerPOP(org.apache.drill.exec.physical.config.MetadataControllerPOP) Tables(org.apache.drill.metastore.components.tables.Tables) Collections(java.util.Collections) AnalyzeColumnUtils(org.apache.drill.exec.metastore.analyze.AnalyzeColumnUtils) MetastoreTableInfo(org.apache.drill.metastore.components.tables.MetastoreTableInfo) ObjectType(org.apache.drill.exec.vector.accessor.ObjectType) TableMetadataUnit(org.apache.drill.metastore.components.tables.TableMetadataUnit) ArrayList(java.util.ArrayList) RowSetReader(org.apache.drill.exec.physical.rowSet.RowSetReader)

Example 32 with RowSetReader

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

the class IcebergQueriesTest method testSelectFromSnapshotIdAndToSnapshotId.

@Test
public void testSelectFromSnapshotIdAndToSnapshotId() throws Exception {
    String snapshotQuery = "select snapshot_id from dfs.tmp.`testAllTypes#snapshots` order by committed_at";
    String query = "select * from table(dfs.tmp.testAllTypes(type => 'iceberg', fromSnapshotId => %s, toSnapshotId => %s))";
    DirectRowSet rowSet = queryBuilder().sql(snapshotQuery).rowSet();
    try {
        RowSetReader reader = rowSet.reader();
        assertTrue(reader.next());
        Long fromSnapshotId = (Long) reader.column(0).reader().getObject();
        assertTrue(reader.next());
        Long toSnapshotId = (Long) reader.column(0).reader().getObject();
        String plan = queryBuilder().sql(query, fromSnapshotId, toSnapshotId).explainJson();
        long count = queryBuilder().physical(plan).run().recordCount();
        assertEquals(1, count);
    } finally {
        rowSet.clear();
    }
}
Also used : DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RowSetReader(org.apache.drill.exec.physical.rowSet.RowSetReader) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 33 with RowSetReader

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

the class StreamingHttpConnection method sendData.

/**
 * Called from query thread, specifically from the Screen operator,
 * for each batch.
 */
@Override
public void sendData(RpcOutcomeListener<Ack> listener, QueryDataPackage data) {
    VectorContainer batch = data.batch();
    try {
        if (batchCount == 0) {
            batchHolder = new BatchHolder(batch);
            reader = new PushResultSetReaderImpl(batchHolder);
            startSignal.await();
        }
        batchHolder.newBatch();
        RowSetReader batchReader = reader.start();
        emitBatch(batchReader);
        batchCount++;
    } catch (IOException e) {
        throw UserException.dataWriteError(e).addContext("Failed to send JSON results to the REST client").build(logger);
    } catch (InterruptedException e) {
        throw new DrillRuntimeException("Interrupted", e);
    } finally {
        batch.zeroVectors();
        listener.success(Acks.OK, null);
    }
}
Also used : BatchHolder(org.apache.drill.exec.physical.resultSet.impl.PushResultSetReaderImpl.BatchHolder) PushResultSetReaderImpl(org.apache.drill.exec.physical.resultSet.impl.PushResultSetReaderImpl) IOException(java.io.IOException) RowSetReader(org.apache.drill.exec.physical.rowSet.RowSetReader) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Aggregations

RowSetReader (org.apache.drill.exec.physical.rowSet.RowSetReader)33 Test (org.junit.Test)26 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)25 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)22 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)21 SubOperatorTest (org.apache.drill.test.SubOperatorTest)16 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)15 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)15 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)11 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)10 ArrayReader (org.apache.drill.exec.vector.accessor.ArrayReader)10 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)10 EvfTest (org.apache.drill.categories.EvfTest)8 VectorContainer (org.apache.drill.exec.record.VectorContainer)7 ResultSetOptions (org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions)6 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)6 TupleReader (org.apache.drill.exec.vector.accessor.TupleReader)6 ScalarReader (org.apache.drill.exec.vector.accessor.ScalarReader)4 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)4 BatchSchema (org.apache.drill.exec.record.BatchSchema)3