Search in sources :

Example 6 with QueryParseException

use of org.apache.jena.query.QueryParseException in project jena by apache.

the class uparse method execOne.

private void execOne(String updateString, Syntax syntax) {
    UpdateRequest req;
    try {
        req = UpdateFactory.create(updateString, syntax);
    } catch (QueryParseException ex) {
        System.err.print("Parse error: ");
        System.err.println(ex.getMessage());
        return;
    }
    //req.output(IndentedWriter.stderr) ;
    if (printUpdate)
        System.out.print(req);
    if (printNone)
        return;
    // And some checking.
    IndentedLineBuffer w = new IndentedLineBuffer();
    UpdateWriter.output(req, w);
    String updateString2 = w.asString();
    UpdateRequest req2 = null;
    try {
        req2 = UpdateFactory.create(updateString2, syntax);
    } catch (QueryParseException ex) {
        System.err.println("Can not reparse update after serialization");
        System.err.println(updateString2);
    }
    if (!req.equalTo(req2))
        System.err.println("Reparsed update does not .equalTo original parsed request");
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) QueryParseException(org.apache.jena.query.QueryParseException) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 7 with QueryParseException

use of org.apache.jena.query.QueryParseException in project jena by apache.

the class ParserARQUpdate method _parse.

private void _parse(UpdateSink sink, Reader r) {
    ARQParser parser = null;
    try {
        parser = new ARQParser(r);
        parser.setUpdateSink(sink);
        parser.UpdateUnit();
    } catch (org.apache.jena.sparql.lang.arq.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.arq.TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this should not happen
        int col = parser.token.endColumn;
        int line = parser.token.endLine;
        throw new QueryParseException(tErr.getMessage(), line, col);
    } catch (QueryException ex) {
        throw ex;
    } catch (JenaException ex) {
        throw new QueryException(ex.getMessage(), ex);
    } catch (Error err) {
        // The token stream can throw errors.
        throw new QueryParseException(err.getMessage(), err, -1, -1);
    } catch (Throwable th) {
        Log.error(this, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) ARQParser(org.apache.jena.sparql.lang.arq.ARQParser) QueryParseException(org.apache.jena.query.QueryParseException)

Example 8 with QueryParseException

use of org.apache.jena.query.QueryParseException in project jena by apache.

the class ParserSPARQL11 method perform.

// All throwable handling.
private static void perform(Query query, String string, Action action) {
    Reader in = new StringReader(string);
    SPARQLParser11 parser = new SPARQLParser11(in);
    try {
        query.setStrict(true);
        parser.setQuery(query);
        action.exec(parser);
    } catch (org.apache.jena.sparql.lang.sparql_11.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.sparql_11.TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this should not happen
        int col = parser.token.endColumn;
        int line = parser.token.endLine;
        throw new QueryParseException(tErr.getMessage(), line, col);
    } catch (QueryException ex) {
        throw ex;
    } catch (JenaException ex) {
        throw new QueryException(ex.getMessage(), ex);
    } catch (Error err) {
        System.err.println(err.getMessage());
        // The token stream can throw errors.
        throw new QueryParseException(err.getMessage(), err, -1, -1);
    } catch (Throwable th) {
        Log.warn(ParserSPARQL11.class, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) StringReader(java.io.StringReader) Reader(java.io.Reader) QueryParseException(org.apache.jena.query.QueryParseException) JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) StringReader(java.io.StringReader)

Example 9 with QueryParseException

use of org.apache.jena.query.QueryParseException in project jena by apache.

the class SyntaxVarScope method check.

// Other check (not scoping at this level) of a query
private static void check(Query query, Collection<Var> vars) {
    // Check any expressions are assigned to fresh variables.
    checkExprListAssignment(vars, query.getProject());
    // Legal in ARQ, not in SPARQL 1.1
    if (!Syntax.syntaxARQ.equals(query.getSyntax())) {
        if (query.isQueryResultStar() && query.hasGroupBy())
            throw new QueryParseException("SELECT * not legal with GROUP BY", -1, -1);
    }
    // Check any variable in an expression is in scope (if GROUP BY) 
    checkExprVarUse(query);
    // ENABLE
    if (false && query.hasGroupBy()) {
        VarExprList exprList2 = query.getGroupBy();
        checkExprListAssignment(vars, exprList2);
    // CHECK 
    }
}
Also used : VarExprList(org.apache.jena.sparql.core.VarExprList) QueryParseException(org.apache.jena.query.QueryParseException)

Example 10 with QueryParseException

use of org.apache.jena.query.QueryParseException in project jena by apache.

the class SyntaxVarScope method checkExprVarUse.

private static void checkExprVarUse(Query query) {
    if (query.hasGroupBy()) {
        VarExprList groupKey = query.getGroupBy();
        // Copy - we need to add variables
        // SELECT (count(*) AS ?C)  (?C+1 as ?D) 
        List<Var> inScopeVars = new ArrayList<>(groupKey.getVars());
        VarExprList exprList = query.getProject();
        for (Var v : exprList.getVars()) {
            // In scope?
            Expr e = exprList.getExpr(v);
            if (e == null) {
                if (!inScopeVars.contains(v)) {
                    throw new QueryParseException("Non-group key variable in SELECT: " + v, -1, -1);
                }
            } else {
                Set<Var> eVars = e.getVarsMentioned();
                for (Var v2 : eVars) {
                    if (!inScopeVars.contains(v2)) {
                        throw new QueryParseException("Non-group key variable in SELECT: " + v2 + " in expression " + e, -1, -1);
                    }
                }
            }
            inScopeVars.add(v);
        }
    }
}
Also used : Expr(org.apache.jena.sparql.expr.Expr) Var(org.apache.jena.sparql.core.Var) VarExprList(org.apache.jena.sparql.core.VarExprList) QueryParseException(org.apache.jena.query.QueryParseException)

Aggregations

QueryParseException (org.apache.jena.query.QueryParseException)16 StringReader (java.io.StringReader)6 QueryException (org.apache.jena.query.QueryException)6 JenaException (org.apache.jena.shared.JenaException)6 Reader (java.io.Reader)5 ARQParser (org.apache.jena.sparql.lang.arq.ARQParser)4 Query (org.apache.jena.query.Query)3 VarExprList (org.apache.jena.sparql.core.VarExprList)3 UpdateRequest (org.apache.jena.update.UpdateRequest)3 JsonBuilder (org.apache.jena.atlas.json.JsonBuilder)2 Syntax (org.apache.jena.query.Syntax)2 Prologue (org.apache.jena.sparql.core.Prologue)2 Expr (org.apache.jena.sparql.expr.Expr)2 SPARQLParser11 (org.apache.jena.sparql.lang.sparql_11.SPARQLParser11)2 UpdateException (org.apache.jena.update.UpdateException)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 ArgDecl (jena.cmd.ArgDecl)1 CmdException (jena.cmd.CmdException)1 CmdLineArgs (jena.cmd.CmdLineArgs)1