File: PhysicalOps.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (341 lines) | stat: -rw-r--r-- 11,496 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
//---------------------------------------------------------------------
// <copyright file="PhysicalOps.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner  Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Globalization;
using System.Data.Query.PlanCompiler;
using md = System.Data.Metadata.Edm;

namespace System.Data.Query.InternalTrees
{
    /// <summary>
    /// A PhysicalProjectOp is a physical Op capping the entire command tree (and the 
    /// subtrees of CollectOps). 
    /// </summary>
    internal class PhysicalProjectOp : PhysicalOp
    {
        #region public methods
        /// <summary>
        /// Instance for pattern matching in rules
        /// </summary>
        internal static readonly PhysicalProjectOp Pattern = new PhysicalProjectOp();
 
        /// <summary>
        /// Get the column map that describes how the result should be reshaped
        /// </summary>
        internal SimpleCollectionColumnMap ColumnMap 
        { 
            get { return m_columnMap; } 
        }

        /// <summary>
        /// Get the (ordered) list of output vars that this node produces
        /// </summary>
        internal VarList Outputs 
        { 
            get { return m_outputVars; } 
        }

        /// <summary>
        /// Visitor pattern method
        /// </summary>
        /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
        /// <param name="n">The Node that references this Op</param>
        [DebuggerNonUserCode]
        internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }

