@Test public void generateSQL() throws Exception { String countFilter = ""; String newTable = "test"; List<String> tableNames = new ArrayList<>(); tableNames.add("blank_access_count_info"); String sql; sql = RuleExecutor.generateSQL(tableNames, newTable, countFilter, adapter); try { metaStoreHelper.execute(sql); metaStoreHelper.dropTable(newTable); } catch (Exception e) { Assert.assertTrue(false); } tableNames.add("blank_access_count_info"); sql = RuleExecutor.generateSQL(tableNames, newTable, countFilter, adapter); try { metaStoreHelper.execute(sql); metaStoreHelper.dropTable(newTable); } catch (Exception e) { Assert.assertTrue(false); } }
@VisibleForTesting static String generateSQL( List<String> tableNames, String newTable, String countFilter, MetaStore adapter) { String sqlFinal, sqlCreate; if (tableNames.size() <= 1) { String tableName = tableNames.size() == 0 ? "blank_access_count_info" : tableNames.get(0); sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM " + tableName + ";"; } else { String sqlPrefix = "SELECT fid, SUM(count) AS count FROM (\n"; String sqlUnion = "SELECT fid, count FROM " + tableNames.get(0) + " \n"; for (int i = 1; i < tableNames.size(); i++) { sqlUnion += "UNION ALL\n" + "SELECT fid, count FROM " + tableNames.get(i) + " \n"; } String sqlSufix = ") as tmp GROUP BY fid "; String sqlCountFilter = (countFilter == null || countFilter.length() == 0) ? "" : "HAVING SUM(count) " + countFilter; String sqlRe = sqlPrefix + sqlUnion + sqlSufix + sqlCountFilter; sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM (" + sqlRe + ") temp;"; } return sqlFinal; }
RuleExecutor implements Runnable { @VisibleForTesting static String generateSQL( List<String> tableNames, String newTable, String countFilter, MetaStore adapter) { String sqlFinal, sqlCreate; if (tableNames.size() <= 1) { String tableName = tableNames.size() == 0 ? "blank_access_count_info" : tableNames.get(0); sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM " + tableName + ";"; } else { String sqlPrefix = "SELECT fid, SUM(count) AS count FROM (\n"; String sqlUnion = "SELECT fid, count FROM " + tableNames.get(0) + " \n"; for (int i = 1; i < tableNames.size(); i++) { sqlUnion += "UNION ALL\n" + "SELECT fid, count FROM " + tableNames.get(i) + " \n"; } String sqlSufix = ") as tmp GROUP BY fid "; String sqlCountFilter = (countFilter == null || countFilter.length() == 0) ? "" : "HAVING SUM(count) " + countFilter; String sqlRe = sqlPrefix + sqlUnion + sqlSufix + sqlCountFilter; sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM (" + sqlRe + ") temp;"; } return sqlFinal; } }
RuleExecutor implements Runnable { @VisibleForTesting static String generateSQL( List<String> tableNames, String newTable, String countFilter, MetaStore adapter) { String sqlFinal, sqlCreate; if (tableNames.size() <= 1) { String tableName = tableNames.size() == 0 ? "blank_access_count_info" : tableNames.get(0); sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM " + tableName + ";"; } else { String sqlPrefix = "SELECT fid, SUM(count) AS count FROM (\n"; String sqlUnion = "SELECT fid, count FROM " + tableNames.get(0) + " \n"; for (int i = 1; i < tableNames.size(); i++) { sqlUnion += "UNION ALL\n" + "SELECT fid, count FROM " + tableNames.get(i) + " \n"; } String sqlSufix = ") as tmp GROUP BY fid "; String sqlCountFilter = (countFilter == null || countFilter.length() == 0) ? "" : "HAVING SUM(count) " + countFilter; String sqlRe = sqlPrefix + sqlUnion + sqlSufix + sqlCountFilter; sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM (" + sqlRe + ") temp;"; } return sqlFinal; } RuleExecutor(
      RuleManager ruleManager, ExecutionContext ctx, TranslateResult tr, MetaStore adapter); }
