Search in sources :

Example 1 with LogicalInputSplit

use of org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit in project drill by axbaretto.

the class HiveScan method getSpecificScan.

@Override
public SubScan getSpecificScan(final int minorFragmentId) throws ExecutionSetupException {
    try {
        final List<LogicalInputSplit> splits = mappings.get(minorFragmentId);
        List<HivePartitionWrapper> parts = Lists.newArrayList();
        final List<List<String>> encodedInputSplits = Lists.newArrayList();
        final List<String> splitTypes = Lists.newArrayList();
        for (final LogicalInputSplit split : splits) {
            final Partition splitPartition = split.getPartition();
            if (splitPartition != null) {
                HiveTableWithColumnCache table = hiveReadEntry.getTable();
                parts.add(createPartitionWithSpecColumns(new HiveTableWithColumnCache(table, new ColumnListsCache(table)), splitPartition));
            }
            encodedInputSplits.add(split.serialize());
            splitTypes.add(split.getType());
        }
        if (parts.size() <= 0) {
            parts = null;
        }
        final HiveReadEntry subEntry = new HiveReadEntry(hiveReadEntry.getTableWrapper(), parts);
        return new HiveSubScan(getUserName(), encodedInputSplits, subEntry, splitTypes, columns, hiveStoragePlugin);
    } catch (IOException | ReflectiveOperationException e) {
        throw new ExecutionSetupException(e);
    }
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) Partition(org.apache.hadoop.hive.metastore.api.Partition) LogicalInputSplit(org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit) IOException(java.io.IOException) HivePartitionWrapper(org.apache.drill.exec.store.hive.HiveTableWrapper.HivePartitionWrapper) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with LogicalInputSplit

use of org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit in project drill by axbaretto.

the class HiveScan method getOperatorAffinity.

@Override
public List<EndpointAffinity> getOperatorAffinity() {
    final Map<String, DrillbitEndpoint> endpointMap = new HashMap<>();
    for (final DrillbitEndpoint endpoint : hiveStoragePlugin.getContext().getBits()) {
        endpointMap.put(endpoint.getAddress(), endpoint);
        logger.debug("endpoing address: {}", endpoint.getAddress());
    }
    final Map<DrillbitEndpoint, EndpointAffinity> affinityMap = new HashMap<>();
    try {
        long totalSize = 0;
        final List<LogicalInputSplit> inputSplits = getInputSplits();
        for (final LogicalInputSplit split : inputSplits) {
            totalSize += Math.max(1, split.getLength());
        }
        for (final LogicalInputSplit split : inputSplits) {
            final float affinity = ((float) Math.max(1, split.getLength())) / totalSize;
            for (final String loc : split.getLocations()) {
                logger.debug("split location: {}", loc);
                final DrillbitEndpoint endpoint = endpointMap.get(loc);
                if (endpoint != null) {
                    if (affinityMap.containsKey(endpoint)) {
                        affinityMap.get(endpoint).addAffinity(affinity);
                    } else {
                        affinityMap.put(endpoint, new EndpointAffinity(endpoint, affinity));
                    }
                }
            }
        }
    } catch (final IOException e) {
        throw new DrillRuntimeException(e);
    }
    for (final DrillbitEndpoint ep : affinityMap.keySet()) {
        Preconditions.checkNotNull(ep);
    }
    for (final EndpointAffinity a : affinityMap.values()) {
        Preconditions.checkNotNull(a.getEndpoint());
    }
    return Lists.newArrayList(affinityMap.values());
}
Also used : DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) HashMap(java.util.HashMap) LogicalInputSplit(org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit) EndpointAffinity(org.apache.drill.exec.physical.EndpointAffinity) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 3 with LogicalInputSplit

use of org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit in project drill by apache.

the class HiveScan method getOperatorAffinity.

