Skip to content

Commit

Permalink
Bump lyx (#444)
Browse files Browse the repository at this point in the history
* Bump lyx

* proper bump

* Bump correct lyx version
  • Loading branch information
reshke committed Jan 24, 2024
1 parent 4bf1957 commit 53775f4
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/lib/pq v1.10.9
github.com/libp2p/go-reuseport v0.4.0
github.com/opentracing/opentracing-go v1.2.0
github.com/pg-sharding/lyx v0.0.0-20240111083355-38b940962fe3
github.com/pg-sharding/lyx v0.0.0-20240124084632-a9f5aa89a6ac
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.31.0
github.com/sevlyar/go-daemon v0.1.6
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pg-sharding/lyx v0.0.0-20240111083355-38b940962fe3 h1:drqKxg58y9R3niC8T4wW6dqziPZnBosuAGC8X/eXLPc=
github.com/pg-sharding/lyx v0.0.0-20240111083355-38b940962fe3/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240119072404-3d559dba6aa8 h1:s8f0Vo257gQvwS++K9RMkxKrgxsdVAXTtc5wJkqHvmg=
github.com/pg-sharding/lyx v0.0.0-20240119072404-3d559dba6aa8/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240123215906-b049786c6ee2 h1:Pja7QaJpBcflHtTUbIEFl/ZGJrk2vOmX6arh1IJwoIU=
github.com/pg-sharding/lyx v0.0.0-20240123215906-b049786c6ee2/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240123223048-f4c8715e77ed h1:NNv0qFDlAFc9/crthqjFqUmYRW5SjGnvkxSiLx6hOwQ=
github.com/pg-sharding/lyx v0.0.0-20240123223048-f4c8715e77ed/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pg-sharding/lyx v0.0.0-20240124084632-a9f5aa89a6ac h1:iJcay9e0ibZYH1Bx/2tLHZsHYj5k5I480VOswOpfeGo=
github.com/pg-sharding/lyx v0.0.0-20240124084632-a9f5aa89a6ac/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
2 changes: 1 addition & 1 deletion router/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestFrontendSimple(t *testing.T) {

qr.EXPECT().Route(gomock.Any(), &lyx.Select{
TargetList: []lyx.Node{
&lyx.AExprConst{Value: "1"},
&lyx.AExprIConst{Value: 1},
},
Where: &lyx.AExprEmpty{},
}, gomock.Any()).Return(routingstate.ShardMatchState{
Expand Down
83 changes: 66 additions & 17 deletions router/qrouter/proxy_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ func NewRoutingMetadataContext(
}

// TODO : unit tests
func (meta *RoutingMetadataContext) RecordConstExpr(resolvedRelation RelationFQN, colname string, expr *lyx.AExprConst) {
func (meta *RoutingMetadataContext) RecordConstExpr(resolvedRelation RelationFQN, colname string, expr string) {
meta.rels[resolvedRelation] = append(meta.rels[resolvedRelation], colname)
if _, ok := meta.exprs[resolvedRelation]; !ok {
meta.exprs[resolvedRelation] = map[string]string{}
}
delete(meta.unparsed_columns, colname)
meta.exprs[resolvedRelation][colname] = expr.Value
meta.exprs[resolvedRelation][colname] = expr
}

// TODO : unit tests
Expand Down Expand Up @@ -191,14 +191,23 @@ func (qr *ProxyQrouter) RouteKeyWithRanges(ctx context.Context, expr lyx.Node, m
spqrlog.Zero.Debug().Str("key", string(meta.params[e.Number-1])).Str("hashed key", string(hashedKey)).Msg("applying hash function on key")

return qr.DeparseKeyWithRangesInternal(ctx, string(hashedKey), meta)
case *lyx.AExprConst:
case *lyx.AExprSConst:
hashedKey, err := hashfunction.ApplyHashFunction([]byte(e.Value), hf)
if err != nil {
return nil, err
}

spqrlog.Zero.Debug().Str("key", e.Value).Str("hashed key", string(hashedKey)).Msg("applying hash function on key")
return qr.DeparseKeyWithRangesInternal(ctx, string(hashedKey), meta)
case *lyx.AExprIConst:
val := fmt.Sprintf("%d", e.Value)
hashedKey, err := hashfunction.ApplyHashFunction([]byte(val), hf)
if err != nil {
return nil, err
}

spqrlog.Zero.Debug().Int("key", e.Value).Str("hashed key", string(hashedKey)).Msg("applying hash function on key")
return qr.DeparseKeyWithRangesInternal(ctx, string(hashedKey), meta)
default:
return nil, ComplexQuery
}
Expand All @@ -224,7 +233,24 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
switch rght := texpr.Right.(type) {
case *lyx.ParamRef:
// ignore
case *lyx.AExprConst:
case *lyx.AExprSConst:
alias, colname := lft.TableAlias, lft.ColName

if !meta.CheckColumnRls(colname) {
spqrlog.Zero.Debug().
Str("colname", colname).
Msg("skip column due no rule mathing")
continue
}

resolvedRelation, err := meta.ResolveRelationByAlias(alias)
if err == nil {
// TBD: postpone routing from here to root of parsing tree
meta.RecordConstExpr(resolvedRelation, colname, rght.Value)
} else {
meta.unparsed_columns[colname] = struct{}{}
}
case *lyx.AExprIConst:
alias, colname := lft.TableAlias, lft.ColName

if !meta.CheckColumnRls(colname) {
Expand All @@ -237,7 +263,8 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
resolvedRelation, err := meta.ResolveRelationByAlias(alias)
if err == nil {
// TBD: postpone routing from here to root of parsing tree
meta.RecordConstExpr(resolvedRelation, colname, rght)
// maybe expimely inefficient. Will be fixed in SPQR-2.0
meta.RecordConstExpr(resolvedRelation, colname, fmt.Sprintf("%d", rght.Value))
} else {
meta.unparsed_columns[colname] = struct{}{}
}
Expand All @@ -246,7 +273,7 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
if len(rght.List) != 0 {
expr := rght.List[0]
switch bexpr := expr.(type) {
case *lyx.AExprConst:
case *lyx.AExprSConst:
alias, colname := lft.TableAlias, lft.ColName

if !meta.CheckColumnRls(colname) {
Expand All @@ -259,7 +286,25 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
resolvedRelation, err := meta.ResolveRelationByAlias(alias)
if err == nil {
// TBD: postpone routing from here to root of parsing tree
meta.RecordConstExpr(resolvedRelation, colname, bexpr)
meta.RecordConstExpr(resolvedRelation, colname, bexpr.Value)
} else {
meta.unparsed_columns[colname] = struct{}{}
}
case *lyx.AExprIConst:
alias, colname := lft.TableAlias, lft.ColName

if !meta.CheckColumnRls(colname) {
spqrlog.Zero.Debug().
Str("colname", colname).
Msg("skip column due no rule mathing")
continue
}

resolvedRelation, err := meta.ResolveRelationByAlias(alias)
if err == nil {
// TBD: postpone routing from here to root of parsing tree
// maybe expimely inefficient. Will be fixed in SPQR-2.0
meta.RecordConstExpr(resolvedRelation, colname, fmt.Sprintf("%d", bexpr.Value))
} else {
meta.unparsed_columns[colname] = struct{}{}
}
Expand All @@ -279,7 +324,7 @@ func (qr *ProxyQrouter) routeByClause(ctx context.Context, expr lyx.Node, meta *
}
case *lyx.ColumnRef:
/* colref = colref case, skip */
case *lyx.AExprConst:
case *lyx.AExprIConst, *lyx.AExprSConst, *lyx.AExprBConst, *lyx.AExprNConst:
/* should not happend */
case *lyx.AExprEmpty:
/*skip*/
Expand Down Expand Up @@ -523,8 +568,6 @@ func (qr *ProxyQrouter) deparseShardingMapping(
Strs("statements", cols).
Msg("deparsed insert statement columns")

meta.ValuesLists = stmt.Values

meta.InsertStmtCols = cols
switch q := stmt.TableRef.(type) {
case *lyx.RangeVar:
Expand All @@ -534,12 +577,17 @@ func (qr *ProxyQrouter) deparseShardingMapping(
}

if selectStmt := stmt.SubSelect; selectStmt != nil {
spqrlog.Zero.Debug().Msg("routing insert stmt on select clause")
_ = qr.DeparseSelectStmt(ctx, selectStmt, meta)
/* try target list */
spqrlog.Zero.Debug().Msg("routing insert stmt on target list")
/* this target list for some insert (...) sharding column */
meta.TargetList = selectStmt.(*lyx.Select).TargetList
switch subS := selectStmt.(type) {
case *lyx.Select:
spqrlog.Zero.Debug().Msg("routing insert stmt on select clause")
_ = qr.DeparseSelectStmt(ctx, subS, meta)
/* try target list */
spqrlog.Zero.Debug().Msg("routing insert stmt on target list")
/* this target list for some insert (...) sharding column */
meta.TargetList = selectStmt.(*lyx.Select).TargetList
case *lyx.ValueClause:
meta.ValuesLists = subS.Values
}
}

return nil
Expand Down Expand Up @@ -760,9 +808,10 @@ func (qr *ProxyQrouter) routeWithRules(ctx context.Context, stmt lyx.Node, sph s
if e.Name == "current_schema" {
any_routable = true
}
case *lyx.AExprConst:
case *lyx.AExprIConst, *lyx.AExprSConst, *lyx.AExprNConst, *lyx.AExprBConst:
// ok
any_routable = true

case *lyx.ColumnRef:
/* Step 1.4.8.2 - SELECT current_schema special case */
if e.ColName == "current_schema" {
Expand Down

0 comments on commit 53775f4

Please sign in to comment.