use of org.smartdata.model.rule.TranslateResult in project SSM by Intel-bigdata.
the class SmartRuleStringParser method doTranslate.
private TranslateResult doTranslate(String rule) throws IOException {
parseErrors.clear();
parserErrorMessage = "";
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();
if (parseErrors.size() > 0) {
throw new IOException(parserErrorMessage);
}
SmartRuleVisitTranslator visitor = new SmartRuleVisitTranslator(ctx);
try {
visitor.visit(tree);
} catch (RuntimeException e) {
throw new IOException(e.getMessage());
}
TranslateResult result = visitor.generateSql();
return result;
}
use of org.smartdata.model.rule.TranslateResult in project SSM by Intel-bigdata.
the class RuleInfoRepo method doLaunchExecutor.
private RuleExecutor 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.setRuleId(ruleInfo.getId());
TranslationContext transCtx = new TranslationContext(ruleInfo.getId(), ruleInfo.getSubmitTime());
TranslateResult tr = executor != null ? executor.getTranslateResult() : new SmartRuleStringParser(ruleInfo.getRuleText(), transCtx, conf).translate();
List<RuleExecutorPlugin> plugins = RuleExecutorPluginManager.getPlugins();
for (RuleExecutorPlugin plugin : plugins) {
plugin.onNewRuleExecutor(ruleInfo, tr);
}
executor = new RuleExecutor(ruleManager, ctx, tr, ruleManager.getMetaStore());
return executor;
}
return null;
}
Aggregations