@Override
public List<EndpointAffinity> getOperatorAffinity() {
    final Map<String, DrillbitEndpoint> endpointMap = new HashMap<>();
    for (final DrillbitEndpoint endpoint : hiveStoragePlugin.getContext().getBits()) {
        endpointMap.put(endpoint.getAddress(), endpoint);
        logger.debug("Endpoint address: {}", endpoint.getAddress());
    }
    final Map<DrillbitEndpoint, EndpointAffinity> affinityMap = new HashMap<>();
    try {
        long totalSize = 0;
        final List<LogicalInputSplit> inputSplits = getInputSplits();
        for (final LogicalInputSplit split : inputSplits) {
            totalSize += Math.max(1, split.getLength());
        }
        for (final LogicalInputSplit split : inputSplits) {
            final float affinity = ((float) Math.max(1, split.getLength())) / totalSize;
            for (final String loc : split.getLocations()) {
                logger.debug("Split location: {}", loc);
                final DrillbitEndpoint endpoint = endpointMap.get(loc);
                if (endpoint != null) {
                    if (affinityMap.containsKey(endpoint)) {
                        affinityMap.get(endpoint).addAffinity(affinity);
                    } else {
                        affinityMap.put(endpoint, new EndpointAffinity(endpoint, affinity));
                    }
                }
            }
        }
    } catch (final IOException e) {
        throw new DrillRuntimeException(e);
    }
    return new ArrayList<>(affinityMap.values());
}
Also used : HashMap(java.util.HashMap) LogicalInputSplit(org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) EndpointAffinity(org.apache.drill.exec.physical.EndpointAffinity) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 4 with LogicalInputSplit

use of org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit in project drill by apache.

the class HiveScan method getSpecificScan.

@Override
public SubScan getSpecificScan(final int minorFragmentId) throws ExecutionSetupException {
    try {
        final List<LogicalInputSplit> splits = mappings.get(minorFragmentId);
        List<HivePartitionWrapper> parts = new ArrayList<>();
        final List<List<String>> encodedInputSplits = new ArrayList<>();
        final List<String> splitTypes = new ArrayList<>();
        for (final LogicalInputSplit split : splits) {
            final Partition splitPartition = split.getPartition();
            if (splitPartition != null) {
                HiveTableWithColumnCache table = hiveReadEntry.getTable();
                parts.add(createPartitionWithSpecColumns(new HiveTableWithColumnCache(table, new ColumnListsCache(table)), splitPartition));
            }
            encodedInputSplits.add(split.serialize());
            splitTypes.add(split.getType());
        }
        if (parts.size() <= 0) {
            parts = null;
        }
        final HiveReadEntry subEntry = new HiveReadEntry(hiveReadEntry.getTableWrapper(), parts);
        return new HiveSubScan(getUserName(), encodedInputSplits, subEntry, splitTypes, columns, hiveStoragePlugin, confProperties);
    } catch (IOException | ReflectiveOperationException e) {
        throw new ExecutionSetupException(e);
    }
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) Partition(org.apache.hadoop.hive.metastore.api.Partition) LogicalInputSplit(org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HivePartitionWrapper(org.apache.drill.exec.store.hive.HiveTableWrapper.HivePartitionWrapper) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with LogicalInputSplit

use of org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit in project drill by axbaretto.

the class HiveScan method applyAssignments.

@Override
public void applyAssignments(final List<CoordinationProtos.DrillbitEndpoint> endpoints) {
    mappings = new ArrayList<>();
    for (int i = 0; i < endpoints.size(); i++) {
        mappings.add(new ArrayList<LogicalInputSplit>());
    }
    final int count = endpoints.size();
    final List<LogicalInputSplit> inputSplits = getInputSplits();
    for (int i = 0; i < inputSplits.size(); i++) {
        mappings.get(i % count).add(inputSplits.get(i));
    }
}
Also used : LogicalInputSplit(org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)

Aggregations

LogicalInputSplit (org.apache.drill.exec.store.hive.HiveMetadataProvider.LogicalInputSplit)6 IOException (java.io.IOException)4 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 List (java.util.List)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)2 EndpointAffinity (org.apache.drill.exec.physical.EndpointAffinity)2 HivePartitionWrapper (org.apache.drill.exec.store.hive.HiveTableWrapper.HivePartitionWrapper)2 Partition (org.apache.hadoop.hive.metastore.api.Partition)2