use of org.smartdata.server.metastore.ExecutionContext in project SSM by Intel-bigdata.
the class TestSmartRuleParser method parseAndExecuteRule.
private void parseAndExecuteRule(String rule) throws Exception {
System.out.println("--> " + rule);
InputStream input = new ByteArrayInputStream(rule.getBytes());
ANTLRInputStream antlrInput = new ANTLRInputStream(input);
SmartRuleLexer lexer = new SmartRuleLexer(antlrInput);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SmartRuleParser parser = new SmartRuleParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(new SSMRuleErrorListener());
ParseTree tree = parser.ssmrule();
System.out.println("Parser tree: " + tree.toStringTree(parser));
System.out.println("Total number of errors: " + parseErrors.size());
SmartRuleVisitTranslator visitor = new SmartRuleVisitTranslator();
visitor.visit(tree);
System.out.println("\nQuery:");
TranslateResult result = visitor.generateSql();
int index = 1;
for (String sql : result.getSqlStatements()) {
System.out.println("" + index + ". " + sql);
index++;
}
if (parseErrors.size() > 0) {
throw new IOException("Error while parse rule");
}
ExecutionContext ctx = new ExecutionContext();
ctx.setProperty(ExecutionContext.RULE_ID, 2016);
DBAdapter dbAdapter = new DBAdapter(TestDBUtil.getTestDBInstance());
RuleQueryExecutor qe = new RuleQueryExecutor(null, ctx, result, dbAdapter);
List<String> paths = qe.executeFileRuleQuery();
index = 1;
System.out.println("\nFiles:");
for (String path : paths) {
System.out.println("" + index + ". " + path);
index++;
}
}
use of org.smartdata.server.metastore.ExecutionContext in project SSM by Intel-bigdata.
the class RuleContainer method doLaunchExecutor.
private RuleQueryExecutor doLaunchExecutor(RuleManager ruleManager) throws IOException {
RuleState state = ruleInfo.getState();
if (state == RuleState.ACTIVE || state == RuleState.DRYRUN) {
if (executor != null && !executor.isExited()) {
return null;
}
ExecutionContext ctx = new ExecutionContext();
ctx.setProperty(ExecutionContext.RULE_ID, ruleInfo.getId());
TranslationContext transCtx = new TranslationContext(ruleInfo.getId(), ruleInfo.getSubmitTime());
TranslateResult tr = executor != null ? executor.getTranslateResult() : ruleManager.doCheckRule(ruleInfo.getRuleText(), transCtx);
executor = new RuleQueryExecutor(ruleManager, ctx, tr, ruleManager.getDbAdapter());
return executor;
}
return null;
}
Aggregations