@@ -54,6 +54,12 @@ type (
5454 singleSource struct {
5555 Source ops.Operator
5656 }
57+
58+ singleSourceI interface {
59+ ops.Operator
60+ getSource () ops.Operator
61+ setSource (ops.Operator )
62+ }
5763)
5864
5965func PlanQuery (ctx * plancontext.PlanningContext , selStmt sqlparser.Statement ) (ops.Operator , error ) {
@@ -89,10 +95,18 @@ func (noInputs) Inputs() []ops.Operator {
8995}
9096
9197// Inputs implements the Operator interface
92- func (s singleSource ) Inputs () []ops.Operator {
98+ func (s * singleSource ) Inputs () []ops.Operator {
9399 return []ops.Operator {s .Source }
94100}
95101
102+ func (s * singleSource ) getSource () ops.Operator {
103+ return s .Source
104+ }
105+
106+ func (s * singleSource ) setSource (src ops.Operator ) {
107+ s .Source = src
108+ }
109+
96110// AddColumn implements the Operator interface
97111func (noColumns ) AddColumn (* plancontext.PlanningContext , sqlparser.Expr ) (int , error ) {
98112 return 0 , vterrors .Errorf (vtrpcpb .Code_INTERNAL , "this operator cannot accept columns" )
@@ -102,3 +116,13 @@ func (noColumns) AddColumn(*plancontext.PlanningContext, sqlparser.Expr) (int, e
102116func (noPredicates ) AddPredicate (* plancontext.PlanningContext , sqlparser.Expr ) (ops.Operator , error ) {
103117 return nil , vterrors .Errorf (vtrpcpb .Code_INTERNAL , "this operator cannot accept predicates" )
104118}
119+
120+ // swap takes two operators with a single source and swaps them. the assumption is that the first op provided has the
121+ // second operator as source. this method will the two operators with each other and return the new root.
122+ // this method is used to push one operator underneath the other
123+ func swap (op , src singleSourceI ) ops.Operator {
124+ tmp := src .getSource ()
125+ src .setSource (op )
126+ op .setSource (tmp )
127+ return src
128+ }
0 commit comments