Search in sources :

Example 6 with TranslateResult

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;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TranslateResult(org.smartdata.model.rule.TranslateResult) IOException(java.io.IOException) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 7 with TranslateResult

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;
}
Also used : SmartRuleStringParser(org.smartdata.rule.parser.SmartRuleStringParser) RuleState(org.smartdata.model.RuleState) ExecutionContext(org.smartdata.server.engine.data.ExecutionContext) TranslateResult(org.smartdata.model.rule.TranslateResult) TranslationContext(org.smartdata.rule.parser.TranslationContext) RuleExecutorPlugin(org.smartdata.model.rule.RuleExecutorPlugin)

Aggregations

TranslateResult (org.smartdata.model.rule.TranslateResult)7 IOException (java.io.IOException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)2 ParseTree (org.antlr.v4.runtime.tree.ParseTree)2 DetailedRuleInfo (org.smartdata.model.DetailedRuleInfo)2 RuleInfo (org.smartdata.model.RuleInfo)2 SmartRuleStringParser (org.smartdata.rule.parser.SmartRuleStringParser)2 TranslationContext (org.smartdata.rule.parser.TranslationContext)2 RuleInfoRepo (org.smartdata.server.engine.rule.RuleInfoRepo)2 SmartConf (org.smartdata.conf.SmartConf)1 MetaStoreException (org.smartdata.metastore.MetaStoreException)1 CmdletDescriptor (org.smartdata.model.CmdletDescriptor)1 RuleState (org.smartdata.model.RuleState)1 RuleExecutorPlugin (org.smartdata.model.rule.RuleExecutorPlugin)1 TimeBasedScheduleInfo (org.smartdata.model.rule.TimeBasedScheduleInfo)1 SmartRuleLexer (org.smartdata.rule.parser.SmartRuleLexer)1 SmartRuleParser (org.smartdata.rule.parser.SmartRuleParser)1