Search in sources :

Example 1 with TabletFragmentInfo

use of org.apache.drill.exec.store.mapr.db.TabletFragmentInfo in project drill by apache.

the class JsonTableGroupScan method computeRegionsToScan.

/**
   * Compute regions to scan based on the scanSpec
   */
private void computeRegionsToScan() {
    boolean foundStartRegion = false;
    regionsToScan = new TreeMap<TabletFragmentInfo, String>();
    for (TabletInfo tabletInfo : tabletInfos) {
        TabletInfoImpl tabletInfoImpl = (TabletInfoImpl) tabletInfo;
        if (!foundStartRegion && !isNullOrEmpty(scanSpec.getStartRow()) && !tabletInfoImpl.containsRow(scanSpec.getStartRow())) {
            continue;
        }
        foundStartRegion = true;
        regionsToScan.put(new TabletFragmentInfo(tabletInfoImpl), tabletInfo.getLocations()[0]);
        if (!isNullOrEmpty(scanSpec.getStopRow()) && tabletInfoImpl.containsRow(scanSpec.getStopRow())) {
            break;
        }
    }
}
Also used : TabletInfoImpl(com.mapr.db.impl.TabletInfoImpl) TabletFragmentInfo(org.apache.drill.exec.store.mapr.db.TabletFragmentInfo) TabletInfo(com.mapr.db.TabletInfo)

Example 2 with TabletFragmentInfo

use of org.apache.drill.exec.store.mapr.db.TabletFragmentInfo in project drill by apache.

the class JsonTableGroupScan method getRegionsToScan.

protected NavigableMap<TabletFragmentInfo, String> getRegionsToScan(int scanRangeSizeMB) {
    // If regionsToScan already computed, just return.
    double estimatedRowCount = ROWCOUNT_UNKNOWN;
    if (doNotAccessRegionsToScan == null) {
        final Table t = this.formatPlugin.getJsonTableCache().getTable(scanSpec.getTableName(), scanSpec.getIndexDesc(), getUserName());
        final MetaTable metaTable = t.getMetaTable();
        QueryCondition scanSpecCondition = scanSpec.getCondition();
        List<ScanRange> scanRanges = (scanSpecCondition == null) ? metaTable.getScanRanges(scanRangeSizeMB) : metaTable.getScanRanges(scanSpecCondition, scanRangeSizeMB);
        logger.debug("getRegionsToScan() with scanSpec {}: table={}, index={}, condition={}, sizeMB={}, #ScanRanges={}", System.identityHashCode(scanSpec), scanSpec.getTableName(), scanSpec.getIndexName(), scanSpec.getCondition() == null ? "null" : scanSpec.getCondition(), scanRangeSizeMB, scanRanges == null ? "null" : scanRanges.size());
        final TreeMap<TabletFragmentInfo, String> regionsToScan = new TreeMap<>();
        if (isIndexScan()) {
            String idxIdentifier = stats.buildUniqueIndexIdentifier(scanSpec.getIndexDesc().getPrimaryTablePath(), scanSpec.getIndexDesc().getIndexName());
            if (stats.isStatsAvailable()) {
                estimatedRowCount = stats.getRowCount(scanSpec.getCondition(), idxIdentifier);
            }
        } else {
            if (stats.isStatsAvailable()) {
                estimatedRowCount = stats.getRowCount(scanSpec.getCondition(), null);
            }
        }
        // If limit pushdown has occurred - factor it in the rowcount
        if (this.maxRecordsToRead > 0) {
            estimatedRowCount = Math.min(estimatedRowCount, this.maxRecordsToRead);
        }
        // If the estimated row count > 0 then scan ranges must be > 0
        Preconditions.checkState(estimatedRowCount == ROWCOUNT_UNKNOWN || estimatedRowCount == 0 || (scanRanges != null && scanRanges.size() > 0), String.format("#Scan ranges should be greater than 0 since estimated rowcount=[%f]", estimatedRowCount));
        if (scanRanges != null && scanRanges.size() > 0) {
            // set the start-row of the scanspec as the start-row of the first scan range
            ScanRange firstRange = scanRanges.get(0);
            QueryCondition firstCondition = firstRange.getCondition();
            byte[] firstStartRow = ((ConditionImpl) firstCondition).getRowkeyRanges().get(0).getStartRow();
            scanSpec.setStartRow(firstStartRow);
            // set the stop-row of ScanSpec as the stop-row of the last scan range
            ScanRange lastRange = scanRanges.get(scanRanges.size() - 1);
            QueryCondition lastCondition = lastRange.getCondition();
            List<RowkeyRange> rowkeyRanges = ((ConditionImpl) lastCondition).getRowkeyRanges();
            byte[] lastStopRow = rowkeyRanges.get(rowkeyRanges.size() - 1).getStopRow();
            scanSpec.setStopRow(lastStopRow);
            for (ScanRange range : scanRanges) {
                TabletInfoImpl tabletInfoImpl = (TabletInfoImpl) range;
                regionsToScan.put(new TabletFragmentInfo(tabletInfoImpl), range.getLocations()[0]);
            }
        }
        setRegionsToScan(regionsToScan);
    }
    return doNotAccessRegionsToScan;
}
Also used : TabletInfoImpl(com.mapr.db.impl.TabletInfoImpl) Table(com.mapr.db.Table) MetaTable(com.mapr.db.MetaTable) ScanRange(com.mapr.db.scan.ScanRange) TreeMap(java.util.TreeMap) ConditionImpl(com.mapr.db.impl.ConditionImpl) MetaTable(com.mapr.db.MetaTable) QueryCondition(org.ojai.store.QueryCondition) TabletFragmentInfo(org.apache.drill.exec.store.mapr.db.TabletFragmentInfo) RowkeyRange(com.mapr.db.impl.ConditionNode.RowkeyRange)

