Search in sources :

Example 1 with WindowParser

use of org.apache.metron.profiler.client.window.generated.WindowParser in project metron by apache.

the class WindowProcessor method process.

/**
 * Create a reusable Window object (parameterized by time) from a statement specifying the window intervals
 * conforming to the Window grammar.
 *
 * @param statement
 * @return Window returns a Window object (parameterized by time) from a statement specifying the window
 * intervals conforming to the Window grammar.
 * @throws ParseException
 */
public static Window process(String statement) throws ParseException {
    TokenStream tokens = createTokenStream(statement);
    if (tokens == null) {
        return null;
    }
    WindowProcessor treeBuilder = new WindowProcessor();
    WindowParser parser = createParser(tokens, Optional.of(treeBuilder));
    parser.window();
    if (treeBuilder.throwable != null) {
        throw new ParseException(treeBuilder.throwable.getMessage(), treeBuilder.throwable);
    }
    return treeBuilder.getWindow();
}
Also used : WindowParser(org.apache.metron.profiler.client.window.generated.WindowParser) ParseException(org.apache.metron.stellar.dsl.ParseException)

Example 2 with WindowParser

use of org.apache.metron.profiler.client.window.generated.WindowParser in project metron by apache.

the class WindowProcessor method syntaxTree.

/**
 * Create a textual representation of the syntax tree.  This is useful for those intrepid souls
 * who wish to extend the window selector language.  God speed.
 * @param statement
 * @return  A string representation of the syntax tree.
 */
public static String syntaxTree(String statement) {
    TokenStream tokens = createTokenStream(statement);
    if (tokens == null) {
        return null;
    }
    WindowParser parser = createParser(tokens, Optional.empty());
    ParseTree tree = parser.window();
    return GrammarUtils.toSyntaxTree(tree);
}
Also used : WindowParser(org.apache.metron.profiler.client.window.generated.WindowParser) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 3 with WindowParser

use of org.apache.metron.profiler.client.window.generated.WindowParser in project metron by apache.

the class WindowProcessor method createParser.

private static WindowParser createParser(TokenStream tokens, Optional<WindowProcessor> windowProcessor) {
    WindowParser parser = new WindowParser(tokens);
    if (windowProcessor.isPresent()) {
        parser.addParseListener(windowProcessor.get());
    }
    parser.removeErrorListeners();
    parser.addErrorListener(new ErrorListener());
    return parser;
}
Also used : ErrorListener(org.apache.metron.stellar.dsl.ErrorListener) WindowParser(org.apache.metron.profiler.client.window.generated.WindowParser)

Aggregations

WindowParser (org.apache.metron.profiler.client.window.generated.WindowParser)3 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 ErrorListener (org.apache.metron.stellar.dsl.ErrorListener)1 ParseException (org.apache.metron.stellar.dsl.ParseException)1