Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Ops.cs « InternalTrees « Query « Data « System « System.Data.Entity « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ffa517fde81d43c1bbcdf1a69705a38e751d9ced (plain)
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
//---------------------------------------------------------------------
// <copyright file="Ops.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner  Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------

namespace System.Data.Query.InternalTrees
{
    using System.Data.Metadata.Edm;
    using System.Diagnostics;

    /// <summary>
    /// The operator types. Includes both scalar and relational operators, 
    /// and physical and logical operators, and rule operators 
    /// </summary>
    internal enum OpType
    {
        #region ScalarOpType
        /// <summary>
        /// Constants
        /// </summary>
        Constant,

        /// <summary>
        /// An internally generated constant
        /// </summary>
        InternalConstant,

        /// <summary>
        /// An internally generated constant used as a null sentinel
        /// </summary>
        NullSentinel,

        /// <summary>
        /// A null constant
        /// </summary>
        Null,

        /// <summary>
        /// ConstantPredicate
        /// </summary>
        ConstantPredicate,
        
        /// <summary>
        /// A Var reference
        /// </summary>
        VarRef,

        /// <summary>
        /// GreaterThan
        /// </summary>
        GT,
        
        /// <summary>
        /// >=
        /// </summary>
        GE,
        
        /// <summary>
        /// Lessthan or equals
        /// </summary>
        LE,

        /// <summary>
        /// Less than
        /// </summary>
        LT,

        /// <summary>
        /// Equals 
        /// </summary>
        EQ,

        /// <summary>
        /// Not equals
        /// </summary>
        NE,

        /// <summary>
        /// String comparison
        /// </summary>
        Like,

        /// <summary>
        /// Addition
        /// </summary>
        Plus,

        /// <summary>
        /// Subtraction
        /// </summary>
        Minus,

        /// <summary>
        /// Multiplication 
        /// </summary>
        Multiply,

        /// <summary>
        /// Division 
        /// </summary>
        Divide,

        /// <summary>
        /// Modulus 
        /// </summary>
        Modulo,

        /// <summary>
        /// Unary Minus 
        /// </summary>
        UnaryMinus,

        /// <summary>
        /// And 
        /// </summary>
        And,

        /// <summary>
        /// Or
        /// </summary>
        Or,

        /// <summary>
        /// Not
        /// </summary>
        Not,
        
        /// <summary>
        /// is null 
        /// </summary>
        IsNull,

        /// <summary>
        /// switched case expression
        /// </summary>
        Case,

        /// <summary>
        /// treat-as 
        /// </summary>
        Treat,

        /// <summary>
        /// is-of 
        /// </summary>
        IsOf,

        /// <summary>
        /// Cast
        /// </summary>
        Cast,

        /// <summary>
        /// Internal cast
        /// </summary>
        SoftCast,

        /// <summary>
        /// a basic aggregate
        /// </summary>
        Aggregate,
        
        /// <summary>
        /// function call
        /// </summary>
        Function,

        /// <summary>
        /// Reference to a "relationship" property
        /// </summary>
        RelProperty,

        /// <summary>
        /// property reference
        /// </summary>
        Property,

        /// <summary>
        /// entity constructor
        /// </summary>
        NewEntity,

        /// <summary>
        /// new instance constructor for a named type(other than multiset, record)
        /// </summary>
        NewInstance,

        /// <summary>
        /// new instance constructor for a named type and sub-types
        /// </summary>
        DiscriminatedNewEntity,

        /// <summary>
        /// Multiset constructor
        /// </summary>
        NewMultiset,
        
        /// <summary>
        /// record constructor
        /// </summary>
        NewRecord,
        
        /// <summary>
        /// Get the key from a Ref
        /// </summary>
        GetRefKey,
        
       /// <summary>
        /// Get the ref from an entity instance
        /// </summary>
        GetEntityRef,
        
        /// <summary>
        /// create a reference 
        /// </summary>
        Ref,
        
        /// <summary>
        /// exists
        /// </summary>
        Exists,

        /// <summary>
        /// get the singleton element from a collection
        /// </summary>
        Element,

        /// <summary>
        /// Builds up a collection
        /// </summary>
        Collect,