Example 3 with TabletFragmentInfo

use of org.apache.drill.exec.store.mapr.db.TabletFragmentInfo in project drill by axbaretto.

the class BinaryTableGroupScan method init.

private void init() {
    logger.debug("Getting region locations");
    TableName tableName = TableName.valueOf(hbaseScanSpec.getTableName());
    try (Admin admin = formatPlugin.getConnection().getAdmin();
        RegionLocator locator = formatPlugin.getConnection().getRegionLocator(tableName)) {
        hTableDesc = admin.getTableDescriptor(tableName);
        // Fetch tableStats only once and cache it.
        if (tableStats == null) {
            tableStats = new MapRDBTableStats(getHBaseConf(), hbaseScanSpec.getTableName());
        }
        boolean foundStartRegion = false;
        regionsToScan = new TreeMap<>();
        List<HRegionLocation> regionLocations = locator.getAllRegionLocations();
        for (HRegionLocation regionLocation : regionLocations) {
            HRegionInfo regionInfo = regionLocation.getRegionInfo();
            if (!foundStartRegion && hbaseScanSpec.getStartRow() != null && hbaseScanSpec.getStartRow().length != 0 && !regionInfo.containsRow(hbaseScanSpec.getStartRow())) {
                continue;
            }
            foundStartRegion = true;
            regionsToScan.put(new TabletFragmentInfo(regionInfo), regionLocation.getHostname());
            if (hbaseScanSpec.getStopRow() != null && hbaseScanSpec.getStopRow().length != 0 && regionInfo.containsRow(hbaseScanSpec.getStopRow())) {
                break;
            }
        }
    } catch (Exception e) {
        throw new DrillRuntimeException("Error getting region info for table: " + hbaseScanSpec.getTableName(), e);
    }
    HBaseUtils.verifyColumns(columns, hTableDesc);
}
Also used : MapRDBTableStats(org.apache.drill.exec.store.mapr.db.MapRDBTableStats) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) Admin(org.apache.hadoop.hbase.client.Admin) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) TabletFragmentInfo(org.apache.drill.exec.store.mapr.db.TabletFragmentInfo) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) IOException(java.io.IOException)

Example 4 with TabletFragmentInfo

use of org.apache.drill.exec.store.mapr.db.TabletFragmentInfo in project drill by axbaretto.

the class JsonTableGroupScan method computeRegionsToScan.

/**
 * Compute regions to scan based on the scanSpec
 */
