protected final void raiseException(RiotParseException ex) { throw new QueryException("Error passing SPARQL JSON results", ex); }
protected static String messageForQueryException(QueryException ex) { if ( ex.getMessage() != null ) return ex.getMessage() ; if ( ex.getCause() != null ) return Lib.classShortName(ex.getCause().getClass()) ; return null ; }
ServletOps.errorBadRequest("Error: \n" + queryString + "\n\r" + ex.getMessage()) ;
qEx.printStackTrace(System.err) ; fail("Parse failure: "+qEx.getMessage()) ; throw qEx ;
ServletOps.errorBadRequest("Error: \n" + queryString + "\n\r" + ex.getMessage()) ;
/** Location of the source for the data. If the model is not set, * then the QueryEngine will attempt to load the data from these URIs * as named graphs in the dataset. */ public void addNamedGraphURI(String uri) { if ( namedGraphURIs == null ) namedGraphURIs = new ArrayList<>() ; if ( namedGraphURIs.contains(uri) ) throw new QueryException("URI already in named graph set: "+uri) ; else namedGraphURIs.add(uri) ; }
@Override public QueryIterator execEvaluated(Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) { try { // Subject bound to something other a URI. if ( argSubject.getArg().isLiteral() || argSubject.getArg().isBlank() ) // Only split IRIs return IterLib.noResults(execCxt) ; if ( argSubject.getArg().isURI() ) // Case 1 : subject is a fixed URI or a variable bount to a URI. return subjectIsIRI(argSubject.getArg(), argObject, binding, execCxt) ; else // Case 2 : subject is an unbound variable. return subjectIsVariable(argSubject.getArg(), argObject, execCxt) ; } catch (QueryException ex) { Log.warn(this, "Unexpected problems in splitIRI: "+ex.getMessage()) ; return null ; } }
protected static String messageForQueryException(QueryException ex) { if ( ex.getMessage() != null ) return ex.getMessage() ; if ( ex.getCause() != null ) return Lib.classShortName(ex.getCause().getClass()) ; return null ; }
private boolean parseNextBinding() { String line; try { line = this.reader.readLine(); //Once EOF has been reached we'll see null for this call so we can return false because there are no further bindings if (line == null) return false; this.lineNum++; } catch (IOException e) { throw new QueryException("Error parsing CSV results - " + e.getMessage()); } if ( line.isEmpty() ) { // Empty input line - no bindings. // Only valid when we expect zero/one values as otherwise we should get a sequence of tab characters // which means a non-empty string which we handle normally if (expectedItems > 1) throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row had 0/1 values when %d were expected", this.lineNum, expectedItems)); binding = BindingFactory.create() ; if ( expectedItems == 1 ) binding.add(vars.get(0), NodeConst.emptyString) ; return true ; } binding = parseLine(vars, line) ; return true ; }
@Test @Category(TestSuites.Prepush.class) public void sparqlOrderByError_bug19157_rfe9971_yes_check() throws Exception { AGGraphMaker maker = closeLater(new AGGraphMaker(conn)); AGGraph graph = closeLater(maker.getGraph()); AGModel model = closeLater(new AGModel(graph)); Resource bob = model.createResource("http://example.org/people/bob"); Resource dave = model.createResource("http://example.org/people/dave"); Property fatherOf = model.createProperty("http://example.org/ontology/fatherOf"); Property age = model.createProperty("http://example.org/ontology/age"); Literal three = model.createTypedLiteral(3); model.add(bob, fatherOf, dave); model.add(dave, age, three); AGQuery query = AGQueryFactory.create("select ?s ?p ?o where { ?s ?p ?o . } order by ?z ?s"); { query.setCheckVariables(true); AGQueryExecution qe = closeLater(AGQueryExecutionFactory.create(query, model)); try { qe.execSelect(); Assert.fail("query should have failed because of ?z"); } catch (QueryException e) { if (!(e.getMessage().contains("Variables do not intersect with query: ?z") || e.getMessage().contains("unknown variable in order expression: ?z") || e.getMessage().contains("Unknown variable used in order expression: ?z"))) { throw e; } } } }
public void addDescribeNode(Node node) { if ( node.isVariable() ) { addResultVar(node) ; return ; } if ( node.isURI() || node.isBlank() ) { if ( !resultNodes.contains(node) ) resultNodes.add(node); return ; } if ( node.isLiteral() ) throw new QueryException("Result node is a literal: "+FmtUtils.stringForNode(node)) ; throw new QueryException("Result node not recognized: "+node) ; }
} catch (QueryException ex) System.out.println("Query exception: "+ex.getMessage()) ;
@Override public Iterator<Triple> execConstructTriples() { try (GraphQueryResult result = getConstructResult()) { List<Triple> tripleArrayList = new ArrayList<>(); while (result.hasNext()) { tripleArrayList.add(AGNodeFactory.asTriple(result.next())); } //Getting Iterator from List return tripleArrayList.iterator(); } catch (QueryEvaluationException e) { throw new QueryException(e); } }
throw new QueryException(String.format("Error Parsing CSV results at Line %d - Unterminated quoted string", this.lineNum)); if ( idx < line.length() ) throw new QueryException(String.format("Error Parsing CSV results at Line %d - Expected comma after quote", this.lineNum)) ; throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row '%s' has %d items when %d was expected", this.lineNum, line, terms.size(), vars.size())) ; for ( int i = 0 ; i < vars.size() ; i++ ) binding.add(vars.get(i), NodeFactory.createLiteral(terms.get(i))) ;
@Override public Iterator<Quad> execConstructQuads() { try (GraphQueryResult result = getConstructResult()) { List<Quad> quadArrayList = new ArrayList<>(); while (result.hasNext()) { quadArrayList.add(AGNodeFactory.asQuad(result.next())); } //Getting Iterator from List return quadArrayList.iterator(); } catch (QueryEvaluationException e) { throw new QueryException(e); } }
/** Add a collection of projection variables to a SELECT query */ public void addProjectVars(Collection<?> vars) { for ( Object obj : vars ) { if ( obj instanceof String ) { this.addResultVar( (String) obj ); continue; } if ( obj instanceof Var ) { this.addResultVar( (Var) obj ); continue; } throw new QueryException( "Not a variable or variable name: " + obj ); } resultVarsSet = true ; }
public void addOrderBy(Node var, int direction) { if ( ! var.isVariable() ) throw new QueryException("Not a variable: "+var) ; SortCondition sc = new SortCondition(var, direction) ; addOrderBy(sc) ; }
public void addResultVar(Node v) { if ( !v.isVariable() ) throw new QueryException("Not a variable: "+v) ; _addResultVar(v.getName()) ; }
public SparqlSelectFunction<T> addOrderBy(Node var, int direction) { if ( ! var.isVariable() ) throw new QueryException("Not a variable: "+var) ; SortCondition sc = new SortCondition(var, direction) ; addOrderBy(sc) ; return this; }
public void addResultVar(Node v, Expr expr) { Var var = null ; if ( v == null ) var = allocInternVar() ; else { if ( !v.isVariable() ) throw new QueryException("Not a variable: "+v) ; var = Var.alloc(v) ; } _addVarExpr(projectVars, var, expr) ; }