Search in sources :

Example 1 with AccessCountTable

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);
    }
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) Statement(java.sql.Statement) SortedTable(org.dbunit.dataset.SortedTable) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) AccessCountTable(org.smartdata.server.metastore.tables.AccessCountTable) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test)

Example 2 with AccessCountTable

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) AccessCountTable(org.smartdata.server.metastore.tables.AccessCountTable)

Aggregations

AccessCountTable (org.smartdata.server.metastore.tables.AccessCountTable)2 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 IDataSet (org.dbunit.dataset.IDataSet)1 ITable (org.dbunit.dataset.ITable)1 SortedTable (org.dbunit.dataset.SortedTable)1 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)1 Test (org.junit.Test)1 DBAdapter (org.smartdata.server.metastore.DBAdapter)1