Search in sources :

Example 1 with GemFireAST

use of org.apache.geode.cache.query.internal.parse.GemFireAST in project geode by apache.

the class QCompiler method compileQuery.

/*
   * compile the string into a Query (returns the root CompiledValue)
   */
public CompiledValue compileQuery(String oqlSource) {
    try {
        OQLLexer lexer = new OQLLexer(new StringReader(oqlSource));
        OQLParser parser = new OQLParser(lexer);
        // by default use Unsupported AST class, overridden for supported
        // operators in the grammer proper
        parser.setASTNodeClass("org.apache.geode.cache.query.internal.parse.ASTUnsupported");
        parser.queryProgram();
        GemFireAST n = (GemFireAST) parser.getAST();
        n.compile(this);
    } catch (Exception ex) {
        // GemFire Exception.
        throw new QueryInvalidException(LocalizedStrings.QCompiler_SYNTAX_ERROR_IN_QUERY_0.toLocalizedString(ex.getMessage()), ex);
    }
    Assert.assertTrue(stackSize() == 1, "stack size = " + stackSize());
    return (CompiledValue) pop();
}
Also used : OQLLexer(org.apache.geode.cache.query.internal.parse.OQLLexer) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) StringReader(java.io.StringReader) GemFireAST(org.apache.geode.cache.query.internal.parse.GemFireAST) OQLParser(org.apache.geode.cache.query.internal.parse.OQLParser) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException)

Example 2 with GemFireAST

use of org.apache.geode.cache.query.internal.parse.GemFireAST in project geode by apache.

the class QCompiler method compileImports.

/**
   * Processes import statements only. This compiler instance remembers the imports and can be used
   * to compile other strings with this context info
   */
public void compileImports(String imports) {
    try {
        OQLLexer lexer = new OQLLexer(new StringReader(imports));
        OQLParser parser = new OQLParser(lexer);
        // by default use Unsupported AST class, overridden for supported
        // operators in the grammer proper
        parser.setASTNodeClass("org.apache.geode.cache.query.internal.parse.ASTUnsupported");
        parser.loneImports();
        GemFireAST n = (GemFireAST) parser.getAST();
        n.compile(this);
    } catch (Exception ex) {
        // GemFire Exception.
        throw new QueryInvalidException(LocalizedStrings.QCompiler_SYNTAX_ERROR_IN_QUERY_0.toLocalizedString(ex.getMessage()), ex);
    }
    Assert.assertTrue(stackSize() == 0, "stack size = " + stackSize() + ";stack=" + this.stack);
}
Also used : OQLLexer(org.apache.geode.cache.query.internal.parse.OQLLexer) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) StringReader(java.io.StringReader) GemFireAST(org.apache.geode.cache.query.internal.parse.GemFireAST) OQLParser(org.apache.geode.cache.query.internal.parse.OQLParser) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException)

Example 3 with GemFireAST

use of org.apache.geode.cache.query.internal.parse.GemFireAST in project geode by apache.

the class QCompiler method compileProjectionAttributes.

/** Returns List<CompiledIteratorDef> or null if projectionAttrs is '*' */
public List compileProjectionAttributes(String projectionAttributes) {
    try {
        OQLLexer lexer = new OQLLexer(new StringReader(projectionAttributes));
        OQLParser parser = new OQLParser(lexer);
        // by default use Unsupported AST class, overridden for supported
        // operators in the grammer proper
        parser.setASTNodeClass("org.apache.geode.cache.query.internal.parse.ASTUnsupported");
        parser.loneProjectionAttributes();
        GemFireAST n = (GemFireAST) parser.getAST();
        // don't compile TOK_STAR
        if (n.getType() == TOK_STAR) {
            return null;
        }
        n.compile(this);
    } catch (Exception ex) {
        // GemFire Exception.
        throw new QueryInvalidException(LocalizedStrings.QCompiler_SYNTAX_ERROR_IN_QUERY_0.toLocalizedString(ex.getMessage()), ex);
    }
    Assert.assertTrue(stackSize() == 1, "stack size = " + stackSize() + ";stack=" + this.stack);
    return (List) pop();
}
Also used : OQLLexer(org.apache.geode.cache.query.internal.parse.OQLLexer) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) StringReader(java.io.StringReader) GemFireAST(org.apache.geode.cache.query.internal.parse.GemFireAST) ArrayList(java.util.ArrayList) List(java.util.List) OQLParser(org.apache.geode.cache.query.internal.parse.OQLParser) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException)

Example 4 with GemFireAST

use of org.apache.geode.cache.query.internal.parse.GemFireAST in project geode by apache.

the class QCompiler method compileFromClause.

/** Returns List<CompiledIteratorDef> */
public List compileFromClause(String fromClause) {
    try {
        OQLLexer lexer = new OQLLexer(new StringReader(fromClause));
        OQLParser parser = new OQLParser(lexer);
        // by default use Unsupported AST class, overridden for supported
        // operators in the grammer proper
        parser.setASTNodeClass("org.apache.geode.cache.query.internal.parse.ASTUnsupported");
        parser.loneFromClause();
        GemFireAST n = (GemFireAST) parser.getAST();
        n.compile(this);
    } catch (Exception ex) {
        // GemFire Exception.
        throw new QueryInvalidException(LocalizedStrings.QCompiler_SYNTAX_ERROR_IN_QUERY_0.toLocalizedString(ex.getMessage()), ex);
    }
    Assert.assertTrue(stackSize() == 1, "stack size = " + stackSize());
    return (List) pop();
}
Also used : OQLLexer(org.apache.geode.cache.query.internal.parse.OQLLexer) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) StringReader(java.io.StringReader) GemFireAST(org.apache.geode.cache.query.internal.parse.GemFireAST) ArrayList(java.util.ArrayList) List(java.util.List) OQLParser(org.apache.geode.cache.query.internal.parse.OQLParser) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException)

Aggregations

StringReader (java.io.StringReader)4 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)4 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)4 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)4 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)4 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)4 GemFireAST (org.apache.geode.cache.query.internal.parse.GemFireAST)4 OQLLexer (org.apache.geode.cache.query.internal.parse.OQLLexer)4 OQLParser (org.apache.geode.cache.query.internal.parse.OQLParser)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2