RuleExecutor implements Runnable { @VisibleForTesting static String generateSQL( List<String> tableNames, String newTable, String countFilter, MetaStore adapter) { String sqlFinal, sqlCreate; if (tableNames.size() <= 1) { String tableName = tableNames.size() == 0 ? "blank_access_count_info" : tableNames.get(0); sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM " + tableName + ";"; } else { String sqlPrefix = "SELECT fid, SUM(count) AS count FROM (\n"; String sqlUnion = "SELECT fid, count FROM " + tableNames.get(0) + " \n"; for (int i = 1; i < tableNames.size(); i++) { sqlUnion += "UNION ALL\n" + "SELECT fid, count FROM " + tableNames.get(i) + " \n"; } String sqlSufix = ") as tmp GROUP BY fid "; String sqlCountFilter = (countFilter == null || countFilter.length() == 0) ? "" : "HAVING SUM(count) " + countFilter; String sqlRe = sqlPrefix + sqlUnion + sqlSufix + sqlCountFilter; sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM (" + sqlRe + ") temp;"; } return sqlFinal; } RuleExecutor(
      RuleManager ruleManager, ExecutionContext ctx, TranslateResult tr, MetaStore adapter); TranslateResult getTranslateResult(); List<String> executeFileRuleQuery(); String callFunction(String funcName, List<Object> parameters); String genVirtualAccessCountTableTopValue(List<Object> parameters); String genVirtualAccessCountTableBottomValue(List<Object> parameters); String genVirtualAccessCountTableTopValueOnStoragePolicy(List<Object> parameters); String genVirtualAccessCountTableBottomValueOnStoragePolicy(List<Object> parameters); String genVirtualAccessCountTable(List<Object> parameters); @Override void run(); boolean isExited(); void setExited(); long getExitTime(); }
RuleExecutor implements Runnable { @VisibleForTesting static String generateSQL( List<String> tableNames, String newTable, String countFilter, MetaStore adapter) { String sqlFinal, sqlCreate; if (tableNames.size() <= 1) { String tableName = tableNames.size() == 0 ? "blank_access_count_info" : tableNames.get(0); sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM " + tableName + ";"; } else { String sqlPrefix = "SELECT fid, SUM(count) AS count FROM (\n"; String sqlUnion = "SELECT fid, count FROM " + tableNames.get(0) + " \n"; for (int i = 1; i < tableNames.size(); i++) { sqlUnion += "UNION ALL\n" + "SELECT fid, count FROM " + tableNames.get(i) + " \n"; } String sqlSufix = ") as tmp GROUP BY fid "; String sqlCountFilter = (countFilter == null || countFilter.length() == 0) ? "" : "HAVING SUM(count) " + countFilter; String sqlRe = sqlPrefix + sqlUnion + sqlSufix + sqlCountFilter; sqlCreate = "CREATE TABLE " + newTable + "(fid INTEGER NOT NULL, count INTEGER NOT NULL);"; try { adapter.execute(sqlCreate); } catch (MetaStoreException e) { LOG.error("Cannot create table " + newTable, e); } sqlFinal = "INSERT INTO " + newTable + " SELECT * FROM (" + sqlRe + ") temp;"; } return sqlFinal; } RuleExecutor(
      RuleManager ruleManager, ExecutionContext ctx, TranslateResult tr, MetaStore adapter); TranslateResult getTranslateResult(); List<String> executeFileRuleQuery(); String callFunction(String funcName, List<Object> parameters); String genVirtualAccessCountTableTopValue(List<Object> parameters); String genVirtualAccessCountTableBottomValue(List<Object> parameters); String genVirtualAccessCountTableTopValueOnStoragePolicy(List<Object> parameters); String genVirtualAccessCountTableBottomValueOnStoragePolicy(List<Object> parameters); String genVirtualAccessCountTable(List<Object> parameters); @Override void run(); boolean isExited(); void setExited(); long getExitTime();  }