1 //---------------------------------------------------------------------
2 // <copyright file="RelOps.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
12 using System.Data.Metadata.Edm;
13 using System.Diagnostics;
14 using System.Globalization;
17 namespace System.Data.Query.InternalTrees
19 internal abstract class ScanTableBaseOp : RelOp
22 private Table m_table;
26 protected ScanTableBaseOp(OpType opType, Table table)
31 protected ScanTableBaseOp(OpType opType)
36 #region public methods
38 /// Get the table instance produced by this Op
40 internal Table Table { get { return m_table; } }
47 internal sealed class ScanTableOp : ScanTableBaseOp
53 /// <param name="table"></param>
54 internal ScanTableOp(Table table)
55 : base(OpType.ScanTable, table)
59 private ScanTableOp() : base(OpType.ScanTable) { }
62 #region public methods
64 /// Only to be used for pattern matches
66 internal static readonly ScanTableOp Pattern = new ScanTableOp();
71 internal override int Arity {get {return 0;} }
74 /// Visitor pattern method
76 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
77 /// <param name="n">The Node that references this Op</param>
79 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
82 /// Visitor pattern method for visitors with a return value
84 /// <param name="v">The visitor</param>
85 /// <param name="n">The node in question</param>
86 /// <returns>An instance of TResultType</returns>
88 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
93 /// Scans a view - very similar to a ScanTable
95 internal sealed class ScanViewOp : ScanTableBaseOp
101 /// <param name="table"></param>
102 internal ScanViewOp(Table table)
103 : base(OpType.ScanView, table)
106 private ScanViewOp() : base(OpType.ScanView) { }
109 #region public methods
111 /// Only to be used for pattern matches
113 internal static readonly ScanViewOp Pattern = new ScanViewOp();
118 internal override int Arity { get { return 1; } }
121 /// Visitor pattern method
123 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
124 /// <param name="n">The Node that references this Op</param>
125 [DebuggerNonUserCode]
126 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
129 /// Visitor pattern method for visitors with a return value
131 /// <param name="v">The visitor</param>
132 /// <param name="n">The node in question</param>
133 /// <returns>An instance of TResultType</returns>
134 [DebuggerNonUserCode]
135 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
140 /// Scans a virtual extent (ie) a transient collection
142 internal sealed class UnnestOp : RelOp
144 #region private state
145 private Table m_table;
150 internal UnnestOp(Var v, Table t) : this()
156 : base(OpType.Unnest)
162 internal static readonly UnnestOp Pattern = new UnnestOp();
165 /// The (collection-typed) Var that's being unnested
167 internal Var Var { get { return m_var; } }
170 /// The table instance produced by this Op
172 internal Table Table { get { return m_table; } }
177 internal override int Arity { get { return 1; } }
180 /// Visitor pattern method
182 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
183 /// <param name="n">The Node that references this Op</param>
184 [DebuggerNonUserCode]
185 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
188 /// Visitor pattern method for visitors with a return value
190 /// <param name="v">The visitor</param>
191 /// <param name="n">The node in question</param>
192 /// <returns>An instance of TResultType</returns>
193 [DebuggerNonUserCode]
194 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
199 /// Base class for all Join operations
201 internal abstract class JoinBaseOp : RelOp
204 internal JoinBaseOp(OpType opType) : base(opType) { }
207 #region public surface
209 /// 3 children - left, right, pred
211 internal override int Arity { get { return 3; } }
216 /// A CrossJoin (n-way)
218 internal sealed class CrossJoinOp : JoinBaseOp
221 private CrossJoinOp() : base(OpType.CrossJoin) { }
224 #region public methods
226 /// Singleton instance
228 internal static readonly CrossJoinOp Instance = new CrossJoinOp();
229 internal static readonly CrossJoinOp Pattern = CrossJoinOp.Instance;
232 /// varying number of children (but usually greater than 1)
234 internal override int Arity { get { return ArityVarying; } }
237 /// Visitor pattern method
239 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
240 /// <param name="n">The Node that references this Op</param>
241 [DebuggerNonUserCode]
242 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
245 /// Visitor pattern method for visitors with a return value
247 /// <param name="v">The visitor</param>
248 /// <param name="n">The node in question</param>
249 /// <returns>An instance of TResultType</returns>
250 [DebuggerNonUserCode]
251 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
258 internal sealed class InnerJoinOp : JoinBaseOp
261 private InnerJoinOp() : base(OpType.InnerJoin) { }
264 #region public methods
265 internal static readonly InnerJoinOp Instance = new InnerJoinOp();
266 internal static readonly InnerJoinOp Pattern = InnerJoinOp.Instance;
269 /// Visitor pattern method
271 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
272 /// <param name="n">The Node that references this Op</param>
273 [DebuggerNonUserCode]
274 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
277 /// Visitor pattern method for visitors with a return value
279 /// <param name="v">The visitor</param>
280 /// <param name="n">The node in question</param>
281 /// <returns>An instance of TResultType</returns>
282 [DebuggerNonUserCode]
283 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
290 internal sealed class LeftOuterJoinOp : JoinBaseOp
293 private LeftOuterJoinOp() : base(OpType.LeftOuterJoin) { }
296 #region public methods
297 internal static readonly LeftOuterJoinOp Instance = new LeftOuterJoinOp();
298 internal static readonly LeftOuterJoinOp Pattern = LeftOuterJoinOp.Instance;
301 /// Visitor pattern method
303 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
304 /// <param name="n">The Node that references this Op</param>
305 [DebuggerNonUserCode]
306 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
309 /// Visitor pattern method for visitors with a return value
311 /// <param name="v">The visitor</param>
312 /// <param name="n">The node in question</param>
313 /// <returns>An instance of TResultType</returns>
314 [DebuggerNonUserCode]
315 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
322 internal sealed class FullOuterJoinOp : JoinBaseOp
324 #region private constructors
325 private FullOuterJoinOp() : base(OpType.FullOuterJoin) { }
328 #region public methods
329 internal static readonly FullOuterJoinOp Instance = new FullOuterJoinOp();
330 internal static readonly FullOuterJoinOp Pattern = FullOuterJoinOp.Instance;
333 /// Visitor pattern method
335 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
336 /// <param name="n">The Node that references this Op</param>
337 [DebuggerNonUserCode]
338 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
341 /// Visitor pattern method for visitors with a return value
343 /// <param name="v">The visitor</param>
344 /// <param name="n">The node in question</param>
345 /// <returns>An instance of TResultType</returns>
346 [DebuggerNonUserCode]
347 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
352 /// Base class for all Apply Ops
354 internal abstract class ApplyBaseOp : RelOp
357 internal ApplyBaseOp(OpType opType) : base(opType) { }
360 #region public surface
362 /// 2 children - left, right
364 internal override int Arity { get { return 2; } }
371 internal sealed class CrossApplyOp : ApplyBaseOp
374 private CrossApplyOp() : base(OpType.CrossApply) { }
377 #region public methods
378 internal static readonly CrossApplyOp Instance = new CrossApplyOp();
379 internal static readonly CrossApplyOp Pattern = CrossApplyOp.Instance;
382 /// Visitor pattern method
384 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
385 /// <param name="n">The Node that references this Op</param>
386 [DebuggerNonUserCode]
387 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
390 /// Visitor pattern method for visitors with a return value
392 /// <param name="v">The visitor</param>
393 /// <param name="n">The node in question</param>
394 /// <returns>An instance of TResultType</returns>
395 [DebuggerNonUserCode]
396 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
403 internal sealed class OuterApplyOp : ApplyBaseOp
406 private OuterApplyOp() : base(OpType.OuterApply) { }
409 #region public methods
410 internal static readonly OuterApplyOp Instance = new OuterApplyOp();
411 internal static readonly OuterApplyOp Pattern = OuterApplyOp.Instance;
414 /// Visitor pattern method
416 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
417 /// <param name="n">The Node that references this Op</param>
418 [DebuggerNonUserCode]
419 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
422 /// Visitor pattern method for visitors with a return value
424 /// <param name="v">The visitor</param>
425 /// <param name="n">The node in question</param>
426 /// <returns>An instance of TResultType</returns>
427 [DebuggerNonUserCode]
428 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
435 internal sealed class FilterOp : RelOp
438 private FilterOp() : base(OpType.Filter) { }
441 #region public methods
442 internal static readonly FilterOp Instance = new FilterOp();
443 internal static readonly FilterOp Pattern = FilterOp.Instance;
446 /// 2 children - input, pred
448 internal override int Arity { get { return 2; } }
451 /// Visitor pattern method
453 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
454 /// <param name="n">The Node that references this Op</param>
455 [DebuggerNonUserCode]
456 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
459 /// Visitor pattern method for visitors with a return value
461 /// <param name="v">The visitor</param>
462 /// <param name="n">The node in question</param>
463 /// <returns>An instance of TResultType</returns>
464 [DebuggerNonUserCode]
465 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
472 internal sealed class ProjectOp : RelOp
474 #region private state
475 private VarVec m_vars;
480 : base(OpType.Project)
482 internal ProjectOp(VarVec vars) : this()
484 Debug.Assert(null != vars, "null vars?");
485 Debug.Assert(!vars.IsEmpty, "empty varlist?");
490 #region public methods
491 internal static readonly ProjectOp Pattern = new ProjectOp();
494 /// 2 children - input, projections (VarDefList)
496 internal override int Arity { get { return 2; } }
499 /// The Vars projected by this Op
501 internal VarVec Outputs { get { return m_vars; } }
504 /// Visitor pattern method
506 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
507 /// <param name="n">The Node that references this Op</param>
508 [DebuggerNonUserCode]
509 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
512 /// Visitor pattern method for visitors with a return value
514 /// <param name="v">The visitor</param>
515 /// <param name="n">The node in question</param>
516 /// <returns>An instance of TResultType</returns>
517 [DebuggerNonUserCode]
518 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
525 internal class SortKey
527 #region private state
530 private string m_collation;
534 internal SortKey(Var v, bool asc, string collation)
538 m_collation = collation;
542 #region public methods
544 /// The Var being sorted
548 get { return m_var; }
549 set { m_var = value; }
553 /// Is this a sort asc, or a sort desc
555 internal bool AscendingSort { get { return m_asc; } }
558 /// An optional collation (only for string types)
560 internal string Collation { get { return m_collation; } }
565 /// Base type for SortOp and ConstrainedSortOp
567 internal abstract class SortBaseOp : RelOp
569 #region private state
570 private List<SortKey> m_keys;
574 // Pattern constructor
575 internal SortBaseOp(OpType opType)
578 Debug.Assert(opType == OpType.Sort || opType == OpType.ConstrainedSort, "SortBaseOp OpType must be Sort or ConstrainedSort");
581 internal SortBaseOp(OpType opType, List<SortKey> sortKeys)
592 internal List<SortKey> Keys { get { return m_keys; } }
598 internal sealed class SortOp : SortBaseOp
601 private SortOp() : base(OpType.Sort) { }
603 internal SortOp(List<SortKey> sortKeys) : base(OpType.Sort, sortKeys) {}
606 #region public methods
607 internal static readonly SortOp Pattern = new SortOp();
610 /// 1 child - the input, SortOp must not contain local VarDefs
612 internal override int Arity { get { return 1; } }
615 /// Visitor pattern method
617 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
618 /// <param name="n">The Node that references this Op</param>
619 [DebuggerNonUserCode]
620 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
623 /// Visitor pattern method for visitors with a return value
625 /// <param name="v">The visitor</param>
626 /// <param name="n">The node in question</param>
627 /// <returns>An instance of TResultType</returns>
628 [DebuggerNonUserCode]
629 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
634 /// A Constrained SortOp. Used to represent physical paging (skip, limit, skip + limit) operations.
636 internal sealed class ConstrainedSortOp : SortBaseOp
638 #region private state
639 private bool _withTies;
643 // Pattern constructor
644 private ConstrainedSortOp() : base(OpType.ConstrainedSort) { }
646 internal ConstrainedSortOp(List<SortKey> sortKeys, bool withTies)
647 : base(OpType.ConstrainedSort, sortKeys)
649 _withTies = withTies;
653 #region public methods
654 internal bool WithTies { get { return _withTies; } set { _withTies = value; } }
656 internal static readonly ConstrainedSortOp Pattern = new ConstrainedSortOp();
659 /// 3 children - the input, a possibly NullOp limit and a possibly NullOp skip count.
661 internal override int Arity { get { return 3; } }
664 /// Visitor pattern method
666 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
667 /// <param name="n">The Node that references this Op</param>
668 [DebuggerNonUserCode]
669 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
672 /// Visitor pattern method for visitors with a return value
674 /// <param name="v">The visitor</param>
675 /// <param name="n">The node in question</param>
676 /// <returns>An instance of TResultType</returns>
677 [DebuggerNonUserCode]
678 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
685 internal abstract class GroupByBaseOp : RelOp
687 #region private state
688 private VarVec m_keys;
689 private VarVec m_outputs;
693 protected GroupByBaseOp(OpType opType) : base(opType)
695 Debug.Assert(opType == OpType.GroupBy || opType == OpType.GroupByInto, "GroupByBaseOp OpType must be GroupBy or GroupByInto");
697 internal GroupByBaseOp(OpType opType, VarVec keys, VarVec outputs)
705 #region public methods
709 internal VarVec Keys { get { return m_keys; } }
712 /// All outputs of this Op - includes keys and aggregates
714 internal VarVec Outputs { get { return m_outputs; } }
717 /// Visitor pattern method
719 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
720 /// <param name="n">The Node that references this Op</param>
721 [DebuggerNonUserCode]
722 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
725 /// Visitor pattern method for visitors with a return value
727 /// <param name="v">The visitor</param>
728 /// <param name="n">The node in question</param>
729 /// <returns>An instance of TResultType</returns>
730 [DebuggerNonUserCode]
731 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
738 internal sealed class GroupByOp : GroupByBaseOp
741 private GroupByOp() : base(OpType.GroupBy) { }
742 internal GroupByOp(VarVec keys, VarVec outputs)
743 : base(OpType.GroupBy, keys, outputs)
748 #region public methods
749 internal static readonly GroupByOp Pattern = new GroupByOp();
752 /// 3 children - input, keys (vardeflist), aggregates (vardeflist)
754 internal override int Arity { get { return 3; } }
757 /// Visitor pattern method
759 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
760 /// <param name="n">The Node that references this Op</param>
761 [DebuggerNonUserCode]
762 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
765 /// Visitor pattern method for visitors with a return value
767 /// <param name="v">The visitor</param>
768 /// <param name="n">The node in question</param>
769 /// <returns>An instance of TResultType</returns>
770 [DebuggerNonUserCode]
771 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
778 internal sealed class GroupByIntoOp : GroupByBaseOp
780 #region private state
781 private readonly VarVec m_inputs;
785 private GroupByIntoOp() : base(OpType.GroupByInto) { }
786 internal GroupByIntoOp(VarVec keys, VarVec inputs, VarVec outputs)
787 : base(OpType.GroupByInto, keys, outputs)
789 this.m_inputs = inputs;
793 #region public methods
797 internal VarVec Inputs { get { return m_inputs; } }
799 internal static readonly GroupByIntoOp Pattern = new GroupByIntoOp();
802 /// 4 children - input, keys (vardeflist), aggregates (vardeflist), groupaggregates (vardeflist)
804 internal override int Arity { get { return 4; } }
807 /// Visitor pattern method
809 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
810 /// <param name="n">The Node that references this Op</param>
811 [DebuggerNonUserCode]
812 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
815 /// Visitor pattern method for visitors with a return value
817 /// <param name="v">The visitor</param>
818 /// <param name="n">The node in question</param>
819 /// <returns>An instance of TResultType</returns>
820 [DebuggerNonUserCode]
821 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
826 /// Base class for set operations - union, intersect, except
828 internal abstract class SetOp : RelOp
830 #region private state
831 private VarMap[] m_varMap;
832 private VarVec m_outputVars;
836 internal SetOp(OpType opType, VarVec outputs, VarMap left, VarMap right)
839 m_varMap = new VarMap[2];
842 m_outputVars = outputs;
844 protected SetOp(OpType opType) : base(opType)
849 #region public methods
852 /// 2 children - left, right
854 internal override int Arity { get { return 2; } }
857 /// Map of result vars to the vars of each branch of the setOp
859 internal VarMap[] VarMap { get { return m_varMap; } }
862 /// Get the set of output vars produced
864 internal VarVec Outputs { get { return m_outputVars; } }
869 /// UnionAll (ie) no duplicate elimination
871 internal sealed class UnionAllOp : SetOp
873 #region private state
874 private Var m_branchDiscriminator;
878 private UnionAllOp() : base(OpType.UnionAll) { }
880 internal UnionAllOp(VarVec outputs, VarMap left, VarMap right, Var branchDiscriminator) : base(OpType.UnionAll, outputs, left, right)
882 m_branchDiscriminator = branchDiscriminator;
886 #region public methods
887 internal static readonly UnionAllOp Pattern = new UnionAllOp();
890 /// Returns the branch discriminator var for this op. It may be null, if
891 /// we haven't been through key pullup yet.
893 internal Var BranchDiscriminator { get { return m_branchDiscriminator; } }
896 /// Visitor pattern method
898 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
899 /// <param name="n">The Node that references this Op</param>
900 [DebuggerNonUserCode]
901 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
904 /// Visitor pattern method for visitors with a return value
906 /// <param name="v">The visitor</param>
907 /// <param name="n">The node in question</param>
908 /// <returns>An instance of TResultType</returns>
909 [DebuggerNonUserCode]
910 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
917 internal sealed class IntersectOp : SetOp
920 private IntersectOp() : base(OpType.Intersect) { }
921 internal IntersectOp(VarVec outputs, VarMap left, VarMap right) : base(OpType.Intersect, outputs, left,right) { }
924 #region public methods
925 internal static readonly IntersectOp Pattern = new IntersectOp();
928 /// Visitor pattern method
930 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
931 /// <param name="n">The Node that references this Op</param>
932 [DebuggerNonUserCode]
933 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
936 /// Visitor pattern method for visitors with a return value
938 /// <param name="v">The visitor</param>
939 /// <param name="n">The node in question</param>
940 /// <returns>An instance of TResultType</returns>
941 [DebuggerNonUserCode]
942 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
949 internal sealed class ExceptOp : SetOp
952 private ExceptOp() : base(OpType.Except) { }
953 internal ExceptOp(VarVec outputs, VarMap left, VarMap right) : base(OpType.Except, outputs, left, right) { }
956 #region public methods
957 internal static readonly ExceptOp Pattern = new ExceptOp();
960 /// Visitor pattern method
962 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
963 /// <param name="n">The Node that references this Op</param>
964 [DebuggerNonUserCode]
965 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
968 /// Visitor pattern method for visitors with a return value
970 /// <param name="v">The visitor</param>
971 /// <param name="n">The node in question</param>
972 /// <returns>An instance of TResultType</returns>
973 [DebuggerNonUserCode]
974 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
981 internal sealed class DistinctOp : RelOp
983 #region private state
984 private VarVec m_keys;
988 private DistinctOp() : base(OpType.Distinct)
991 internal DistinctOp(VarVec keyVars) : this()
993 Debug.Assert(keyVars != null);
994 Debug.Assert(!keyVars.IsEmpty);
999 #region public methods
1000 internal static readonly DistinctOp Pattern = new DistinctOp();
1005 internal override int Arity { get { return 1; } }
1008 /// Get "key" vars for the distinct
1010 internal VarVec Keys { get { return m_keys; } }
1013 /// Visitor pattern method
1015 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1016 /// <param name="n">The Node that references this Op</param>
1017 [DebuggerNonUserCode]
1018 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1021 /// Visitor pattern method for visitors with a return value
1023 /// <param name="v">The visitor</param>
1024 /// <param name="n">The node in question</param>
1025 /// <returns>An instance of TResultType</returns>
1026 [DebuggerNonUserCode]
1027 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1032 /// Selects out a single row from a underlying subquery. Two flavors of this Op exist.
1033 /// The first flavor enforces the single-row-ness (ie) an error is raised if the
1034 /// underlying subquery produces more than one row.
1035 /// The other flavor simply choses any row from the input
1037 internal sealed class SingleRowOp : RelOp
1039 #region constructors
1040 private SingleRowOp() : base(OpType.SingleRow) { }
1043 #region public methods
1045 /// Singleton instance
1047 internal static readonly SingleRowOp Instance = new SingleRowOp();
1049 /// Pattern for transformation rules
1051 internal static readonly SingleRowOp Pattern = Instance;
1056 internal override int Arity { get { return 1; } }
1059 /// Visitor pattern method
1061 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1062 /// <param name="n">The Node that references this Op</param>
1063 [DebuggerNonUserCode]
1064 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1067 /// Visitor pattern method for visitors with a return value
1069 /// <param name="v">The visitor</param>
1070 /// <param name="n">The node in question</param>
1071 /// <returns>An instance of TResultType</returns>
1072 [DebuggerNonUserCode]
1073 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1079 /// Represents a table with a single row
1081 internal sealed class SingleRowTableOp : RelOp
1083 #region constructors
1084 private SingleRowTableOp() : base(OpType.SingleRowTable) { }
1087 #region public methods
1089 /// Singleton instance
1091 internal static readonly SingleRowTableOp Instance = new SingleRowTableOp();
1093 /// Pattern for transformation rules
1095 internal static readonly SingleRowTableOp Pattern = Instance;
1100 internal override int Arity { get { return 0; } }
1103 /// Visitor pattern method
1105 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1106 /// <param name="n">The Node that references this Op</param>
1107 [DebuggerNonUserCode]
1108 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1111 /// Visitor pattern method for visitors with a return value
1113 /// <param name="v">The visitor</param>
1114 /// <param name="n">The node in question</param>
1115 /// <returns>An instance of TResultType</returns>
1116 [DebuggerNonUserCode]
1117 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }