1 //---------------------------------------------------------------------
2 // <copyright file="Visitors.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
8 //---------------------------------------------------------------------
10 namespace System.Data.Query.InternalTrees
13 using pc = System.Data.Query.PlanCompiler; // To be able to use PlanCompiler.Assert instead of Debug.Assert in this class.
16 /// Simple implemenation of the BasicOpVisitor interface.
18 internal abstract class BasicOpVisitor
21 /// Default constructor.
23 internal BasicOpVisitor() { }
25 #region Visitor Helpers
27 /// Visit the children of this Node
29 /// <param name="n">The Node that references the Op</param>
30 protected virtual void VisitChildren(Node n)
32 foreach (Node chi in n.Children)
39 /// Visit the children of this Node. but in reverse order
41 /// <param name="n">The current node</param>
42 protected virtual void VisitChildrenReverse(Node n)
44 for (int i = n.Children.Count - 1; i >= 0; i--)
46 VisitNode(n.Children[i]);
53 /// <param name="n"></param>
54 internal virtual void VisitNode(Node n)
59 /// Default node visitor
61 /// <param name="n"></param>
62 protected virtual void VisitDefault(Node n)
68 /// Default handler for all constantOps
70 /// <param name="op">the constant op</param>
71 /// <param name="n">the node</param>
72 protected virtual void VisitConstantOp(ConstantBaseOp op, Node n)
74 VisitScalarOpDefault(op, n);
78 /// Default handler for all TableOps
80 /// <param name="op"></param>
81 /// <param name="n"></param>
82 protected virtual void VisitTableOp(ScanTableBaseOp op, Node n)
84 VisitRelOpDefault(op, n);
88 /// Default handler for all JoinOps
90 /// <param name="op">join op</param>
91 /// <param name="n"></param>
92 protected virtual void VisitJoinOp(JoinBaseOp op, Node n)
94 VisitRelOpDefault(op, n);
98 /// Default handler for all ApplyOps
100 /// <param name="op">apply op</param>
101 /// <param name="n"></param>
102 protected virtual void VisitApplyOp(ApplyBaseOp op, Node n)
104 VisitRelOpDefault(op, n);
107 /// Default handler for all SetOps
109 /// <param name="op">set op</param>
110 /// <param name="n"></param>
111 protected virtual void VisitSetOp(SetOp op, Node n)
113 VisitRelOpDefault(op, n);
117 /// Default handler for all SortOps
119 /// <param name="op">sort op</param>
120 /// <param name="n"></param>
121 protected virtual void VisitSortOp(SortBaseOp op, Node n)
123 VisitRelOpDefault(op, n);
127 /// Default handler for all GroupBy ops
129 /// <param name="op">sort op</param>
130 /// <param name="n"></param>
131 protected virtual void VisitGroupByOp(GroupByBaseOp op, Node n)
133 VisitRelOpDefault(op, n);
137 #region BasicOpVisitor Members
140 /// Trap method for unrecognized Op types
142 /// <param name="op">The Op being visited</param>
143 /// <param name="n">The Node that references the Op</param>
144 public virtual void Visit(Op op, Node n)
146 throw new NotSupportedException(System.Data.Entity.Strings.Iqt_General_UnsupportedOp(op.GetType().FullName));
150 protected virtual void VisitScalarOpDefault(ScalarOp op, Node n)
156 /// Visitor pattern method for ConstantOp
158 /// <param name="op">The ConstantOp being visited</param>
159 /// <param name="n">The Node that references the Op</param>
160 public virtual void Visit(ConstantOp op, Node n)
162 VisitConstantOp(op, n);
166 /// Visitor pattern method for NullOp
168 /// <param name="op">The NullOp being visited</param>
169 /// <param name="n">The Node that references the Op</param>
170 public virtual void Visit(NullOp op, Node n)
172 VisitConstantOp(op, n);
176 /// Visitor pattern method for NullSentinelOp
178 /// <param name="op">The NullSentinelOp being visited</param>
179 /// <param name="n">The Node that references the Op</param>
180 public virtual void Visit(NullSentinelOp op, Node n)
182 VisitConstantOp(op, n);
186 /// Visitor pattern method for InternalConstantOp
188 /// <param name="op">The InternalConstantOp being visited</param>
189 /// <param name="n">The Node that references the Op</param>
190 public virtual void Visit(InternalConstantOp op, Node n)
192 VisitConstantOp(op, n);
196 /// Visitor pattern method for ConstantPredicateOp
198 /// <param name="op">The ConstantPredicateOp being visited</param>
199 /// <param name="n">The Node that references the Op</param>
200 public virtual void Visit(ConstantPredicateOp op, Node n)
202 VisitConstantOp(op, n);
206 /// Visitor pattern method for FunctionOp
208 /// <param name="op">The FunctionOp being visited</param>
209 /// <param name="n">The Node that references the Op</param>
210 public virtual void Visit(FunctionOp op, Node n)
212 VisitScalarOpDefault(op, n);
216 /// Visitor pattern method for PropertyOp
218 /// <param name="op">The PropertyOp being visited</param>
219 /// <param name="n">The Node that references the Op</param>
220 public virtual void Visit(PropertyOp op, Node n)
222 VisitScalarOpDefault(op, n);
226 /// Visitor pattern method for RelPropertyOp
228 /// <param name="op">The RelPropertyOp being visited</param>
229 /// <param name="n">The Node that references the Op</param>
230 public virtual void Visit(RelPropertyOp op, Node n)
232 VisitScalarOpDefault(op, n);
236 /// Visitor pattern method for CaseOp
238 /// <param name="op">The CaseOp being visited</param>
239 /// <param name="n">The Node that references the Op</param>
240 public virtual void Visit(CaseOp op, Node n)
242 VisitScalarOpDefault(op, n);
246 /// Visitor pattern method for ComparisonOp
248 /// <param name="op">The ComparisonOp being visited</param>
249 /// <param name="n">The Node that references the Op</param>
250 public virtual void Visit(ComparisonOp op, Node n)
252 VisitScalarOpDefault(op, n);
256 /// Visitor pattern method for LikeOp
258 /// <param name="op">The LikeOp being visited</param>
259 /// <param name="n">The Node that references the Op</param>
260 public virtual void Visit(LikeOp op, Node n)
262 VisitScalarOpDefault(op, n);
266 /// Visitor pattern method for AggregateOp
268 /// <param name="op">The AggregateOp being visited</param>
269 /// <param name="n">The Node that references the Op</param>
270 public virtual void Visit(AggregateOp op, Node n)
272 VisitScalarOpDefault(op, n);
276 /// Visitor pattern method for NewInstanceOp
278 /// <param name="op">The NewInstanceOp being visited</param>
279 /// <param name="n">The Node that references the Op</param>
280 public virtual void Visit(NewInstanceOp op, Node n)
282 VisitScalarOpDefault(op, n);
286 /// Visitor pattern method for NewEntityOp
288 /// <param name="op">The NewEntityOp being visited</param>
289 /// <param name="n">The Node that references the Op</param>
290 public virtual void Visit(NewEntityOp op, Node n)
292 VisitScalarOpDefault(op, n);
296 /// Visitor pattern method for DiscriminatedNewInstanceOp
298 /// <param name="op">The DiscriminatedNewInstanceOp being visited</param>
299 /// <param name="n">The Node that references the Op</param>
300 public virtual void Visit(DiscriminatedNewEntityOp op, Node n)
302 VisitScalarOpDefault(op, n);
306 /// Visitor pattern method for NewMultisetOp
308 /// <param name="op">The NewMultisetOp being visited</param>
309 /// <param name="n">The Node that references the Op</param>
310 public virtual void Visit(NewMultisetOp op, Node n)
312 VisitScalarOpDefault(op, n);
316 /// Visitor pattern method for NewRecordOp
318 /// <param name="op">The NewRecordOp being visited</param>
319 /// <param name="n">The Node that references the Op</param>
320 public virtual void Visit(NewRecordOp op, Node n)
322 VisitScalarOpDefault(op, n);
326 /// Visitor pattern method for RefOp
328 /// <param name="op">The RefOp being visited</param>
329 /// <param name="n">The Node that references the Op</param>
330 public virtual void Visit(RefOp op, Node n)
332 VisitScalarOpDefault(op, n);
336 /// Visitor pattern method for VarRefOp
338 /// <param name="op">The VarRefOp being visited</param>
339 /// <param name="n">The Node that references the Op</param>
340 public virtual void Visit(VarRefOp op, Node n)
342 VisitScalarOpDefault(op, n);
346 /// Visitor pattern method for ConditionalOp
348 /// <param name="op">The ConditionalOp being visited</param>
349 /// <param name="n">The Node that references the Op</param>
350 public virtual void Visit(ConditionalOp op, Node n)
352 VisitScalarOpDefault(op, n);
356 /// Visitor pattern method for ArithmeticOp
358 /// <param name="op">The ArithmeticOp being visited</param>
359 /// <param name="n">The Node that references the Op</param>
360 public virtual void Visit(ArithmeticOp op, Node n)
362 VisitScalarOpDefault(op, n);
366 /// Visitor pattern method for TreatOp
368 /// <param name="op">The TreatOp being visited</param>
369 /// <param name="n">The Node that references the Op</param>
370 public virtual void Visit(TreatOp op, Node n)
372 VisitScalarOpDefault(op, n);
376 /// Visitor pattern method for CastOp
378 /// <param name="op">The CastOp being visited</param>
379 /// <param name="n">The Node that references the Op</param>
380 public virtual void Visit(CastOp op, Node n)
382 VisitScalarOpDefault(op, n);
385 /// Visitor pattern method for SoftCastOp
387 /// <param name="op">The SoftCastOp being visited</param>
388 /// <param name="n">The Node that references the Op</param>
389 public virtual void Visit(SoftCastOp op, Node n)
391 VisitScalarOpDefault(op, n);
395 /// Visitor pattern method for IsOp
397 /// <param name="op">The IsOp being visited</param>
398 /// <param name="n">The Node that references the Op</param>
399 public virtual void Visit(IsOfOp op, Node n)
401 VisitScalarOpDefault(op, n);
405 /// Visitor pattern method for ExistsOp
407 /// <param name="op">The ExistsOp being visited</param>
408 /// <param name="n">The Node that references the Op</param>
409 public virtual void Visit(ExistsOp op, Node n)
411 VisitScalarOpDefault(op, n);
415 /// Visitor pattern method for ElementOp
417 /// <param name="op">The ElementOp being visited</param>
418 /// <param name="n">The Node that references the Op</param>
419 public virtual void Visit(ElementOp op, Node n)
421 VisitScalarOpDefault(op, n);
425 /// Visitor pattern method for GetEntityRefOp
427 /// <param name="op">The GetEntityRefOp being visited</param>
428 /// <param name="n">The Node that references the Op</param>
429 public virtual void Visit(GetEntityRefOp op, Node n)
431 VisitScalarOpDefault(op, n);
435 /// Visitor pattern method for GetRefKeyOp
437 /// <param name="op">The GetRefKeyOp being visited</param>
438 /// <param name="n">The Node that references the Op</param>
439 public virtual void Visit(GetRefKeyOp op, Node n)
441 VisitScalarOpDefault(op, n);
445 /// Visitor pattern method for NestOp
447 /// <param name="op">The NestOp being visited</param>
448 /// <param name="n">The Node that references the Op</param>
449 public virtual void Visit(CollectOp op, Node n)
451 VisitScalarOpDefault(op, n);
454 public virtual void Visit(DerefOp op, Node n)
456 VisitScalarOpDefault(op, n);
459 public virtual void Visit(NavigateOp op, Node n)
461 VisitScalarOpDefault(op, n);
467 protected virtual void VisitAncillaryOpDefault(AncillaryOp op, Node n)
473 /// Visitor pattern method for VarDefOp
475 /// <param name="op">The VarDefOp being visited</param>
476 /// <param name="n">The Node that references the Op</param>
477 public virtual void Visit(VarDefOp op, Node n)
479 VisitAncillaryOpDefault(op, n);
483 /// Visitor pattern method for VarDefListOp
485 /// <param name="op">The VarDefListOp being visited</param>
486 /// <param name="n">The Node that references the Op</param>
487 public virtual void Visit(VarDefListOp op, Node n)
489 VisitAncillaryOpDefault(op, n);
496 protected virtual void VisitRelOpDefault(RelOp op, Node n)
502 /// Visitor pattern method for ScanTableOp
504 /// <param name="op">The ScanTableOp being visited</param>
505 /// <param name="n">The Node that references the Op</param>
506 public virtual void Visit(ScanTableOp op, Node n)
512 /// Visitor pattern method for ScanViewOp
514 /// <param name="op">The ScanViewOp being visited</param>
515 /// <param name="n">The Node that references the Op</param>
516 public virtual void Visit(ScanViewOp op, Node n)
522 /// Visitor pattern method for UnnestOp
524 /// <param name="op">The UnnestOp being visited</param>
525 /// <param name="n">The Node that references the Op</param>
526 public virtual void Visit(UnnestOp op, Node n)
528 VisitRelOpDefault(op, n);
532 /// Visitor pattern method for ProjectOp
534 /// <param name="op">The ProjectOp being visited</param>
535 /// <param name="n">The Node that references the Op</param>
536 public virtual void Visit(ProjectOp op, Node n)
538 VisitRelOpDefault(op, n);
542 /// Visitor pattern method for FilterOp
544 /// <param name="op">The FilterOp being visited</param>
545 /// <param name="n">The Node that references the Op</param>
546 public virtual void Visit(FilterOp op, Node n)
548 VisitRelOpDefault(op, n);
552 /// Visitor pattern method for SortOp
554 /// <param name="op">The SortOp being visited</param>
555 /// <param name="n">The Node that references the Op</param>
556 public virtual void Visit(SortOp op, Node n)
562 /// Visitor pattern method for ConstrainedSortOp
564 /// <param name="op">The ConstrainedSortOp being visited</param>
565 /// <param name="n">The Node that references the Op</param>
566 public virtual void Visit(ConstrainedSortOp op, Node n)
572 /// Visitor pattern method for GroupByOp
574 /// <param name="op">The GroupByOp being visited</param>
575 /// <param name="n">The Node that references the Op</param>
576 public virtual void Visit(GroupByOp op, Node n)
578 VisitGroupByOp(op, n);
582 /// Visitor pattern method for GroupByIntoOp
584 /// <param name="op">The GroupByIntoOp being visited</param>
585 /// <param name="n">The Node that references the Op</param>
586 public virtual void Visit(GroupByIntoOp op, Node n)
588 VisitGroupByOp(op, n);
592 /// Visitor pattern method for CrossJoinOp
594 /// <param name="op">The CrossJoinOp being visited</param>
595 /// <param name="n">The Node that references the Op</param>
596 public virtual void Visit(CrossJoinOp op, Node n)
602 /// Visitor pattern method for InnerJoinOp
604 /// <param name="op">The InnerJoinOp being visited</param>
605 /// <param name="n">The Node that references the Op</param>
606 public virtual void Visit(InnerJoinOp op, Node n)
612 /// Visitor pattern method for LeftOuterJoinOp
614 /// <param name="op">The LeftOuterJoinOp being visited</param>
615 /// <param name="n">The Node that references the Op</param>
616 public virtual void Visit(LeftOuterJoinOp op, Node n)
622 /// Visitor pattern method for FullOuterJoinOp
624 /// <param name="op">The FullOuterJoinOp being visited</param>
625 /// <param name="n">The Node that references the Op</param>
626 public virtual void Visit(FullOuterJoinOp op, Node n)
632 /// Visitor pattern method for CrossApplyOp
634 /// <param name="op">The CrossApplyOp being visited</param>
635 /// <param name="n">The Node that references the Op</param>
636 public virtual void Visit(CrossApplyOp op, Node n)
642 /// Visitor pattern method for OuterApplyOp
644 /// <param name="op">The OuterApplyOp being visited</param>
645 /// <param name="n">The Node that references the Op</param>
646 public virtual void Visit(OuterApplyOp op, Node n)
652 /// Visitor pattern method for UnionAllOp
654 /// <param name="op">The UnionAllOp being visited</param>
655 /// <param name="n">The Node that references the Op</param>
656 public virtual void Visit(UnionAllOp op, Node n)
662 /// Visitor pattern method for IntersectOp
664 /// <param name="op">The IntersectOp being visited</param>
665 /// <param name="n">The Node that references the Op</param>
666 public virtual void Visit(IntersectOp op, Node n)
672 /// Visitor pattern method for ExceptOp
674 /// <param name="op">The ExceptOp being visited</param>
675 /// <param name="n">The Node that references the Op</param>
676 public virtual void Visit(ExceptOp op, Node n)
682 /// Visitor pattern method for DistinctOp
684 /// <param name="op">The DistinctOp being visited</param>
685 /// <param name="n">The Node that references the Op</param>
686 public virtual void Visit(DistinctOp op, Node n)
688 VisitRelOpDefault(op, n);
692 /// Visitor pattern method for SingleRowOp
694 /// <param name="op">The SingleRowOp being visited</param>
695 /// <param name="n">The Node that references the Op</param>
696 public virtual void Visit(SingleRowOp op, Node n)
698 VisitRelOpDefault(op, n);
702 /// Visitor pattern method for SingleRowTableOp
704 /// <param name="op">The SingleRowTableOp being visited</param>
705 /// <param name="n">The Node that references the Op</param>
706 public virtual void Visit(SingleRowTableOp op, Node n)
708 VisitRelOpDefault(op, n);
714 protected virtual void VisitPhysicalOpDefault(PhysicalOp op, Node n)
720 /// Visitor pattern method for PhysicalProjectOp
722 /// <param name="op">The op being visited</param>
723 /// <param name="n">The Node that references the Op</param>
724 public virtual void Visit(PhysicalProjectOp op, Node n)
726 VisitPhysicalOpDefault(op, n);
731 /// Common handling for all nestOps
733 /// <param name="op">nest op</param>
734 /// <param name="n"></param>
735 protected virtual void VisitNestOp(NestBaseOp op, Node n)
737 VisitPhysicalOpDefault(op, n);
740 /// Visitor pattern method for SingleStreamNestOp
742 /// <param name="op">The op being visited</param>
743 /// <param name="n">The Node that references the Op</param>
744 public virtual void Visit(SingleStreamNestOp op, Node n)
749 /// Visitor pattern method for MultistreamNestOp
751 /// <param name="op">The op being visited</param>
752 /// <param name="n">The Node that references the Op</param>
753 public virtual void Visit(MultiStreamNestOp op, Node n)
764 /// Simple implementation of the BasicOpVisitorOfT interface"/>
766 /// <typeparam name="TResultType">type parameter</typeparam>
767 internal abstract class BasicOpVisitorOfT<TResultType>
769 #region visitor helpers
772 /// Simply iterates over all children, and manages any updates
774 /// <param name="n">The current node</param>
775 protected virtual void VisitChildren(Node n)
777 for (int i = 0; i < n.Children.Count; i++)
779 VisitNode(n.Children[i]);
784 /// Simply iterates over all children, and manages any updates, but in reverse order
786 /// <param name="n">The current node</param>
787 protected virtual void VisitChildrenReverse(Node n)
789 for (int i = n.Children.Count - 1; i >= 0; i--)
791 VisitNode(n.Children[i]);
796 /// Simple wrapper to invoke the appropriate action on a node
798 /// <param name="n">the node to process</param>
799 /// <returns></returns>
800 internal TResultType VisitNode(Node n)
802 // Invoke the visitor
803 return n.Op.Accept<TResultType>(this, n);
807 /// A default processor for any node. Visits the children and returns itself unmodified.
809 /// <param name="n">the node to process</param>
810 /// <returns>a potentially new node</returns>
811 protected virtual TResultType VisitDefault(Node n)
814 return default(TResultType);
820 /// No processing yet for this node - raises an exception
822 /// <param name="n"></param>
823 internal virtual TResultType Unimplemented(Node n)
825 pc.PlanCompiler.Assert(false, "Not implemented op type");
826 return default(TResultType);
830 /// Catch-all processor - raises an exception
832 /// <param name="op"></param>
833 /// <param name="n"></param>
834 /// <returns></returns>
835 public virtual TResultType Visit(Op op, Node n)
837 return Unimplemented(n);
840 #region AncillaryOp Visitors
843 /// A default processor for all AncillaryOps.
845 /// Allows new visitors to just override this to handle all AncillaryOps
847 /// <param name="op">the AncillaryOp</param>
848 /// <param name="n">the node to process</param>
849 /// <returns>a potentially modified subtree</returns>
850 protected virtual TResultType VisitAncillaryOpDefault(AncillaryOp op, Node n)
852 return VisitDefault(n);
858 /// <param name="op"></param>
859 /// <param name="n"></param>
860 /// <returns></returns>
861 public virtual TResultType Visit(VarDefOp op, Node n)
863 return VisitAncillaryOpDefault(op, n);
869 /// <param name="op"></param>
870 /// <param name="n"></param>
871 /// <returns></returns>
872 public virtual TResultType Visit(VarDefListOp op, Node n)
874 return VisitAncillaryOpDefault(op, n);
879 #region PhysicalOp Visitors
882 /// A default processor for all PhysicalOps.
884 /// Allows new visitors to just override this to handle all PhysicalOps
886 /// <param name="op">the PhysicalOp</param>
887 /// <param name="n">the node to process</param>
888 /// <returns>a potentially modified subtree</returns>
889 protected virtual TResultType VisitPhysicalOpDefault(PhysicalOp op, Node n)
891 return VisitDefault(n);
895 /// PhysicalProjectOp
897 /// <param name="op"></param>
898 /// <param name="n"></param>
899 /// <returns></returns>
900 public virtual TResultType Visit(PhysicalProjectOp op, Node n)
902 return VisitPhysicalOpDefault(op, n);
905 #region NestOp Visitors
908 /// A default processor for all NestOps.
910 /// Allows new visitors to just override this to handle all NestOps
912 /// <param name="op">the NestOp</param>
913 /// <param name="n">the node to process</param>
914 /// <returns>a potentially modified subtree</returns>
915 protected virtual TResultType VisitNestOp(NestBaseOp op, Node n)
917 return VisitPhysicalOpDefault(op, n);
921 /// SingleStreamNestOp
923 /// <param name="op"></param>
924 /// <param name="n"></param>
925 /// <returns></returns>
926 public virtual TResultType Visit(SingleStreamNestOp op, Node n)
928 return VisitNestOp(op, n);
931 /// MultiStreamNestOp
933 /// <param name="op"></param>
934 /// <param name="n"></param>
935 /// <returns></returns>
936 public virtual TResultType Visit(MultiStreamNestOp op, Node n)
938 return VisitNestOp(op, n);
945 #region RelOp Visitors
948 /// A default processor for all RelOps.
950 /// Allows new visitors to just override this to handle all RelOps
952 /// <param name="op">the RelOp</param>
953 /// <param name="n">the node to process</param>
954 /// <returns>a potentially modified subtree</returns>
955 protected virtual TResultType VisitRelOpDefault(RelOp op, Node n)
957 return VisitDefault(n);
960 #region ApplyOp Visitors
963 /// Common handling for all ApplyOps
965 /// <param name="op">the ApplyOp</param>
966 /// <param name="n">the node to process</param>
967 /// <returns>a potentially modified subtree</returns>
968 protected virtual TResultType VisitApplyOp(ApplyBaseOp op, Node n)
970 return VisitRelOpDefault(op, n);
976 /// <param name="op"></param>
977 /// <param name="n"></param>
978 /// <returns></returns>
979 public virtual TResultType Visit(CrossApplyOp op, Node n)
981 return VisitApplyOp(op, n);
987 /// <param name="op"></param>
988 /// <param name="n"></param>
989 /// <returns></returns>
990 public virtual TResultType Visit(OuterApplyOp op, Node n)
992 return VisitApplyOp(op, n);
997 #region JoinOp Visitors
1000 /// A default processor for all JoinOps.
1002 /// Allows new visitors to just override this to handle all JoinOps.
1004 /// <param name="op">the JoinOp</param>
1005 /// <param name="n">the node to process</param>
1006 /// <returns>a potentially modified subtree</returns>
1007 protected virtual TResultType VisitJoinOp(JoinBaseOp op, Node n)
1009 return VisitRelOpDefault(op, n);
1015 /// <param name="op"></param>
1016 /// <param name="n"></param>
1017 /// <returns></returns>
1018 public virtual TResultType Visit(CrossJoinOp op, Node n)
1020 return VisitJoinOp(op, n);
1026 /// <param name="op"></param>
1027 /// <param name="n"></param>
1028 /// <returns></returns>
1029 public virtual TResultType Visit(FullOuterJoinOp op, Node n)
1031 return VisitJoinOp(op, n);
1037 /// <param name="op"></param>
1038 /// <param name="n"></param>
1039 /// <returns></returns>
1040 public virtual TResultType Visit(LeftOuterJoinOp op, Node n)
1042 return VisitJoinOp(op, n);
1048 /// <param name="op"></param>
1049 /// <param name="n"></param>
1050 /// <returns></returns>
1051 public virtual TResultType Visit(InnerJoinOp op, Node n)
1053 return VisitJoinOp(op, n);
1058 #region SetOp Visitors
1061 /// A default processor for all SetOps.
1063 /// Allows new visitors to just override this to handle all SetOps.
1065 /// <param name="op">the SetOp</param>
1066 /// <param name="n">the node to process</param>
1067 /// <returns>a potentially modified subtree</returns>
1068 protected virtual TResultType VisitSetOp(SetOp op, Node n)
1070 return VisitRelOpDefault(op, n);
1076 /// <param name="op"></param>
1077 /// <param name="n"></param>
1078 /// <returns></returns>
1079 public virtual TResultType Visit(ExceptOp op, Node n)
1081 return VisitSetOp(op, n);
1087 /// <param name="op"></param>
1088 /// <param name="n"></param>
1089 /// <returns></returns>
1090 public virtual TResultType Visit(IntersectOp op, Node n)
1092 return VisitSetOp(op, n);
1098 /// <param name="op"></param>
1099 /// <param name="n"></param>
1100 /// <returns></returns>
1101 public virtual TResultType Visit(UnionAllOp op, Node n)
1103 return VisitSetOp(op, n);
1111 /// <param name="op"></param>
1112 /// <param name="n"></param>
1113 /// <returns></returns>
1114 public virtual TResultType Visit(DistinctOp op, Node n)
1116 return VisitRelOpDefault(op, n);
1122 /// <param name="op"></param>
1123 /// <param name="n"></param>
1124 /// <returns></returns>
1125 public virtual TResultType Visit(FilterOp op, Node n)
1127 return VisitRelOpDefault(op, n);
1133 /// <param name="op"></param>
1134 /// <param name="n"></param>
1135 /// <returns></returns>
1136 protected virtual TResultType VisitGroupByOp(GroupByBaseOp op, Node n)
1138 return VisitRelOpDefault(op, n);
1145 /// <param name="op"></param>
1146 /// <param name="n"></param>
1147 /// <returns></returns>
1148 public virtual TResultType Visit(GroupByOp op, Node n)
1150 return VisitGroupByOp(op, n);
1156 /// <param name="op"></param>
1157 /// <param name="n"></param>
1158 /// <returns></returns>
1159 public virtual TResultType Visit(GroupByIntoOp op, Node n)
1161 return VisitGroupByOp(op, n);
1167 /// <param name="op"></param>
1168 /// <param name="n"></param>
1169 /// <returns></returns>
1170 public virtual TResultType Visit(ProjectOp op, Node n)
1172 return VisitRelOpDefault(op, n);
1177 /// Default handler for all TableOps
1179 /// <param name="op"></param>
1180 /// <param name="n"></param>
1181 /// <returns></returns>
1182 protected virtual TResultType VisitTableOp(ScanTableBaseOp op, Node n)
1184 return VisitRelOpDefault(op, n);
1189 /// <param name="op"></param>
1190 /// <param name="n"></param>
1191 /// <returns></returns>
1192 public virtual TResultType Visit(ScanTableOp op, Node n)
1194 return VisitTableOp(op, n);
1200 /// <param name="op"></param>
1201 /// <param name="n"></param>
1202 /// <returns></returns>
1203 public virtual TResultType Visit(ScanViewOp op, Node n)
1205 return VisitTableOp(op, n);
1210 /// Visitor pattern method for SingleRowOp
1212 /// <param name="op">The SingleRowOp being visited</param>
1213 /// <param name="n">The Node that references the Op</param>
1214 /// <returns></returns>
1215 public virtual TResultType Visit(SingleRowOp op, Node n)
1217 return VisitRelOpDefault(op, n);
1221 /// Visitor pattern method for SingleRowTableOp
1223 /// <param name="op">The SingleRowTableOp being visited</param>
1224 /// <param name="n">The Node that references the Op</param>
1225 /// <returns></returns>
1226 public virtual TResultType Visit(SingleRowTableOp op, Node n)
1228 return VisitRelOpDefault(op, n);
1232 /// A default processor for all SortOps.
1234 /// Allows new visitors to just override this to handle ConstrainedSortOp/SortOp.
1236 /// <param name="op">the SetOp</param>
1237 /// <param name="n">the node to process</param>
1238 /// <returns>a potentially modified subtree</returns>
1239 protected virtual TResultType VisitSortOp(SortBaseOp op, Node n)
1241 return VisitRelOpDefault(op, n);
1247 /// <param name="op"></param>
1248 /// <param name="n"></param>
1249 /// <returns></returns>
1250 public virtual TResultType Visit(SortOp op, Node n)
1252 return VisitSortOp(op, n);
1256 /// ConstrainedSortOp
1258 /// <param name="op"></param>
1259 /// <param name="n"></param>
1260 /// <returns></returns>
1261 public virtual TResultType Visit(ConstrainedSortOp op, Node n)
1263 return VisitSortOp(op, n);
1269 /// <param name="op"></param>
1270 /// <param name="n"></param>
1271 /// <returns></returns>
1272 public virtual TResultType Visit(UnnestOp op, Node n)
1274 return VisitRelOpDefault(op, n);
1279 #region ScalarOp Visitors
1282 /// A default processor for all ScalarOps.
1284 /// Allows new visitors to just override this to handle all ScalarOps
1286 /// <param name="op">the ScalarOp</param>
1287 /// <param name="n">the node to process</param>
1288 /// <returns>a potentially new node</returns>
1289 protected virtual TResultType VisitScalarOpDefault(ScalarOp op, Node n)
1291 return VisitDefault(n);
1295 /// Default handler for all constant Ops
1297 /// <param name="op"></param>
1298 /// <param name="n"></param>
1299 /// <returns></returns>
1300 protected virtual TResultType VisitConstantOp(ConstantBaseOp op, Node n)
1302 return VisitScalarOpDefault(op, n);
1308 /// <param name="op"></param>
1309 /// <param name="n"></param>
1310 /// <returns></returns>
1311 public virtual TResultType Visit(AggregateOp op, Node n)
1313 return VisitScalarOpDefault(op, n);
1319 /// <param name="op"></param>
1320 /// <param name="n"></param>
1321 /// <returns></returns>
1322 public virtual TResultType Visit(ArithmeticOp op, Node n)
1324 return VisitScalarOpDefault(op, n);
1330 /// <param name="op"></param>
1331 /// <param name="n"></param>
1332 /// <returns></returns>
1333 public virtual TResultType Visit(CaseOp op, Node n)
1335 return VisitScalarOpDefault(op, n);
1341 /// <param name="op"></param>
1342 /// <param name="n"></param>
1343 /// <returns></returns>
1344 public virtual TResultType Visit(CastOp op, Node n)
1346 return VisitScalarOpDefault(op, n);
1352 /// <param name="op"></param>
1353 /// <param name="n"></param>
1354 /// <returns></returns>
1355 public virtual TResultType Visit(SoftCastOp op, Node n)
1357 return VisitScalarOpDefault(op, n);
1363 /// <param name="op"></param>
1364 /// <param name="n"></param>
1365 /// <returns></returns>
1366 public virtual TResultType Visit(CollectOp op, Node n)
1368 return VisitScalarOpDefault(op, n);
1374 /// <param name="op"></param>
1375 /// <param name="n"></param>
1376 /// <returns></returns>
1377 public virtual TResultType Visit(ComparisonOp op, Node n)
1379 return VisitScalarOpDefault(op, n);
1385 /// <param name="op"></param>
1386 /// <param name="n"></param>
1387 /// <returns></returns>
1388 public virtual TResultType Visit(ConditionalOp op, Node n)
1390 return VisitScalarOpDefault(op, n);
1396 /// <param name="op"></param>
1397 /// <param name="n"></param>
1398 /// <returns></returns>
1399 public virtual TResultType Visit(ConstantOp op, Node n)
1401 return VisitConstantOp(op, n);
1405 /// ConstantPredicateOp
1407 /// <param name="op"></param>
1408 /// <param name="n"></param>
1409 /// <returns></returns>
1410 public virtual TResultType Visit(ConstantPredicateOp op, Node n)
1412 return VisitConstantOp(op, n);
1418 /// <param name="op"></param>
1419 /// <param name="n"></param>
1420 /// <returns></returns>
1421 public virtual TResultType Visit(ElementOp op, Node n)
1423 return VisitScalarOpDefault(op, n);
1429 /// <param name="op"></param>
1430 /// <param name="n"></param>
1431 /// <returns></returns>
1432 public virtual TResultType Visit(ExistsOp op, Node n)
1434 return VisitScalarOpDefault(op, n);
1440 /// <param name="op"></param>
1441 /// <param name="n"></param>
1442 /// <returns></returns>
1443 public virtual TResultType Visit(FunctionOp op, Node n)
1445 return VisitScalarOpDefault(op, n);
1451 /// <param name="op"></param>
1452 /// <param name="n"></param>
1453 /// <returns></returns>
1454 public virtual TResultType Visit(GetEntityRefOp op, Node n)
1456 return VisitScalarOpDefault(op, n);
1462 /// <param name="op"></param>
1463 /// <param name="n"></param>
1464 /// <returns></returns>
1465 public virtual TResultType Visit(GetRefKeyOp op, Node n)
1467 return VisitScalarOpDefault(op, n);
1471 /// InternalConstantOp
1473 /// <param name="op"></param>
1474 /// <param name="n"></param>
1475 /// <returns></returns>
1476 public virtual TResultType Visit(InternalConstantOp op, Node n)
1478 return VisitConstantOp(op, n);
1484 /// <param name="op"></param>
1485 /// <param name="n"></param>
1486 /// <returns></returns>
1487 public virtual TResultType Visit(IsOfOp op, Node n)
1489 return VisitScalarOpDefault(op, n);
1495 /// <param name="op"></param>
1496 /// <param name="n"></param>
1497 /// <returns></returns>
1498 public virtual TResultType Visit(LikeOp op, Node n)
1500 return VisitScalarOpDefault(op, n);
1506 /// <param name="op"></param>
1507 /// <param name="n"></param>
1508 /// <returns></returns>
1509 public virtual TResultType Visit(NewEntityOp op, Node n)
1511 return VisitScalarOpDefault(op, n);
1517 /// <param name="op"></param>
1518 /// <param name="n"></param>
1519 /// <returns></returns>
1520 public virtual TResultType Visit(NewInstanceOp op, Node n)
1522 return VisitScalarOpDefault(op, n);
1526 /// DiscriminatedNewInstanceOp
1528 /// <param name="op"></param>
1529 /// <param name="n"></param>
1530 /// <returns></returns>
1531 public virtual TResultType Visit(DiscriminatedNewEntityOp op, Node n)
1533 return VisitScalarOpDefault(op, n);
1539 /// <param name="op"></param>
1540 /// <param name="n"></param>
1541 /// <returns></returns>
1542 public virtual TResultType Visit(NewMultisetOp op, Node n)
1544 return VisitScalarOpDefault(op, n);
1550 /// <param name="op"></param>
1551 /// <param name="n"></param>
1552 /// <returns></returns>
1553 public virtual TResultType Visit(NewRecordOp op, Node n)
1555 return VisitScalarOpDefault(op, n);
1561 /// <param name="op"></param>
1562 /// <param name="n"></param>
1563 /// <returns></returns>
1564 public virtual TResultType Visit(NullOp op, Node n)
1566 return VisitConstantOp(op, n);
1572 /// <param name="op"></param>
1573 /// <param name="n"></param>
1574 /// <returns></returns>
1575 public virtual TResultType Visit(NullSentinelOp op, Node n)
1577 return VisitConstantOp(op, n);
1583 /// <param name="op"></param>
1584 /// <param name="n"></param>
1585 /// <returns></returns>
1586 public virtual TResultType Visit(PropertyOp op, Node n)
1588 return VisitScalarOpDefault(op, n);
1593 /// <param name="op"></param>
1594 /// <param name="n"></param>
1595 /// <returns></returns>
1596 public virtual TResultType Visit(RelPropertyOp op, Node n)
1598 return VisitScalarOpDefault(op, n);
1604 /// <param name="op"></param>
1605 /// <param name="n"></param>
1606 /// <returns></returns>
1607 public virtual TResultType Visit(RefOp op, Node n)
1609 return VisitScalarOpDefault(op, n);
1615 /// <param name="op"></param>
1616 /// <param name="n"></param>
1617 /// <returns></returns>
1618 public virtual TResultType Visit(TreatOp op, Node n)
1620 return VisitScalarOpDefault(op, n);
1626 /// <param name="op"></param>
1627 /// <param name="n"></param>
1628 /// <returns></returns>
1629 public virtual TResultType Visit(VarRefOp op, Node n)
1631 return VisitScalarOpDefault(op, n);
1634 public virtual TResultType Visit(DerefOp op, Node n)
1636 return VisitScalarOpDefault(op, n);
1638 public virtual TResultType Visit(NavigateOp op, Node n)
1640 return VisitScalarOpDefault(op, n);
1646 /// A visitor implementation that allows subtrees to be modified (in a bottom-up
1649 internal abstract class BasicOpVisitorOfNode : BasicOpVisitorOfT<Node>
1651 #region visitor helpers
1654 /// Simply iterates over all children, and manages any updates
1656 /// <param name="n">The current node</param>
1657 protected override void VisitChildren(Node n)
1659 for (int i = 0; i < n.Children.Count; i++)
1661 n.Children[i] = VisitNode(n.Children[i]);
1666 /// Simply iterates over all children, and manages any updates, but in reverse order
1668 /// <param name="n">The current node</param>
1669 protected override void VisitChildrenReverse(Node n)
1671 for (int i = n.Children.Count - 1; i >= 0; i--)
1673 n.Children[i] = VisitNode(n.Children[i]);
1678 /// A default processor for any node. Visits the children and returns itself unmodified.
1680 /// <param name="n">the node to process</param>
1681 /// <returns>a potentially new node</returns>
1682 protected override Node VisitDefault(Node n)
1690 #region AncillaryOp Visitors
1693 /// A default processor for all AncillaryOps.
1695 /// Allows new visitors to just override this to handle all AncillaryOps
1697 /// <param name="op">the AncillaryOp</param>
1698 /// <param name="n">the node to process</param>
1699 /// <returns>a potentially modified subtree</returns>
1700 protected override Node VisitAncillaryOpDefault(AncillaryOp op, Node n)
1702 return VisitDefault(n);
1707 #region PhysicalOp Visitors
1710 /// A default processor for all PhysicalOps.
1712 /// Allows new visitors to just override this to handle all PhysicalOps
1714 /// <param name="op">the PhysicalOp</param>
1715 /// <param name="n">the node to process</param>
1716 /// <returns>a potentially modified subtree</returns>
1717 protected override Node VisitPhysicalOpDefault(PhysicalOp op, Node n)
1719 return VisitDefault(n);
1724 #region RelOp Visitors
1727 /// A default processor for all RelOps.
1729 /// Allows new visitors to just override this to handle all RelOps
1731 /// <param name="op">the RelOp</param>
1732 /// <param name="n">the node to process</param>
1733 /// <returns>a potentially modified subtree</returns>
1734 protected override Node VisitRelOpDefault(RelOp op, Node n)
1736 return VisitDefault(n);
1740 #region ScalarOp Visitors
1743 /// A default processor for all ScalarOps.
1745 /// Allows new visitors to just override this to handle all ScalarOps
1747 /// <param name="op">the ScalarOp</param>
1748 /// <param name="n">the node to process</param>
1749 /// <returns>a potentially new node</returns>
1750 protected override Node VisitScalarOpDefault(ScalarOp op, Node n)
1752 return VisitDefault(n);