        /// <summary>
        /// gets the target entity pointed at by a reference
        /// </summary>
        Deref,

        /// <summary>
        /// Traverse a relationship and get the references of the other end
        /// </summary>
        Navigate,
        #endregion

        #region RelOpType
        /// <summary>
        /// A table scan
        /// </summary>
        ScanTable,
        /// <summary>
        /// A view scan
        /// </summary>
        ScanView,

        /// <summary>
        /// Filter
        /// </summary>
        Filter,
        
        /// <summary>
        /// Project
        /// </summary>
        Project,

        /// <summary>
        /// InnerJoin
        /// </summary>
        InnerJoin,

        /// <summary>
        /// LeftOuterJoin
        /// </summary>
        LeftOuterJoin,

        /// <summary>
        /// FullOuter join
        /// </summary>
        FullOuterJoin,

        /// <summary>
        /// Cross join
        /// </summary>
        CrossJoin,

        /// <summary>
        /// cross apply
        /// </summary>
        CrossApply,

        /// <summary>
        /// outer apply 
        /// </summary>
        OuterApply,

        /// <summary>
        /// Unnest
        /// </summary>
        Unnest,

        /// <summary>
        /// Sort
        /// </summary>
        Sort,

        /// <summary>
        /// Constrained Sort (physical paging - Limit and Skip)
        /// </summary>
        ConstrainedSort,

        /// <summary>
        /// GroupBy
        /// </summary>
        GroupBy,

        /// <summary>
        /// GroupByInto (projects the group as well)
        /// </summary>
        GroupByInto,

        /// <summary>
        /// UnionAll
        /// </summary>
        UnionAll,
        /// <summary>
        /// Intersect
        /// </summary>
        Intersect,
        /// <summary>
        /// Except
        /// </summary>
        Except,

        /// <summary>
        /// Distinct
        /// </summary>
        Distinct,

        /// <summary>
        /// Select a single row from a subquery
        /// </summary>
        SingleRow,

        /// <summary>
        /// A table with exactly one row
        /// </summary>
        SingleRowTable,

        #endregion

        #region AncillaryOpType
        /// <summary>
        /// Variable definition
        /// </summary>
        VarDef,
        /// <summary>
        /// List of variable definitions
        /// </summary>
        VarDefList,
        #endregion
        
        #region RulePatternOpType
        /// <summary>
        /// Leaf
        /// </summary>
        Leaf,
        #endregion

        #region PhysicalOpType
        /// <summary>
        /// Physical Project
        /// </summary>
        PhysicalProject,

        /// <summary>
        /// single-stream nest aggregation
        /// </summary>
        SingleStreamNest,
        /// <summary>
        /// multi-stream nest aggregation
        /// </summary>
        MultiStreamNest,
        #endregion

        /// <summary>
        /// NotValid
        /// </summary>
        MaxMarker,
        NotValid = MaxMarker
    }

    /// <summary>
    /// Represents an operator 
    /// </summary>
    internal abstract class Op
    {
        #region private state
        private OpType m_opType;
        #endregion

        #region constructors
        /// <summary>
        /// Basic constructor
        /// </summary>
        internal Op(OpType opType) 
        { 
            m_opType = opType; 
        }
        #endregion

        #region public methods
        /// <summary>
        /// Represents an unknown arity. Usually for Ops that can have a varying number of Args
        /// </summary>
        internal const int ArityVarying = -1;
 
        /// <summary>
        /// Kind of Op
        /// </summary>
        internal OpType OpType { get { return m_opType; } }

        /// <summary>
        /// The Arity of this Op (ie) how many arguments can it have.
        /// Returns -1 if the arity is not known a priori
        /// </summary>
        internal virtual int Arity { get { return ArityVarying; } }

        /// <summary>
        /// Is this a ScalarOp
        /// </summary>
        internal virtual bool IsScalarOp { get { return false; } }

        /// <summary>
        /// Is this a RulePatternOp
        /// </summary>
        internal virtual bool IsRulePatternOp { get { return false; } }

        /// <summary>
        /// Is this a RelOp
        /// </summary>
        internal virtual bool IsRelOp { get { return false; } }

        /// <summary>
        /// Is this an AncillaryOp
        /// </summary>
        internal virtual bool IsAncillaryOp { get { return false; } }

