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));
}
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<>();
}
}
Aggregations