Search in sources :

Example 1 with AccessCountTable

use of org.smartdata.metastore.dao.AccessCountTable in project SSM by Intel-bigdata.

the class RuleExecutor method getAccessCountTablesDuringLast.

/**
 * @param lastInterval
 * @return
 */
private List<String> getAccessCountTablesDuringLast(long lastInterval) {
    List<String> tableNames = new ArrayList<>();
    if (ruleManager == null || ruleManager.getStatesManager() == null) {
        return tableNames;
    }
    List<AccessCountTable> accTables = null;
    try {
        accTables = ruleManager.getStatesManager().getTablesInLast(lastInterval);
    } catch (MetaStoreException e) {
        LOG.error("Rule " + ctx.getRuleId() + " get access info tables exception", e);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Rule " + ctx.getRuleId() + " got " + accTables.size() + " tables:");
        int idx = 1;
        for (AccessCountTable t : accTables) {
            LOG.debug(idx + ".  " + (t.isEphemeral() ? " [TABLE] " : "        ") + t.getTableName() + " ");
        }
    }
    if (accTables == null || accTables.size() == 0) {
        return tableNames;
    }
    for (AccessCountTable t : accTables) {
        tableNames.add(t.getTableName());
        if (t.isEphemeral()) {
            dynamicCleanups.push("DROP TABLE IF EXISTS " + t.getTableName() + ";");
        }
    }
    return tableNames;
}
Also used : MetaStoreException(org.smartdata.metastore.MetaStoreException) ArrayList(java.util.ArrayList) AccessCountTable(org.smartdata.metastore.dao.AccessCountTable)

Example 2 with AccessCountTable

use of org.smartdata.metastore.dao.AccessCountTable in project SSM by Intel-bigdata.

the class MetaStore method getHotFiles.

public List<FileAccessInfo> getHotFiles(List<AccessCountTable> tables, int topNum) throws MetaStoreException {
    Iterator<AccessCountTable> tableIterator = tables.iterator();
    if (tableIterator.hasNext()) {
        try {
            Map<Long, Integer> accessCounts = accessCountDao.getHotFiles(tables, topNum);
            if (accessCounts.size() == 0) {
                return new ArrayList<>();
            }
            Map<Long, String> idToPath = getFilePaths(accessCounts.keySet());
            List<FileAccessInfo> result = new ArrayList<>();
            for (Map.Entry<Long, Integer> entry : accessCounts.entrySet()) {
                Long fid = entry.getKey();
                if (idToPath.containsKey(fid) && entry.getValue() > 0) {
                    result.add(new FileAccessInfo(fid, idToPath.get(fid), entry.getValue()));
                }
            }
            return result;
        } catch (EmptyResultDataAccessException e) {
            return new ArrayList<>();
        } catch (Exception e) {
            throw new MetaStoreException(e);
        } finally {
            for (AccessCountTable accessCountTable : tables) {
                if (accessCountTable.isEphemeral()) {
                    this.dropTable(accessCountTable.getTableName());
                }
            }
        }
    } else {
        return new ArrayList<>();
    }
}
Also used : FileAccessInfo(org.smartdata.model.FileAccessInfo) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) SQLException(java.sql.SQLException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) AccessCountTable(org.smartdata.metastore.dao.AccessCountTable) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)2 AccessCountTable (org.smartdata.metastore.dao.AccessCountTable)2 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MetaStoreException (org.smartdata.metastore.MetaStoreException)1 FileAccessInfo (org.smartdata.model.FileAccessInfo)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1