/// <summary> /// Applies the query to the given datasource /// </summary> internal RDFConstructQueryResult ApplyToDataSource(RDFDataSource datasource) { this.PatternGroupResultTables.Clear(); this.PatternResultTables.Clear(); RDFConstructQueryResult constructResult = new RDFConstructQueryResult(this.ToString()); if (this.PatternGroups.Any()) { //Iterate the pattern groups of the query var fedPatternResultTables = new Dictionary <RDFPatternGroup, List <DataTable> >(); foreach (var patternGroup in this.PatternGroups) { //Step 1: Get the intermediate result tables of the current pattern group if (datasource.IsFederation()) { #region TrueFederations foreach (var store in (RDFFederation)datasource) { //Step FED.1: Evaluate the patterns of the current pattern group on the current store RDFQueryEngine.EvaluatePatterns(this, patternGroup, store); //Step FED.2: Federate the patterns of the current pattern group on the current store if (!fedPatternResultTables.ContainsKey(patternGroup)) { fedPatternResultTables.Add(patternGroup, this.PatternResultTables[patternGroup]); } else { fedPatternResultTables[patternGroup].ForEach(fprt => fprt.Merge(this.PatternResultTables[patternGroup].Single(prt => prt.TableName.Equals(fprt.TableName, StringComparison.Ordinal)), true, MissingSchemaAction.Add)); } } this.PatternResultTables[patternGroup] = fedPatternResultTables[patternGroup]; #endregion } else { RDFQueryEngine.EvaluatePatterns(this, patternGroup, datasource); } //Step 2: Get the result table of the current pattern group RDFQueryEngine.CombinePatterns(this, patternGroup); //Step 3: Apply the filters of the current pattern group to its result table RDFQueryEngine.ApplyFilters(this, patternGroup); } //Step 4: Get the result table of the query DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList(), false); //Step 5: Fill the templates from the result table DataTable filledResultTable = RDFQueryEngine.FillTemplates(this, queryResultTable); //Step 6: Apply the modifiers of the query to the result table constructResult.ConstructResults = RDFQueryEngine.ApplyModifiers(this, filledResultTable); } return(constructResult); }