        /// <summary>
        /// Visitor pattern method for visitors with a return value
        /// </summary>
        /// <param name="v">The visitor</param>
        /// <param name="n">The node in question</param>
        /// <returns>An instance of TResultType</returns>
        [DebuggerNonUserCode]
        internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }

        #endregion

        #region private constructors
        /// <summary>
        /// basic constructor
        /// </summary>
        /// <param name="outputVars">List of outputs from this Op</param>
        /// <param name="columnMap">column map that describes the result to be shaped</param>
        internal PhysicalProjectOp(VarList outputVars, SimpleCollectionColumnMap columnMap)
            : this()
        {
            Debug.Assert(null != columnMap, "null columnMap?");
            m_outputVars = outputVars;
            m_columnMap = columnMap;
        }

        private PhysicalProjectOp()
            : base(OpType.PhysicalProject)
        {
        }
        #endregion

        #region private state
        private SimpleCollectionColumnMap m_columnMap;
        private VarList m_outputVars;
        #endregion
    }

    /// <summary>
    /// Represents information about one collection being managed by the NestOps. 
    /// The CollectionVar is a Var that represents the entire collection. 
    /// </summary>
    internal class CollectionInfo
    {
        #region public methods
        /// <summary>
        /// The collection-var
        /// </summary>
        internal Var CollectionVar
        {
            get { return m_collectionVar; }
        }
        /// <summary>
        /// the column map for the collection element
        /// </summary>
        internal ColumnMap ColumnMap
        {
            get { return m_columnMap; }
        }

        /// <summary>
        /// list of vars describing the collection element; flattened to remove 
        /// nested collections
        /// </summary>
        internal VarList FlattenedElementVars
        {
            get { return m_flattenedElementVars; }
        }

        /// <summary>
        /// list of keys specific to this collection
        /// </summary>
        internal VarVec Keys
        {
            get { return m_keys; }
        }

        /// <summary>
        /// list of sort keys specific to this collection
        /// </summary>
        internal List<InternalTrees.SortKey> SortKeys
        {
            get { return m_sortKeys; }
        }

        /// <summary>
        /// Discriminator Value for this collection (for a given NestOp).
        /// Should we break this out into a subtype of CollectionInfo
        /// </summary>
        internal object DiscriminatorValue
        {
            get { return m_discriminatorValue; }
        }

        #endregion

        #region constructors
        internal CollectionInfo(Var collectionVar, ColumnMap columnMap, VarList flattenedElementVars, VarVec keys, List<InternalTrees.SortKey> sortKeys, object discriminatorValue)
        {
            m_collectionVar = collectionVar;
            m_columnMap = columnMap;
            m_flattenedElementVars = flattenedElementVars;
            m_keys = keys;
            m_sortKeys = sortKeys;
            m_discriminatorValue = discriminatorValue;
        }
        #endregion

        #region private state
        private Var m_collectionVar;    // the collection Var
        private ColumnMap m_columnMap;  // column map for the collection element
        private VarList m_flattenedElementVars; // elementVars, removing collections;
        private VarVec m_keys;              //list of keys specific to this collection
        private List<InternalTrees.SortKey> m_sortKeys;          //list of sort keys specific to this collection
        private object m_discriminatorValue;
        #endregion
    }

    /// <summary>
    /// Base class for Nest operations
    /// </summary>
    internal abstract class NestBaseOp : PhysicalOp
    {
        #region publics

        /// <summary>
        /// (Ordered) list of prefix sort keys (defines ordering of results)
        /// </summary>
        internal List<SortKey> PrefixSortKeys
        {
            get { return m_prefixSortKeys; }
        }

        /// <summary>
        /// Outputs of the NestOp. Includes the Keys obviously, and one Var for each of
        /// the collections produced. In addition, this may also include non-key vars
        /// from the outer row
        /// </summary>
        internal VarVec Outputs 
        { 
            get { return m_outputs; } 
        }
        
        /// <summary>
        /// Information about each collection managed by the NestOp
        /// </summary>
        internal List<CollectionInfo> CollectionInfo
        {
            get { return m_collectionInfoList; }
        }
        #endregion

        #region constructors
        internal NestBaseOp(OpType opType, List<SortKey> prefixSortKeys, 
            VarVec outputVars, 
            List<CollectionInfo> collectionInfoList)
            : base(opType)
        {
            m_outputs = outputVars;
            m_collectionInfoList = collectionInfoList;
            m_prefixSortKeys = prefixSortKeys;
        }
        #endregion

        #region private state
        private List<SortKey> m_prefixSortKeys; // list of sort key prefixes
        private VarVec m_outputs; // list of all output vars
        private List<CollectionInfo> m_collectionInfoList;
        #endregion
    }

    /// <summary>
    /// Single-stream nest aggregation Op. 
    /// (Somewhat similar to a group-by op - should we merge these?)
    /// </summary>
    internal class SingleStreamNestOp : NestBaseOp
    {
        #region publics
        /// <summary>
        /// 1 child - the input
        /// </summary>
        internal override int Arity { get { return 1; } }

        /// <summary>
        /// The discriminator Var (when there are multiple collections)
        /// </summary>
        internal Var Discriminator 
        { 
            get { return m_discriminator; } 
        }
        /// <summary>
        /// List of postfix sort keys (mostly to deal with multi-level nested collections)
        /// </summary>
        internal List<SortKey> PostfixSortKeys
        {
            get { return m_postfixSortKeys; }
        }
        /// <summary>
        /// Set of keys for this nest operation
        /// </summary>
        internal VarVec Keys
        {
            get { return m_keys; }
        }

        /// <summary>
        /// Visitor pattern method
        /// </summary>
        /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
        /// <param name="n">The Node that references this Op</param>
        [DebuggerNonUserCode]
        internal override void Accept(BasicOpVisitor v, Node n) 
        { 
            v.Visit(this, n); 
        }

        /// <summary>
        /// Visitor pattern method for visitors with a return value
        /// </summary>
        /// <param name="v">The visitor</param>
        /// <param name="n">The node in question</param>
        /// <returns>An instance of TResultType</returns>
        [DebuggerNonUserCode]
        internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) 
        { 
            return v.Visit(this, n); 
        }

        #endregion

        #region constructors
        internal SingleStreamNestOp(VarVec keys,
            List<SortKey> prefixSortKeys, List<SortKey> postfixSortKeys, 
            VarVec outputVars, List<CollectionInfo> collectionInfoList, 
            Var discriminatorVar)
            : base(OpType.SingleStreamNest, prefixSortKeys, outputVars, collectionInfoList)
        {
            m_keys = keys;
            m_postfixSortKeys = postfixSortKeys;
            m_discriminator = discriminatorVar;
        }
        #endregion

        #region private state
        private VarVec m_keys; // keys for this operation
        private Var m_discriminator; // Var describing the discriminator
        List<SortKey> m_postfixSortKeys; // list of postfix sort keys 
        #endregion
    }

    /// <summary>
    /// Represents a multi-stream nest operation. The first input represents the 
    /// container row, while all the other inputs represent collections
    /// </summary>
    internal class MultiStreamNestOp : NestBaseOp
    {
        #region publics
        /// <summary>
        /// Visitor pattern method
        /// </summary>
        /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
        /// <param name="n">The Node that references this Op</param>
        [DebuggerNonUserCode]
        internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }

        /// <summary>
        /// Visitor pattern method for visitors with a return value
        /// </summary>
        /// <param name="v">The visitor</param>
        /// <param name="n">The node in question</param>
        /// <returns>An instance of TResultType</returns>
        [DebuggerNonUserCode]
        internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
        #endregion

        #region constructors
        internal MultiStreamNestOp(List<SortKey> prefixSortKeys, VarVec outputVars, 
            List<CollectionInfo> collectionInfoList)
            : base(OpType.MultiStreamNest, prefixSortKeys, outputVars, collectionInfoList)
        {
        }
        #endregion

        #region private state
        #endregion
    }
}