private void computeRegionsToScan() {
    boolean foundStartRegion = false;
    regionsToScan = new TreeMap<TabletFragmentInfo, String>();
    for (TabletInfo tabletInfo : tabletInfos) {
        TabletInfoImpl tabletInfoImpl = (TabletInfoImpl) tabletInfo;
        if (!foundStartRegion && !isNullOrEmpty(scanSpec.getStartRow()) && !tabletInfoImpl.containsRow(scanSpec.getStartRow())) {
            continue;
        }
        foundStartRegion = true;
        regionsToScan.put(new TabletFragmentInfo(tabletInfoImpl), tabletInfo.getLocations()[0]);
        if (!isNullOrEmpty(scanSpec.getStopRow()) && tabletInfoImpl.containsRow(scanSpec.getStopRow())) {
            break;
        }
    }
}
Also used : TabletInfoImpl(com.mapr.db.impl.TabletInfoImpl) TabletFragmentInfo(org.apache.drill.exec.store.mapr.db.TabletFragmentInfo) TabletInfo(com.mapr.db.TabletInfo)

Example 5 with TabletFragmentInfo

use of org.apache.drill.exec.store.mapr.db.TabletFragmentInfo in project drill by apache.

the class BinaryTableGroupScan method init.

private void init() {
    logger.debug("Getting region locations");
    TableName tableName = TableName.valueOf(hbaseScanSpec.getTableName());
    try (Admin admin = formatPlugin.getConnection().getAdmin();
        RegionLocator locator = formatPlugin.getConnection().getRegionLocator(tableName)) {
        hTableDesc = admin.getTableDescriptor(tableName);
        // Fetch tableStats only once and cache it.
        if (tableStats == null) {
            tableStats = new MapRDBTableStats(getHBaseConf(), hbaseScanSpec.getTableName());
        }
        boolean foundStartRegion = false;
        final TreeMap<TabletFragmentInfo, String> regionsToScan = new TreeMap<>();
        List<HRegionLocation> regionLocations = locator.getAllRegionLocations();
        for (HRegionLocation regionLocation : regionLocations) {
            HRegionInfo regionInfo = regionLocation.getRegionInfo();
            if (!foundStartRegion && hbaseScanSpec.getStartRow() != null && hbaseScanSpec.getStartRow().length != 0 && !regionInfo.containsRow(hbaseScanSpec.getStartRow())) {
                continue;
            }
            foundStartRegion = true;
            regionsToScan.put(new TabletFragmentInfo(regionInfo), regionLocation.getHostname());
            if (hbaseScanSpec.getStopRow() != null && hbaseScanSpec.getStopRow().length != 0 && regionInfo.containsRow(hbaseScanSpec.getStopRow())) {
                break;
            }
        }
        setRegionsToScan(regionsToScan);
    } catch (Exception e) {
        throw new DrillRuntimeException("Error getting region info for table: " + hbaseScanSpec.getTableName(), e);
    }
    HBaseUtils.verifyColumns(columns, hTableDesc);
}
Also used : MapRDBTableStats(org.apache.drill.exec.store.mapr.db.MapRDBTableStats) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Admin(org.apache.hadoop.hbase.client.Admin) TreeMap(java.util.TreeMap) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) TabletFragmentInfo(org.apache.drill.exec.store.mapr.db.TabletFragmentInfo)

Aggregations

TabletFragmentInfo (org.apache.drill.exec.store.mapr.db.TabletFragmentInfo)5 TabletInfoImpl (com.mapr.db.impl.TabletInfoImpl)3 TabletInfo (com.mapr.db.TabletInfo)2 TreeMap (java.util.TreeMap)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)2 MapRDBTableStats (org.apache.drill.exec.store.mapr.db.MapRDBTableStats)2 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)2 TableName (org.apache.hadoop.hbase.TableName)2 Admin (org.apache.hadoop.hbase.client.Admin)2 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)2 MetaTable (com.mapr.db.MetaTable)1 Table (com.mapr.db.Table)1 ConditionImpl (com.mapr.db.impl.ConditionImpl)1 RowkeyRange (com.mapr.db.impl.ConditionNode.RowkeyRange)1 ScanRange (com.mapr.db.scan.ScanRange)1 IOException (java.io.IOException)1 QueryCondition (org.ojai.store.QueryCondition)1