/// <summary> /// Creates a new Join /// </summary> /// <param name="lhs">Left Hand Side</param> /// <param name="rhs">Right Hand Side</param> public ParallelJoin(ISparqlAlgebra lhs, ISparqlAlgebra rhs) { if (!lhs.Variables.IsDisjoint(rhs.Variables)) throw new RdfQueryException("Cannot create a ParallelJoin between two algebra operators which are not distinct"); this._lhs = lhs; this._rhs = rhs; this._d = new ParallelEvaluateDelegate(this.ParallelEvaluate); }
/// <summary> /// Creates a new Join. /// </summary> /// <param name="lhs">Left Hand Side.</param> /// <param name="rhs">Right Hand Side.</param> public ParallelJoin(ISparqlAlgebra lhs, ISparqlAlgebra rhs) { if (!lhs.Variables.IsDisjoint(rhs.Variables)) { throw new RdfQueryException("Cannot create a ParallelJoin between two algebra operators which are not distinct"); } _lhs = lhs; _rhs = rhs; _d = new ParallelEvaluateDelegate(ParallelEvaluate); }
/// <summary> /// Evaluates the Union /// </summary> /// <param name="context"></param> /// <returns></returns> public BaseMultiset Evaluate(SparqlEvaluationContext context) { //Create a copy of the evaluation context for the RHS SparqlEvaluationContext context2 = new SparqlEvaluationContext(context.Query, context.Data, context.Processor); if (!(context.InputMultiset is IdentityMultiset)) { context2.InputMultiset = new Multiset(); foreach (ISet s in context.InputMultiset.Sets) { context2.InputMultiset.Add(s.Copy()); } } List <Uri> activeGraphs = context.Data.ActiveGraphUris.ToList(); List <Uri> defaultGraphs = context.Data.DefaultGraphUris.ToList(); ParallelEvaluateDelegate d = new ParallelEvaluateDelegate(this.ParallelEvaluate); IAsyncResult lhs = d.BeginInvoke(this._lhs, context, activeGraphs, defaultGraphs, null, null); IAsyncResult rhs = d.BeginInvoke(this._rhs, context2, activeGraphs, defaultGraphs, null, null); WaitHandle.WaitAll(new WaitHandle[] { lhs.AsyncWaitHandle, rhs.AsyncWaitHandle }); bool rhsOk = false; try { BaseMultiset lhsResult = d.EndInvoke(lhs); rhsOk = true; BaseMultiset rhsResult = d.EndInvoke(rhs); context.CheckTimeout(); context.OutputMultiset = lhsResult.Union(rhsResult); context.CheckTimeout(); context.InputMultiset = context.OutputMultiset; return(context.OutputMultiset); } catch { if (!rhsOk) { //Clean up the RHS evaluation call if the LHS has errored try { d.EndInvoke(rhs); } catch { //Ignore this error as we're already going to throw the other error } } throw; } }
/// <summary> /// Evaluates the Union /// </summary> /// <param name="context"></param> /// <returns></returns> public BaseMultiset Evaluate(SparqlEvaluationContext context) { //Create a copy of the evaluation context for the RHS SparqlEvaluationContext context2 = new SparqlEvaluationContext(context.Query, context.Data, context.Processor); if (!(context.InputMultiset is IdentityMultiset)) { context2.InputMultiset = new Multiset(); foreach (ISet s in context.InputMultiset.Sets) { context2.InputMultiset.Add(s.Copy()); } } IGraph activeGraph = context.Data.ActiveGraph; IGraph defaultGraph = context.Data.DefaultGraph; ParallelEvaluateDelegate d = new ParallelEvaluateDelegate(this.ParallelEvaluate); IAsyncResult lhs = d.BeginInvoke(this._lhs, context, activeGraph, defaultGraph, null, null); IAsyncResult rhs = d.BeginInvoke(this._rhs, context2, activeGraph, defaultGraph, null, null); WaitHandle.WaitAll(new WaitHandle[] { lhs.AsyncWaitHandle, rhs.AsyncWaitHandle }); bool rhsOk = false; try { BaseMultiset lhsResult = d.EndInvoke(lhs); rhsOk = true; BaseMultiset rhsResult = d.EndInvoke(rhs); context.CheckTimeout(); context.OutputMultiset = lhsResult.Union(rhsResult); context.CheckTimeout(); context.InputMultiset = context.OutputMultiset; return context.OutputMultiset; } catch { if (!rhsOk) { //Clean up the RHS evaluation call if the LHS has errored try { d.EndInvoke(rhs); } catch { //Ignore this error as we're already going to throw the other error } } throw; } }