Ejemplo n.º 1
0
        /// <summary>
        /// Applies the query to the given store
        /// </summary>
        public RDFSelectQueryResult ApplyToStore(RDFStore store)
        {
            if (store != null)
            {
                this.PatternGroupResultTables.Clear();
                this.PatternResultTables.Clear();

                RDFSelectQueryResult selectResult = new RDFSelectQueryResult(this.ToString());
                if (!this.IsEmpty)
                {
                    //Iterate the pattern groups of the query
                    foreach (RDFPatternGroup patternGroup in this.PatternGroups)
                    {
                        //Step 1: Get the intermediate result tables of the current pattern group
                        RDFSelectQueryEngine.EvaluatePatterns(this, patternGroup, store);

                        //Step 2: Get the result table of the current pattern group
                        RDFSelectQueryEngine.CombinePatterns(this, patternGroup);

                        //Step 3: Apply the filters of the current pattern group to its result table
                        RDFSelectQueryEngine.ApplyFilters(this, patternGroup);
                    }

                    //Step 4: Get the result table of the query
                    DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList <DataTable>(), false);

                    //Step 5: Apply the modifiers of the query to the result table
                    selectResult.SelectResults = RDFSelectQueryEngine.ApplyModifiers(this, queryResultTable);
                }

                return(selectResult);
            }
            throw new RDFQueryException("Cannot execute SELECT query because given \"store\" parameter is null.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies the query to the given federation
        /// </summary>
        public RDFSelectQueryResult ApplyToFederation(RDFFederation federation)
        {
            if (federation != null)
            {
                this.PatternGroupResultTables.Clear();
                this.PatternResultTables.Clear();

                RDFSelectQueryResult selectResult = new RDFSelectQueryResult(this.ToString());
                if (!this.IsEmpty)
                {
                    //Iterate the pattern groups of the query
                    var fedPatternResultTables = new Dictionary <RDFPatternGroup, List <DataTable> >();
                    foreach (RDFPatternGroup patternGroup in this.PatternGroups)
                    {
                        #region TrueFederations
                        foreach (RDFStore store in federation.Stores.Values)
                        {
                            //Step 1: Evaluate the patterns of the current pattern group on the current store
                            RDFSelectQueryEngine.EvaluatePatterns(this, patternGroup, store);

                            //Step 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

                        //Step 3: Get the result table of the current pattern group
                        RDFSelectQueryEngine.CombinePatterns(this, patternGroup);

                        //Step 4: Apply the filters of the current pattern group to its result table
                        RDFSelectQueryEngine.ApplyFilters(this, patternGroup);
                    }

                    //Step 5: Get the result table of the query
                    DataTable queryResultTable = RDFQueryEngine.CombineTables(this.PatternGroupResultTables.Values.ToList <DataTable>(), false);

                    //Step 6: Apply the modifiers of the query to the result table
                    selectResult.SelectResults = RDFSelectQueryEngine.ApplyModifiers(this, queryResultTable);
                }

                return(selectResult);
            }
            throw new RDFQueryException("Cannot execute SELECT query because given \"federation\" parameter is null.");
        }