vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/concatenate.go (about)

     1  /*
     2  Copyright 2020 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package planbuilder
    18  
    19  import (
    20  	"vitess.io/vitess/go/vt/sqlparser"
    21  	"vitess.io/vitess/go/vt/vterrors"
    22  	"vitess.io/vitess/go/vt/vtgate/engine"
    23  )
    24  
    25  type concatenate struct {
    26  	v3Plan
    27  	lhs, rhs logicalPlan
    28  	order    int
    29  }
    30  
    31  var _ logicalPlan = (*concatenate)(nil)
    32  
    33  func (c *concatenate) Order() int {
    34  	return c.order
    35  }
    36  
    37  func (c *concatenate) ResultColumns() []*resultColumn {
    38  	return c.lhs.ResultColumns()
    39  }
    40  
    41  func (c *concatenate) Reorder(order int) {
    42  	c.lhs.Reorder(order)
    43  	c.rhs.Reorder(c.lhs.Order())
    44  	c.order = c.rhs.Order() + 1
    45  }
    46  
    47  func (c *concatenate) Wireup(plan logicalPlan, jt *jointab) error {
    48  	// TODO systay should we do something different here?
    49  	err := c.lhs.Wireup(plan, jt)
    50  	if err != nil {
    51  		return err
    52  	}
    53  	return c.rhs.Wireup(plan, jt)
    54  }
    55  
    56  func (c *concatenate) SupplyVar(from, to int, col *sqlparser.ColName, varname string) {
    57  	panic("implement me")
    58  }
    59  
    60  func (c *concatenate) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, colNumber int) {
    61  	panic("implement me")
    62  }
    63  
    64  func (c *concatenate) SupplyWeightString(colNumber int, alsoAddToGroupBy bool) (weightcolNumber int, err error) {
    65  	panic("implement me")
    66  }
    67  
    68  func (c *concatenate) Primitive() engine.Primitive {
    69  	lhs := c.lhs.Primitive()
    70  	rhs := c.rhs.Primitive()
    71  
    72  	return engine.NewConcatenate([]engine.Primitive{lhs, rhs}, nil)
    73  }
    74  
    75  // Rewrite implements the logicalPlan interface
    76  func (c *concatenate) Rewrite(inputs ...logicalPlan) error {
    77  	if len(inputs) != 2 {
    78  		return vterrors.VT13001("concatenate: wrong number of inputs")
    79  	}
    80  	c.lhs = inputs[0]
    81  	c.rhs = inputs[1]
    82  	return nil
    83  }
    84  
    85  // Inputs implements the logicalPlan interface
    86  func (c *concatenate) Inputs() []logicalPlan {
    87  	return []logicalPlan{c.lhs, c.rhs}
    88  }