Skip to content

Commit

Permalink
Rename lookup to lookupVindex for better readability
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <[email protected]>
  • Loading branch information
beingnoble03 committed Dec 18, 2024
1 parent 919bfe4 commit f0a04ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,16 @@ import (
)

// lookup is responsible for performing actions related to lookup vindexes.
type lookup struct {
type lookupVindex struct {
ts *topo.Server
tmc tmclient.TabletManagerClient

logger logutil.Logger
parser *sqlparser.Parser
}

// prepareCreateLookup performs the preparatory steps for creating a
// Lookup Vindex.
func (l *lookup) prepareCreateLookup(ctx context.Context, workflow, keyspace string, specs *vschemapb.Keyspace, continueAfterCopyWithOwner bool) (
// prepareCreate performs the preparatory steps for creating a Lookup Vindex.
func (l *lookupVindex) prepareCreate(ctx context.Context, workflow, keyspace string, specs *vschemapb.Keyspace, continueAfterCopyWithOwner bool) (
ms *vtctldatapb.MaterializeSettings, sourceVSchema, targetVSchema *vschemapb.Keyspace, cancelFunc func() error, err error) {
var (
// sourceVSchemaTable is the table info present in the vschema.
Expand Down Expand Up @@ -242,7 +241,7 @@ type vindexInfo struct {
}

// validateAndGetVindex validates and extracts vindex configuration
func (l *lookup) validateAndGetVindex(specs *vschemapb.Keyspace) (*vschemapb.Vindex, *vindexInfo, error) {
func (l *lookupVindex) validateAndGetVindex(specs *vschemapb.Keyspace) (*vschemapb.Vindex, *vindexInfo, error) {
if specs == nil {
return nil, nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "no vindex provided")
}
Expand Down Expand Up @@ -314,7 +313,7 @@ func (l *lookup) validateAndGetVindex(specs *vschemapb.Keyspace) (*vschemapb.Vin
}, nil
}

func (l *lookup) getTargetAndSourceVSchema(ctx context.Context, sourceKeyspace string, targetKeyspace string) (sourceVSchema *vschemapb.Keyspace, targetVSchema *vschemapb.Keyspace, err error) {
func (l *lookupVindex) getTargetAndSourceVSchema(ctx context.Context, sourceKeyspace string, targetKeyspace string) (sourceVSchema *vschemapb.Keyspace, targetVSchema *vschemapb.Keyspace, err error) {
sourceVSchema, err = l.ts.GetVSchema(ctx, sourceKeyspace)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -375,7 +374,7 @@ func getSourceTable(specs *vschemapb.Keyspace, targetTableName string, fromCols
return sourceTable, sourceTableName, nil
}

func (l *lookup) generateCreateDDLStatement(tableSchema *tabletmanagerdatapb.SchemaDefinition, sourceVindexColumns []string, vInfo *vindexInfo, vindex *vschemapb.Vindex) (string, error) {
func (l *lookupVindex) generateCreateDDLStatement(tableSchema *tabletmanagerdatapb.SchemaDefinition, sourceVindexColumns []string, vInfo *vindexInfo, vindex *vschemapb.Vindex) (string, error) {
lines := strings.Split(tableSchema.TableDefinitions[0].Schema, "\n")
if len(lines) < 3 {
// Should never happen.
Expand Down
30 changes: 15 additions & 15 deletions go/vt/vtctl/workflow/materializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1515,13 +1515,13 @@ func TestCreateLookupVindexCreateDDL(t *testing.T) {
setStartingVschema()
}()
}
l := &lookup{
lv := &lookupVindex{
ts: env.ws.ts,
tmc: env.ws.tmc,
logger: env.ws.Logger(),
parser: env.ws.SQLParser(),
}
outms, _, _, cancelFunc, err := l.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, tcase.specs, false)
outms, _, _, cancelFunc, err := lv.prepareCreate(ctx, "workflow", ms.SourceKeyspace, tcase.specs, false)
if tcase.err != "" {
require.Error(t, err)
require.Contains(t, err.Error(), tcase.err, "prepareCreateLookup(%s) err: %v, does not contain %v", tcase.description, err, tcase.err)
Expand Down Expand Up @@ -1769,13 +1769,13 @@ func TestCreateLookupVindexSourceVSchema(t *testing.T) {
t.Fatal(err)
}

l := &lookup{
lv := &lookupVindex{
ts: env.ws.ts,
tmc: env.ws.tmc,
logger: env.ws.Logger(),
parser: env.ws.SQLParser(),
}
_, got, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, specs, false)
_, got, _, _, err := lv.prepareCreate(ctx, "workflow", ms.SourceKeyspace, specs, false)
require.NoError(t, err)
if !proto.Equal(got, tcase.out) {
t.Errorf("%s: got:\n%v, want\n%v", tcase.description, got, tcase.out)
Expand Down Expand Up @@ -2011,13 +2011,13 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) {
t.Fatal(err)
}

l := &lookup{
lv := &lookupVindex{
ts: env.ws.ts,
tmc: env.ws.tmc,
logger: env.ws.Logger(),
parser: env.ws.SQLParser(),
}
_, _, got, cancelFunc, err := l.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, specs, false)
_, _, got, cancelFunc, err := lv.prepareCreate(ctx, "workflow", ms.SourceKeyspace, specs, false)
if tcase.err != "" {
if err == nil || !strings.Contains(err.Error(), tcase.err) {
t.Errorf("prepareCreateLookup(%s) err: %v, must contain %v", tcase.description, err, tcase.err)
Expand Down Expand Up @@ -2139,13 +2139,13 @@ func TestCreateLookupVindexSameKeyspace(t *testing.T) {
t.Fatal(err)
}

l := &lookup{
lv := &lookupVindex{
ts: env.ws.ts,
tmc: env.ws.tmc,
logger: env.ws.Logger(),
parser: env.ws.SQLParser(),
}
_, got, _, _, err := l.prepareCreateLookup(ctx, "keyspace", ms.TargetKeyspace, specs, false)
_, got, _, _, err := lv.prepareCreate(ctx, "keyspace", ms.TargetKeyspace, specs, false)
require.NoError(t, err)
if !proto.Equal(got, want) {
t.Errorf("same keyspace: got:\n%v, want\n%v", got, want)
Expand Down Expand Up @@ -2271,13 +2271,13 @@ func TestCreateCustomizedVindex(t *testing.T) {
t.Fatal(err)
}

l := &lookup{
lv := &lookupVindex{
ts: env.ws.ts,
tmc: env.ws.tmc,
logger: env.ws.Logger(),
parser: env.ws.SQLParser(),
}
_, got, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.TargetKeyspace, specs, false)
_, got, _, _, err := lv.prepareCreate(ctx, "workflow", ms.TargetKeyspace, specs, false)
require.NoError(t, err)
if !proto.Equal(got, want) {
t.Errorf("customize create lookup error same: got:\n%v, want\n%v", got, want)
Expand Down Expand Up @@ -2395,13 +2395,13 @@ func TestCreateLookupVindexIgnoreNulls(t *testing.T) {
t.Fatal(err)
}

l := &lookup{
lv := &lookupVindex{
ts: env.ws.ts,
tmc: env.ws.tmc,
logger: env.ws.Logger(),
parser: env.ws.SQLParser(),
}
ms, ks, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.TargetKeyspace, specs, false)
ms, ks, _, _, err := lv.prepareCreate(ctx, "workflow", ms.TargetKeyspace, specs, false)
require.NoError(t, err)
if !proto.Equal(wantKs, ks) {
t.Errorf("unexpected keyspace value: got:\n%v, want\n%v", ks, wantKs)
Expand Down Expand Up @@ -2481,17 +2481,17 @@ func TestStopAfterCopyFlag(t *testing.T) {
t.Fatal(err)
}

l := &lookup{
lv := &lookupVindex{
ts: env.ws.ts,
tmc: env.ws.tmc,
logger: env.ws.Logger(),
parser: env.ws.SQLParser(),
}
ms1, _, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.TargetKeyspace, specs, false)
ms1, _, _, _, err := lv.prepareCreate(ctx, "workflow", ms.TargetKeyspace, specs, false)
require.NoError(t, err)
require.Equal(t, ms1.StopAfterCopy, true)

ms2, _, _, _, err := l.prepareCreateLookup(ctx, "workflow", ms.TargetKeyspace, specs, true)
ms2, _, _, _, err := lv.prepareCreate(ctx, "workflow", ms.TargetKeyspace, specs, true)
require.NoError(t, err)
require.Equal(t, ms2.StopAfterCopy, false)
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,13 @@ func (s *Server) LookupVindexCreate(ctx context.Context, req *vtctldatapb.Lookup
span.Annotate("cells", req.Cells)
span.Annotate("tablet_types", req.TabletTypes)

l := &lookup{
lv := &lookupVindex{
ts: s.ts,
tmc: s.tmc,
logger: s.Logger(),
parser: s.SQLParser(),
}
ms, sourceVSchema, targetVSchema, cancelFunc, err := l.prepareCreateLookup(ctx, req.Workflow, req.Keyspace, req.Vindex, req.ContinueAfterCopyWithOwner)
ms, sourceVSchema, targetVSchema, cancelFunc, err := lv.prepareCreate(ctx, req.Workflow, req.Keyspace, req.Vindex, req.ContinueAfterCopyWithOwner)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f0a04ec

Please sign in to comment.