@@ -352,50 +352,58 @@ public TupleExpr optimize(TupleExpr expr, EvaluationStatistics evaluationStatist
352352 public CloseableIteration <BindingSet , QueryEvaluationException > evaluate (TupleExpr expr , BindingSet bindings )
353353 throws QueryEvaluationException {
354354
355- CloseableIteration <BindingSet , QueryEvaluationException > ret ;
355+ CloseableIteration <BindingSet , QueryEvaluationException > ret = null ;
356356
357- if (expr instanceof StatementPattern ) {
358- ret = evaluate ((StatementPattern ) expr , bindings );
359- } else if (expr instanceof UnaryTupleOperator ) {
360- ret = evaluate ((UnaryTupleOperator ) expr , bindings );
361- } else if (expr instanceof BinaryTupleOperator ) {
362- ret = evaluate ((BinaryTupleOperator ) expr , bindings );
363- } else if (expr instanceof SingletonSet ) {
364- ret = evaluate ((SingletonSet ) expr , bindings );
365- } else if (expr instanceof EmptySet ) {
366- ret = evaluate ((EmptySet ) expr , bindings );
367- } else if (expr instanceof ZeroLengthPath ) {
368- ret = evaluate ((ZeroLengthPath ) expr , bindings );
369- } else if (expr instanceof ArbitraryLengthPath ) {
370- ret = evaluate ((ArbitraryLengthPath ) expr , bindings );
371- } else if (expr instanceof BindingSetAssignment ) {
372- ret = evaluate ((BindingSetAssignment ) expr , bindings );
373- } else if (expr instanceof TripleRef ) {
374- ret = evaluate ((TripleRef ) expr , bindings );
375- } else if (expr instanceof TupleFunctionCall ) {
376- if (getQueryEvaluationMode ().compareTo (QueryEvaluationMode .STANDARD ) < 0 ) {
377- throw new QueryEvaluationException (
378- "Tuple function call not supported in query evaluation mode " + getQueryEvaluationMode ());
357+ try {
358+ if (expr instanceof StatementPattern ) {
359+ ret = evaluate ((StatementPattern ) expr , bindings );
360+ } else if (expr instanceof UnaryTupleOperator ) {
361+ ret = evaluate ((UnaryTupleOperator ) expr , bindings );
362+ } else if (expr instanceof BinaryTupleOperator ) {
363+ ret = evaluate ((BinaryTupleOperator ) expr , bindings );
364+ } else if (expr instanceof SingletonSet ) {
365+ ret = evaluate ((SingletonSet ) expr , bindings );
366+ } else if (expr instanceof EmptySet ) {
367+ ret = evaluate ((EmptySet ) expr , bindings );
368+ } else if (expr instanceof ZeroLengthPath ) {
369+ ret = evaluate ((ZeroLengthPath ) expr , bindings );
370+ } else if (expr instanceof ArbitraryLengthPath ) {
371+ ret = evaluate ((ArbitraryLengthPath ) expr , bindings );
372+ } else if (expr instanceof BindingSetAssignment ) {
373+ ret = evaluate ((BindingSetAssignment ) expr , bindings );
374+ } else if (expr instanceof TripleRef ) {
375+ ret = evaluate ((TripleRef ) expr , bindings );
376+ } else if (expr instanceof TupleFunctionCall ) {
377+ if (getQueryEvaluationMode ().compareTo (QueryEvaluationMode .STANDARD ) < 0 ) {
378+ throw new QueryEvaluationException (
379+ "Tuple function call not supported in query evaluation mode " + getQueryEvaluationMode ());
380+ }
381+ return evaluate (expr , bindings );
382+ } else if (expr == null ) {
383+ throw new IllegalArgumentException ("expr must not be null" );
384+ } else {
385+ throw new QueryEvaluationException ("Unsupported tuple expr type: " + expr .getClass ());
379386 }
380- return evaluate ((TupleFunctionCall ) expr , bindings );
381- } else if (expr == null ) {
382- throw new IllegalArgumentException ("expr must not be null" );
383- } else {
384- throw new QueryEvaluationException ("Unsupported tuple expr type: " + expr .getClass ());
385- }
386387
387- if (trackTime ) {
388- // set resultsSizeActual to at least be 0 so we can track iterations that don't procude anything
389- expr .setTotalTimeNanosActual (Math .max (0 , expr .getTotalTimeNanosActual ()));
390- ret = new TimedIterator (ret , expr );
391- }
388+ if (trackTime ) {
389+ // set resultsSizeActual to at least be 0 so we can track iterations that don't procude anything
390+ expr .setTotalTimeNanosActual (Math .max (0 , expr .getTotalTimeNanosActual ()));
391+ ret = new TimedIterator (ret , expr );
392+ }
392393
393- if (trackResultSize ) {
394- // set resultsSizeActual to at least be 0 so we can track iterations that don't procude anything
395- expr .setResultSizeActual (Math .max (0 , expr .getResultSizeActual ()));
396- ret = new ResultSizeCountingIterator (ret , expr );
394+ if (trackResultSize ) {
395+ // set resultsSizeActual to at least be 0 so we can track iterations that don't procude anything
396+ expr .setResultSizeActual (Math .max (0 , expr .getResultSizeActual ()));
397+ ret = new ResultSizeCountingIterator (ret , expr );
398+ }
399+ return ret ;
400+
401+ } catch (Throwable t ) {
402+ if (ret != null ) {
403+ ret .close ();
404+ }
405+ throw t ;
397406 }
398- return ret ;
399407 }
400408
401409 @ Override
@@ -708,9 +716,18 @@ protected QueryEvaluationStep prepare(DescribeOperator node, QueryEvaluationCont
708716
709717 @ Override
710718 public CloseableIteration <BindingSet , QueryEvaluationException > evaluate (BindingSet bs ) {
711- return new DescribeIteration (child .evaluate (bs ), DefaultEvaluationStrategy .this ,
712- node .getBindingNames (),
713- bs );
719+ CloseableIteration <BindingSet , QueryEvaluationException > evaluate = null ;
720+
721+ try {
722+ evaluate = child .evaluate (bs );
723+ return new DescribeIteration (evaluate , DefaultEvaluationStrategy .this , node .getBindingNames (), bs );
724+ } catch (Throwable t ) {
725+ if (evaluate != null ) {
726+ evaluate .close ();
727+ }
728+ throw t ;
729+ }
730+
714731 }
715732 };
716733 }
0 commit comments