예제 #1
0
        public bool RewriteQuery(
            T_Tile toFill,
            T_Tile toAvoid,
            IEnumerable <T_Tile> views,
            out T_Tile rewriting)
        {
            if (!this.RewriteQueryOnce(toFill, toAvoid, views, out rewriting))
            {
                return(false);
            }
            HashSet <T_Tile> tileSet = new HashSet <T_Tile>();

            this.GatherViews(rewriting, tileSet);
            int num1 = this.CountOperators(rewriting);
            int num2 = 0;
            int num3 = Math.Min(0, Math.Max(0, (int)((double)tileSet.Count * 0.0)));

            while (num2++ < num3)
            {
                IEnumerable <T_Tile> views1 = num2 != 1 ? (IEnumerable <T_Tile>) RewritingProcessor <T_Tile> .RandomPermutation <T_Tile>((IEnumerable <T_Tile>) tileSet) : RewritingProcessor <T_Tile> .Reverse <T_Tile>(views, tileSet);

                T_Tile rewriting1;
                this.RewriteQueryOnce(toFill, toAvoid, views1, out rewriting1);
                int num4 = this.CountOperators(rewriting1);
                if (num4 < num1)
                {
                    num1      = num4;
                    rewriting = rewriting1;
                }
                HashSet <T_Tile> views2 = new HashSet <T_Tile>();
                this.GatherViews(rewriting1, views2);
                tileSet = views2;
            }
            return(true);
        }
예제 #2
0
 public RewritingPass(T_Tile toFill, T_Tile toAvoid, List <T_Tile> views, RewritingProcessor <T_Tile> qp)
 {
     m_toFill  = toFill;
     m_toAvoid = toAvoid;
     m_views   = views;
     m_qp      = qp;
 }
 internal QueryRewriter(
     EdmType generatedType,
     ViewgenContext context,
     ViewGenMode typesGenerationMode)
 {
     this._typesGenerationMode = typesGenerationMode;
     this._context             = context;
     this._generatedType       = generatedType;
     this._domainMap           = context.MemberMaps.LeftDomainMap;
     this._config        = context.Config;
     this._identifiers   = context.CqlIdentifiers;
     this._qp            = new RewritingProcessor <Tile <FragmentQuery> >((TileProcessor <Tile <FragmentQuery> >) new DefaultTileProcessor <FragmentQuery>((TileQueryProcessor <FragmentQuery>)context.LeftFragmentQP));
     this._extentPath    = new MemberPath(context.Extent);
     this._keyAttributes = new List <MemberPath>(MemberPath.GetKeyMembers(context.Extent, this._domainMap));
     foreach (LeftCellWrapper leftCellWrapper in this._context.AllWrappersForExtent)
     {
         FragmentQuery        fragmentQuery = leftCellWrapper.FragmentQuery;
         Tile <FragmentQuery> tile          = (Tile <FragmentQuery>)QueryRewriter.CreateTile(fragmentQuery);
         this._fragmentQueries.Add(fragmentQuery);
         this._views.Add(tile);
     }
     this.AdjustMemberDomainsForUpdateViews();
     this._domainQuery = this.GetDomainQuery(this.FragmentQueries, generatedType);
     this._usedViews   = new HashSet <FragmentQuery>();
 }
예제 #4
0
        private static bool RewriteQueryInternal(
            T_Tile toFill, T_Tile toAvoid, out T_Tile rewriting, List <T_Tile> views,
            RewritingProcessor <T_Tile> qp)
        {
            var rewritingPass = new RewritingPass <T_Tile>(toFill, toAvoid, views, qp);

            return(rewritingPass.RewriteQuery(out rewriting));
        }
예제 #5
0
 // used for union simplification
 private RewritingSimplifier(T_Tile rewriting, T_Tile toFill, T_Tile toAvoid, RewritingProcessor <T_Tile> qp)
 {
     m_originalRewriting = toFill;
     m_toAvoid           = toAvoid;
     m_qp        = qp;
     m_usedViews = new Dictionary <T_Tile, TileOpKind>();
     GatherUnionedSubqueriesInUsedViews(rewriting);
 }
예제 #6
0
 // used for join/antisemijoin simplification
 private RewritingSimplifier(
     T_Tile originalRewriting, T_Tile toAvoid, Dictionary <T_Tile, TileOpKind> usedViews,
     RewritingProcessor <T_Tile> qp)
 {
     m_originalRewriting = originalRewriting;
     m_toAvoid           = toAvoid;
     m_qp        = qp;
     m_usedViews = usedViews;
 }
        private void PrintStatistics(RewritingProcessor <Tile <FragmentQuery> > qp)
        {
            int numSATChecks;
            int numIntersection;
            int numUnion;
            int numDifference;
            int numErrors;

            qp.GetStatistics(out numSATChecks, out numIntersection, out numUnion, out numDifference, out numErrors);
        }
예제 #8
0
        public static bool RewriteQuery(
            T_Tile toFill,
            T_Tile toAvoid,
            out T_Tile rewriting,
            List <T_Tile> views,
            RewritingProcessor <T_Tile> qp)
        {
            if (!new RewritingPass <T_Tile>(toFill, toAvoid, views, qp).RewriteQuery(out rewriting))
            {
                return(false);
            }
            RewritingSimplifier <T_Tile> .TrySimplifyUnionRewriting(ref rewriting, toFill, toAvoid, qp);

            return(true);
        }
        internal static bool TrySimplifyJoinRewriting(
            ref T_Tile rewriting,
            T_Tile toAvoid,
            Dictionary <T_Tile, TileOpKind> usedViews,
            RewritingProcessor <T_Tile> qp)
        {
            T_Tile simplifiedRewriting;

            if (!new RewritingSimplifier <T_Tile>(rewriting, toAvoid, usedViews, qp).SimplifyRewriting(out simplifiedRewriting))
            {
                return(false);
            }
            rewriting = simplifiedRewriting;
            return(true);
        }
        internal static bool TrySimplifyUnionRewriting(
            ref T_Tile rewriting,
            T_Tile toFill,
            T_Tile toAvoid,
            RewritingProcessor <T_Tile> qp)
        {
            T_Tile simplifiedRewriting;

            if (!new RewritingSimplifier <T_Tile>(rewriting, toFill, toAvoid, qp).SimplifyRewriting(out simplifiedRewriting))
            {
                return(false);
            }
            rewriting = simplifiedRewriting;
            return(true);
        }
예제 #11
0
        public static IEnumerable <IEnumerable <T> > Permute <T>(IEnumerable <T> list)
        {
            IEnumerable <T> rest          = (IEnumerable <T>)null;
            int             valuePosition = 0;

            foreach (T obj in list)
            {
                rest = RewritingProcessor <T_Tile> .AllButOne <T>(list, valuePosition ++);

                foreach (IEnumerable <T> rest1 in RewritingProcessor <T_Tile> .Permute <T>(rest))
                {
                    yield return(RewritingProcessor <T_Tile> .Concat <T>(obj, rest1));
                }
            }
            if (rest == null)
            {
                yield return(list);
            }
        }
예제 #12
0
        // called for top query only
        internal static bool TrySimplifyUnionRewriting(ref T_Tile rewriting, T_Tile toFill, T_Tile toAvoid, RewritingProcessor <T_Tile> qp)
        {
            var simplifier = new RewritingSimplifier <T_Tile>(rewriting, toFill, toAvoid, qp);
            // gather all unioned subqueries
            T_Tile simplifiedRewriting;

            if (simplifier.SimplifyRewriting(out simplifiedRewriting))
            {
                rewriting = simplifiedRewriting;
                return(true);
            }
            return(false);
        }