示例#1
0
        /// <summary>
        /// procedure are in 2 stages, stage 1 apply raw Where Clause to get data interested
        /// stage 2, apply evaluation strategy to get the overall result
        ///
        /// PS:for simple 1 table select, do the original sql query over all possible worlds of
        /// this table in PD, and return results in the descending order of probability
        /// </summary>
        /// <param name="isIntermediateResult"> </param>
        public DataTable HandleSelectSqlQuery(bool isIntermediateResult)
        {
            if (_query.HasSubquery)
            {
                var table1        = _query.TableName;
                int attributeSize = PreparePossibleStatesTable(table1);
                CreatePossibleWorldsTable(table1, attributeSize);
                PreparePossibleWorldsTable(table1);
                PreparePossibleWorldsAggregatedTable(table1);

                var subQueryHandler = new SelectQueryHandler(_query.SubQuery, underlineDatabase);
                var table2          = subQueryHandler.HandleSelectSqlQuery(true);

                var attributeSelected = AttbutesWithoutRenaming(_query.Attributes);
                JoinPossibleWorlds(table1 + "_PossibleWorlds", "subquery_PossibleWorlds", "answer_PossibleWorlds",
                                   _query.JoinOnAttributes, attributeSelected);
                JoinPossibleWorldsAggregatedTable(table1 + "_PossibleWorldsAggregated", "subquery_PossibleWorldsAggregated", "answer_PossibleWorldsAggregated");

                DataTable result = NaiveStrategy(_query.Attributes, _query.ConditionClause, "answer", isIntermediateResult);
                return(result);
            }
            else
            {
                // no more subquery/join, now just consider a single table
                var       answerTableName = "needToGetRidOfThisVariable";
                DataTable result          = ComputeJointResultUsingNaiveStrategy(_query.Attributes, _query, isIntermediateResult);
                return(result);
            }
        }
        public string submitQuerySQL(string sql, out DataTable answerSet)
        {
            SqlQuery rawQuery = new SqlQuery(sql);
            QueryType qType = rawQuery.ProcessType();
            answerSet = null;
            switch (qType)
            {
                case QueryType.INSERT:
                    var query = new SqlInsertQuery(sql);
                    query.ProcessAndPopulateEachField();
                    var iHandler = new InsertQueryHandler(query, underlineDatabase);
                    answerSet = iHandler.HandleInsertQuery();
                    break;
                case QueryType.SELECT:
                    var squery = new SqlSelectQuery(sql);
                    var sHandler = new SelectQueryHandler(squery, underlineDatabase);
                    answerSet = sHandler.HandleSelectSqlQuery();
                    break;
                case QueryType.CREATE:
                    var cquery = new SqlCreateTableQuery(sql);
                    var handler = new CreateTableHandler(cquery,underlineDatabase);
                    answerSet = handler.HandleCreateTableQuery();
                    break;
                default:
                    break;
            }

            return "end of submitSQL function";
        }
 private void PreparePossibleTables(string tName)
 {
     SelectQueryHandler queryHandler = new SelectQueryHandler(null, _underlineDatabase);
     var tables = new List<string>();
     tables.Add(tName);
     queryHandler.PrepareReleventTables(tables);
 }
        /// <summary>
        /// procedure are in 2 stages, stage 1 apply raw Where Clause to get data interested
        /// stage 2, apply evaluation strategy to get the overall result
        /// 
        /// PS:for simple 1 table select, do the original sql query over all possible worlds of
        /// this table in PD, and return results in the descending order of probability
        /// </summary>
        /// <param name="isIntermediateResult"> </param>
        public DataTable HandleSelectSqlQuery(bool isIntermediateResult)
        {
            if (_query.HasSubquery)
            {
                var table1 = _query.TableName;
                int attributeSize = PreparePossibleStatesTable(table1);
                CreatePossibleWorldsTable(table1, attributeSize);
                PreparePossibleWorldsTable(table1);
                PreparePossibleWorldsAggregatedTable(table1);

                var subQueryHandler = new SelectQueryHandler(_query.SubQuery, underlineDatabase);
                var table2 = subQueryHandler.HandleSelectSqlQuery(true);

                var attributeSelected = AttbutesWithoutRenaming(_query.Attributes);
                JoinPossibleWorlds(table1 + "_PossibleWorlds", "subquery_PossibleWorlds", "answer_PossibleWorlds",
                    _query.JoinOnAttributes, attributeSelected);
                JoinPossibleWorldsAggregatedTable(table1+"_PossibleWorldsAggregated", "subquery_PossibleWorldsAggregated", "answer_PossibleWorldsAggregated");

                DataTable result = NaiveStrategy(_query.Attributes, _query.ConditionClause, "answer",isIntermediateResult);
                return result;
            }
            else
            {
                // no more subquery/join, now just consider a single table
                var answerTableName = "needToGetRidOfThisVariable";
                DataTable result = ComputeJointResultUsingNaiveStrategy(_query.Attributes, _query,isIntermediateResult);
                return result;
            }
        }