use of org.smartdata.server.metastore.tables.AccessCountTable in project SSM by Intel-bigdata.
the class TestDBAdapter method testCreateProportionView.
@Test
public void testCreateProportionView() throws Exception {
Statement statement = databaseTester.getConnection().getConnection().createStatement();
statement.execute(AccessCountTable.createTableSQL("table1"));
statement.execute(AccessCountTable.createTableSQL("table2"));
statement.execute(AccessCountTable.createTableSQL("table3"));
statement.execute(AccessCountTable.createTableSQL("expect"));
IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("accessCountTable.xml"));
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
AccessCountTable table3 = new AccessCountTable("table3", 0L, 10L, TimeGranularity.SECOND);
DBAdapter dbAdapter = new DBAdapter(databaseTester.getConnection().getConnection());
// 50%
AccessCountTable viewTable = new AccessCountTable(0L, 5L);
dbAdapter.createProportionView(viewTable, table3);
ITable actual = databaseTester.getConnection().createTable(viewTable.getTableName());
ITable expect = databaseTester.getConnection().createTable(table3.getTableName());
SortedTable sortedActual = new SortedTable(actual, new String[] { "fid" });
sortedActual.setUseComparable(true);
Assert.assertTrue(sortedActual.getRowCount() == expect.getRowCount());
for (int i = 0; i < expect.getRowCount(); i++) {
Integer actualAC = (Integer) sortedActual.getValue(i, AccessCountTable.ACCESSCOUNT_FIELD);
Integer expectAC = (Integer) expect.getValue(i, AccessCountTable.ACCESSCOUNT_FIELD);
Assert.assertTrue(actualAC == expectAC / 2);
}
}
use of org.smartdata.server.metastore.tables.AccessCountTable in project SSM by Intel-bigdata.
the class RuleQueryExecutor 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 (SQLException e) {
LOG.error("Rule " + ctx.getRuleId() + " get access info tables exception", e);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Rule " + ctx.getRuleId() + " got " + accTables.size() + " tables.");
}
if (accTables == null || accTables.size() == 0) {
return tableNames;
}
for (AccessCountTable t : accTables) {
tableNames.add(t.getTableName());
if (t.isView()) {
dynamicCleanups.push("DROP VIEW " + t.getTableName() + ";");
}
}
return tableNames;
}
Aggregations