        /// <summary>
        /// Is this a PhysicalOp
        /// </summary>
        internal virtual bool IsPhysicalOp { get { return false; } }

        /// <summary>
        /// Is the other Op equivalent?
        /// </summary>
        /// <param name="other">the other Op to compare</param>
        /// <returns>true, if the Ops are equivalent</returns>
        internal virtual bool IsEquivalent(Op other)
        {
            return false;
        }

        /// <summary>
        /// Simple mechanism to get the type for an Op. Applies only to scalar and ancillaryOps
        /// </summary>
        internal virtual TypeUsage Type
        {
            get { return null; }
            set { throw System.Data.Entity.Error.NotSupported(); }
        }

        /// <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 virtual 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 virtual TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) 
        { 
            return v.Visit(this, n);
        }
        #endregion
    }

    /// <summary>
    /// All scalars fall into this category
    /// </summary>
    internal abstract class ScalarOp : Op
    {
        #region private state
        private TypeUsage m_type;
        #endregion

        #region constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="opType">kind of Op</param>
        /// <param name="type">type of value produced by this Op</param>
        internal ScalarOp(OpType opType, TypeUsage type)
            : this(opType)
        {
            Debug.Assert(type != null, "No type specified for ScalarOp");
            m_type = type;
        }

        protected ScalarOp(OpType opType) : base(opType) { }
        #endregion

        #region public methods
        /// <summary>
        /// ScalarOp
        /// </summary>
        internal override bool IsScalarOp { get { return true; } }

        /// <summary>
        /// Two scalarOps are equivalent (usually) if their OpTypes and types are the 
        /// same. Obviously, their arguments need to be equivalent as well - but that's
        /// checked elsewhere
        /// </summary>
        /// <param name="other">The other Op to compare against</param>
        /// <returns>true, if the Ops are indeed equivalent</returns>
        internal override bool IsEquivalent(Op other)
        {
            return (other.OpType == this.OpType && TypeSemantics.IsStructurallyEqual(this.Type, other.Type));
        }

        /// <summary>
        /// Datatype of result
        /// </summary>
        internal override TypeUsage Type 
        { 
            get { return m_type; } 
            set { m_type = value; } 
        }
        
        /// <summary>
        /// Is this an Aggregate
        /// </summary>
        internal virtual bool IsAggregateOp 
        {
            get{return false;}
        }
        #endregion
    }

    /// <summary>
    /// All relational operators - filter, project, join etc.
    /// </summary>
    internal abstract class RelOp : Op
    {
        #region constructors
        /// <summary>
        /// Basic constructor.
        /// </summary>
        /// <param name="opType">kind of Op</param>
        internal RelOp(OpType opType) : base(opType) { }
        #endregion

        #region public methods
        /// <summary>
        /// RelOp
        /// </summary>
        internal override bool IsRelOp { get { return true; } }
        #endregion
    }

    /// <summary>
    /// AncillaryOp
    /// </summary>
    internal abstract class AncillaryOp : Op
    {
        #region constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="opType">kind of Op</param>
        internal AncillaryOp(OpType opType) : base(opType) { }
        #endregion

        #region public methods
        /// <summary>
        /// AncillaryOp
        /// </summary>
        internal override bool IsAncillaryOp { get { return true; } }
        #endregion
    }

    /// <summary>
    /// Represents all physical operators
    /// </summary>
    internal abstract class PhysicalOp : Op
    {
        #region constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="opType">the op type</param>
        internal PhysicalOp(OpType opType) : base(opType) { }
        #endregion

        #region public methods
        /// <summary>
        /// This is a physical Op
        /// </summary>
        internal override bool IsPhysicalOp { get { return true; } }
        #endregion
    }

    /// <summary>
    /// All rule pattern operators - Leaf, Tree
    /// </summary>
    internal abstract class RulePatternOp : Op
    {
        #region constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="opType">kind of Op</param>
        internal RulePatternOp(OpType opType) : base(opType) { }
        #endregion

        #region public methods
        /// <summary>
        /// RulePatternOp
        /// </summary>
        internal override bool IsRulePatternOp { get { return true; } }
        #endregion
    }
}