Skip to content

Commit

Permalink
refactor: remove routeLegacy and use engine.route for both v3 and gen4
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Dec 2, 2021
1 parent af0e7a0 commit 4f40d2a
Show file tree
Hide file tree
Showing 25 changed files with 480 additions and 1,813 deletions.
74 changes: 2 additions & 72 deletions go/vt/vtgate/engine/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 20 additions & 23 deletions go/vt/vtgate/engine/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ type Route struct {
// Vindex specifies the vindex to be used.
Vindex vindexes.SingleColumn

// Values specifies the vindex values to use for routing.
Values []evalengine.Expr
// Value specifies the vindex value to use for routing.
Value RouteValue

// OrderBy specifies the key order for merge sorting. This will be
// set only for scatter queries that need the results to be
Expand Down Expand Up @@ -107,6 +107,16 @@ type Route struct {
noTxNeeded
}

type RouteValue interface {
// ResolveValue allows for retrieval of the value we expose for public consumption
ResolveValue(bindVars map[string]*querypb.BindVariable) (sqltypes.Value, error)

// ResolveList allows for retrieval of the value we expose for public consumption
ResolveList(bindVars map[string]*querypb.BindVariable) ([]sqltypes.Value, error)

MarshalJSON() ([]byte, error)
}

// NewSimpleRoute creates a Route with the bare minimum of parameters.
func NewSimpleRoute(opcode RouteOpcode, keyspace *vindexes.Keyspace) *Route {
return &Route{
Expand Down Expand Up @@ -589,14 +599,11 @@ func (route *Route) paramsAnyShard(vcursor VCursor, bindVars map[string]*querypb
}

func (route *Route) paramsSelectEqual(vcursor VCursor, bindVars map[string]*querypb.BindVariable) ([]*srvtopo.ResolvedShard, []map[string]*querypb.BindVariable, error) {
env := &evalengine.ExpressionEnv{
BindVars: bindVars,
}
value, err := route.Values[0].Evaluate(env)
value, err := route.Value.ResolveValue(bindVars)
if err != nil {
return nil, nil, err
}
rss, _, err := resolveShards(vcursor, route.Vindex, route.Keyspace, []sqltypes.Value{value.Value()})
rss, _, err := resolveShards(vcursor, route.Vindex, route.Keyspace, []sqltypes.Value{value})
if err != nil {
return nil, nil, err
}
Expand All @@ -608,29 +615,23 @@ func (route *Route) paramsSelectEqual(vcursor VCursor, bindVars map[string]*quer
}

func (route *Route) paramsSelectIn(vcursor VCursor, bindVars map[string]*querypb.BindVariable) ([]*srvtopo.ResolvedShard, []map[string]*querypb.BindVariable, error) {
env := &evalengine.ExpressionEnv{
BindVars: bindVars,
}
value, err := route.Values[0].Evaluate(env)
value, err := route.Value.ResolveList(bindVars)
if err != nil {
return nil, nil, err
}
rss, values, err := resolveShards(vcursor, route.Vindex, route.Keyspace, value.TupleValues())
rss, values, err := resolveShards(vcursor, route.Vindex, route.Keyspace, value)
if err != nil {
return nil, nil, err
}
return rss, shardVars(bindVars, values), nil
}

func (route *Route) paramsSelectMultiEqual(vcursor VCursor, bindVars map[string]*querypb.BindVariable) ([]*srvtopo.ResolvedShard, []map[string]*querypb.BindVariable, error) {
env := &evalengine.ExpressionEnv{
BindVars: bindVars,
}
key, err := route.Values[0].Evaluate(env)
value, err := route.Value.ResolveList(bindVars)
if err != nil {
return nil, nil, err
}
rss, _, err := resolveShards(vcursor, route.Vindex, route.Keyspace, key.TupleValues())
rss, _, err := resolveShards(vcursor, route.Vindex, route.Keyspace, value)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -805,12 +806,8 @@ func (route *Route) description() PrimitiveDescription {
if route.Vindex != nil {
other["Vindex"] = route.Vindex.String()
}
if len(route.Values) > 0 {
var values []string
for _, value := range route.Values {
values = append(values, evalengine.FormatExpr(value))
}
other["Values"] = values
if route.Value != nil {
other["Values"] = route.Value
}
if len(route.SysTableTableSchema) != 0 {
sysTabSchema := "["
Expand Down
Loading

0 comments on commit 4f40d2a

Please sign in to comment.