Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Solve #1722, Rename and refine implementation of top N access count (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
littlezhou authored May 3, 2018
1 parent 107bd00 commit 772fa95
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public List<String> executeFileRuleQuery() {
if (index == tr.getRetSqlIndex()) {
ret = adapter.executeFilesPathQuery(sql);
} else {
if (sql != null && sql.length() > 3) {
sql = sql.trim();
if (sql.length() > 5) {
adapter.execute(sql);
}
}
Expand Down Expand Up @@ -145,7 +146,7 @@ public String callFunction(String funcName, List<Object> parameters) {
}
}

public String genVirtualAccessCountTableMaxValue(List<Object> parameters) {
public String genVirtualAccessCountTableTopValue(List<Object> parameters) {
List<Object> paraList = (List<Object>) parameters.get(0);
String table = (String) parameters.get(1);
String var = (String) parameters.get(2);
Expand All @@ -156,7 +157,7 @@ public String genVirtualAccessCountTableMaxValue(List<Object> parameters) {
try {
count = adapter.queryForLong(sql0);
} catch (MetaStoreException e) {
LOG.error("Get maximum access count from table '" + table + "' error.", e);
LOG.error("Get top access count from table '" + table + "' error.", e);
}
ctx.setProperty(var, count == null ? 0L : count);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public GeneralDao(DataSource dataSource) {

public Long queryForLong(String sql) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
Long x = jdbcTemplate.queryForObject(sql, Long.class);
return x;
return jdbcTemplate.queryForObject(sql, Long.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class FileObject extends SmartObject {
new Property("accessCount", ValueType.LONG,
Arrays.asList(ValueType.TIMEINTVAL),
"VIRTUAL_ACCESS_COUNT_TABLE", "", false, "count"));
PROPERTIES.put("accessCountMax",
new Property("accessCountMax", ValueType.LONG,
PROPERTIES.put("accessCountTop",
new Property("accessCountTop", ValueType.LONG,
Arrays.asList(ValueType.TIMEINTVAL, ValueType.LONG),
"VIRTUAL_ACCESS_COUNT_TABLE", "", false, "count"));
PROPERTIES.put("length",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public NodeTransResult doGenerateSql(TreeNode root, String tableName) throws IOE
return new NodeTransResult(virTab, realParas.formatParameters());
}

if (p.getPropertyName().equals("accessCountMax")) {
if (p.getPropertyName().equals("accessCountTop")) {
String rid = "";
if (transCtx != null) {
rid = transCtx.getRuleId() + "_";
Expand All @@ -897,9 +897,9 @@ public NodeTransResult doGenerateSql(TreeNode root, String tableName) throws IOE
sqlStatements.add("$@genVirtualAccessCountTable(" + virTab + ")");
dynamicParameters.put(virTab, Arrays.asList(realParas.getValues(), virTab));
}
String mStr = virTab + "_max_" + realParas.getValues().get(1).toString();
String mStr = virTab + "_top_" + realParas.getValues().get(1).toString();
String mStrValue = mStr + "_value";
sqlStatements.add("$@genVirtualAccessCountTableMaxValue(" + mStr + ")");
sqlStatements.add("$@genVirtualAccessCountTableTopValue(" + mStr + ")");
dynamicParameters.put(mStr, Arrays.asList(realParas.getValues(), virTab, mStrValue));
procAcc = true;
return new NodeTransResult(null, "$" + mStrValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TestSmartRuleStringParser {
public void testRuleTranslate() throws Exception {
List<String> rules = new LinkedList<>();
rules.add("file : path matches \"/test/*\" | sync -dest \"hdfs://remotecluster:port/somedir\"");
rules.add("file : accessCount(10min) > accessCountMax(10min, 10) | sleep -ms 0");
rules.add("file : accessCount(10min) > accessCountTop(10min, 10) | sleep -ms 0");

for (String rule : rules) {
parseRule(rule);
Expand Down

0 comments on commit 772fa95

Please sign in to comment.