Search in sources :

Example 1 with IndexDesc

use of com.mapr.db.index.IndexDesc in project drill by apache.

the class MapRDBIndexDiscover method getTableIndexFromMFS.

/**
 * For a given table name get the list of indexes defined on the table according to the visibility of
 * the indexes based on permissions.
 * @param tableName table name
 * @return an IndexCollection representing the list of indexes for that table
 */
private IndexCollection getTableIndexFromMFS(String tableName) {
    try {
        Set<DrillIndexDescriptor> idxSet = new HashSet<>();
        Collection<IndexDesc> indexes = admin().getTableIndexes(new Path(tableName));
        if (indexes.size() == 0) {
            logger.error("No index returned from Admin.getTableIndexes for table {}", tableName);
            return null;
        }
        for (IndexDesc idx : indexes) {
            DrillIndexDescriptor hbaseIdx = buildIndexDescriptor(tableName, idx);
            if (hbaseIdx == null) {
                // not able to build a valid index based on the index info from MFS
                logger.error("Not able to build index for {}", idx.toString());
                continue;
            }
            idxSet.add(hbaseIdx);
        }
        if (idxSet.size() == 0) {
            logger.error("No index found for table {}.", tableName);
            return null;
        }
        return new DrillIndexCollection(getOriginalScanRel(), idxSet);
    } catch (DBException ex) {
        logger.error("Could not get table index from File system.", ex);
    } catch (InvalidIndexDefinitionException ex) {
        logger.error("Invalid index definition detected.", ex);
    }
    return null;
}
Also used : Path(org.apache.hadoop.fs.Path) SchemaPath(org.apache.drill.common.expression.SchemaPath) FieldPath(org.ojai.FieldPath) DBException(com.mapr.db.exceptions.DBException) IndexDesc(com.mapr.db.index.IndexDesc) HashSet(java.util.HashSet)

Example 2 with IndexDesc

use of com.mapr.db.index.IndexDesc in project drill by apache.

the class JsonTableGroupScan method getAverageRowSizeStats.

/**
 * Get the estimated average rowsize. DO NOT call this API directly.
 * Call the stats API instead which modifies the counts based on preference options.
 * @param index to use for generating the estimate
 * @return row count post filtering
 */
public MapRDBStatisticsPayload getAverageRowSizeStats(IndexDescriptor index) {
    IndexDesc indexDesc = null;
    double avgRowSize = AVG_ROWSIZE_UNKNOWN;
    if (index != null) {
        indexDesc = (IndexDesc) ((MapRDBIndexDescriptor) index).getOriginalDesc();
    }
    // If no index is specified, get it from the primary table
    if (indexDesc == null && scanSpec.isSecondaryIndex()) {
        throw new UnsupportedOperationException("getAverageRowSizeStats should be invoked on primary table");
    }
    // Get the index table or primary table and use the DB API to get the estimated number of rows. For size estimates,
    // we assume that all the columns would be read from the disk.
    final Table table = this.formatPlugin.getJsonTableCache().getTable(scanSpec.getTableName(), indexDesc, getUserName());
    if (table != null) {
        final MetaTable metaTable = table.getMetaTable();
        if (metaTable != null) {
            avgRowSize = metaTable.getAverageRowSize();
        }
    }
    logger.debug("index_plan_info: getEstimatedRowCount obtained from DB Client for {}: indexName: {}, indexInfo: {}, " + "avgRowSize: {}, estimatedSize {}", this, (indexDesc == null ? "null" : indexDesc.getIndexName()), (indexDesc == null ? "null" : indexDesc.getIndexInfo()), avgRowSize, fullTableEstimatedSize);
    return new MapRDBStatisticsPayload(ROWCOUNT_UNKNOWN, ROWCOUNT_UNKNOWN, avgRowSize);
}
Also used : Table(com.mapr.db.Table) MetaTable(com.mapr.db.MetaTable) MapRDBStatisticsPayload(org.apache.drill.exec.planner.index.MapRDBStatisticsPayload) IndexDesc(com.mapr.db.index.IndexDesc) MetaTable(com.mapr.db.MetaTable) MapRDBIndexDescriptor(org.apache.drill.exec.planner.index.MapRDBIndexDescriptor)

Example 3 with IndexDesc

use of com.mapr.db.index.IndexDesc in project drill by apache.

the class MapRDBFormatMatcher method isReadableIndex.

/**
 * Get an instance of DrillTable for a particular native secondary index
 * @param fs
 * @param selection
 * @param fsPlugin
 * @param storageEngineName
 * @param userName
 * @param secondaryIndexDesc
 * @return
 * @throws IOException
 */
public DrillTable isReadableIndex(DrillFileSystem fs, FileSelection selection, FileSystemPlugin fsPlugin, String storageEngineName, String userName, IndexDescriptor secondaryIndexDesc) throws IOException {
    FileStatus status = selection.getFirstPath(fs);
    if (!isFileReadable(fs, status)) {
        return null;
    }
    MapRDBFormatPlugin fp = (MapRDBFormatPlugin) getFormatPlugin();
    DrillTable dt = new DynamicDrillTable(fsPlugin, storageEngineName, userName, new FormatSelection(fp.getConfig(), selection));
    // TODO:  Create groupScan using index descriptor
    dt.setGroupScan(fp.getGroupScan(userName, selection, null, /* columns */
    (IndexDesc) ((MapRDBIndexDescriptor) secondaryIndexDesc).getOriginalDesc(), null));
    return dt;
}
Also used : MapRFileStatus(com.mapr.fs.MapRFileStatus) FileStatus(org.apache.hadoop.fs.FileStatus) DynamicDrillTable(org.apache.drill.exec.planner.logical.DynamicDrillTable) DrillTable(org.apache.drill.exec.planner.logical.DrillTable) DynamicDrillTable(org.apache.drill.exec.planner.logical.DynamicDrillTable) FormatSelection(org.apache.drill.exec.store.dfs.FormatSelection) IndexDesc(com.mapr.db.index.IndexDesc)

Aggregations

IndexDesc (com.mapr.db.index.IndexDesc)3 MetaTable (com.mapr.db.MetaTable)1 Table (com.mapr.db.Table)1 DBException (com.mapr.db.exceptions.DBException)1 MapRFileStatus (com.mapr.fs.MapRFileStatus)1 HashSet (java.util.HashSet)1 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 MapRDBIndexDescriptor (org.apache.drill.exec.planner.index.MapRDBIndexDescriptor)1 MapRDBStatisticsPayload (org.apache.drill.exec.planner.index.MapRDBStatisticsPayload)1 DrillTable (org.apache.drill.exec.planner.logical.DrillTable)1 DynamicDrillTable (org.apache.drill.exec.planner.logical.DynamicDrillTable)1 FormatSelection (org.apache.drill.exec.store.dfs.FormatSelection)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 Path (org.apache.hadoop.fs.Path)1 FieldPath (org.ojai.FieldPath)1