Search in sources :

Example 1 with FileAccessInfo

use of org.smartdata.model.FileAccessInfo in project SSM by Intel-bigdata.

the class TestTableAggregator method testGetTopN.

@Test
public void testGetTopN() throws Exception {
    createTables(databaseTester.getConnection());
    IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("accessCountTable.xml"));
    databaseTester.setDataSet(dataSet);
    databaseTester.onSetup();
    MetaStore metaStore = new MetaStore(druidPool);
    prepareFiles(metaStore);
    AccessCountTable table1 = new AccessCountTable("table1", 0L, 0L, false);
    AccessCountTable table2 = new AccessCountTable("table2", 0L, 0L, false);
    AccessCountTable table3 = new AccessCountTable("table3", 0L, 0L, false);
    List<FileAccessInfo> accessInfos = metaStore.getHotFiles(Arrays.asList(table1, table2, table3), 1);
    Assert.assertTrue(accessInfos.size() == 1);
    FileAccessInfo expected1 = new FileAccessInfo(103L, "/file3", 7);
    Assert.assertTrue(accessInfos.get(0).equals(expected1));
    List<FileAccessInfo> accessInfos2 = metaStore.getHotFiles(Arrays.asList(table1, table2, table3), 2);
    List<FileAccessInfo> expected2 = Arrays.asList(expected1, new FileAccessInfo(102L, "/file2", 6));
    Assert.assertTrue(accessInfos2.size() == expected2.size());
    Assert.assertTrue(accessInfos2.containsAll(expected2));
}
Also used : MetaStore(org.smartdata.metastore.MetaStore) FileAccessInfo(org.smartdata.model.FileAccessInfo) IDataSet(org.dbunit.dataset.IDataSet) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) DBTest(org.smartdata.metastore.DBTest) Test(org.junit.Test)

Example 2 with FileAccessInfo

use of org.smartdata.model.FileAccessInfo 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

FileAccessInfo (org.smartdata.model.FileAccessInfo)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IDataSet (org.dbunit.dataset.IDataSet)1 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)1 Test (org.junit.Test)1 DBTest (org.smartdata.metastore.DBTest)1 MetaStore (org.smartdata.metastore.MetaStore)1 AccessCountTable (org.smartdata.metastore.dao.AccessCountTable)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1