From cf111aa2b7b6961363b7d97c7829610d509a7021 Mon Sep 17 00:00:00 2001 From: Manit Gupta Date: Thu, 7 Nov 2024 13:50:40 +0530 Subject: [PATCH 1/4] Add Expression verification API signature --- accessors/clients/spanner/client/interface.go | 23 +++++++++ accessors/spanner/expression_verify.go | 49 +++++++++++++++++++ internal/convert.go | 21 ++++++++ 3 files changed, 93 insertions(+) create mode 100644 accessors/clients/spanner/client/interface.go create mode 100644 accessors/spanner/expression_verify.go diff --git a/accessors/clients/spanner/client/interface.go b/accessors/clients/spanner/client/interface.go new file mode 100644 index 000000000..451dfbc03 --- /dev/null +++ b/accessors/clients/spanner/client/interface.go @@ -0,0 +1,23 @@ +package spannerclient + +import ( + "context" + + sp "cloud.google.com/go/spanner" +) + + +type SpannerClient interface {} + +// This implements the SpannerClient interface. This is the primary implementation that should be used in all places other than tests. +type SpannerCLientImpl struct { + spannerClient *sp.Client +} + +func NewSpannerClientImpl(ctx context.Context, dbURI string) (*SpannerCLientImpl, error) { + c, err := GetOrCreateClient(ctx, dbURI) + if err != nil { + return nil, err + } + return &SpannerCLientImpl{spannerClient: c}, nil +} \ No newline at end of file diff --git a/accessors/spanner/expression_verify.go b/accessors/spanner/expression_verify.go new file mode 100644 index 000000000..41c5ebf13 --- /dev/null +++ b/accessors/spanner/expression_verify.go @@ -0,0 +1,49 @@ +package spanneraccessor + +import ( + "context" + + spanneradmin "github.com/GoogleCloudPlatform/spanner-migration-tool/accessors/clients/spanner/admin" + spannerclient "github.com/GoogleCloudPlatform/spanner-migration-tool/accessors/clients/spanner/client" + "github.com/GoogleCloudPlatform/spanner-migration-tool/internal" +) + + +type ExpressionVerificationAccessor interface { + //Creates an empty staging database if it does not exist. + CreateStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string) (bool, error) + //Initialize an empty database (or force initializes a non-empty one) with a conv object + InitializeStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string, conv *internal.Conv, force bool) (bool, error) + //Deletes a staging database + DeleteStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string) (bool, error) + //Verifies an expression by making a call to Spanner + VerifyExpression(ctx context.Context, spannerClient spannerclient.SpannerClient, dbURI string, conv *internal.Conv, expressionDetail internal.ExpressionDetail) (internal.VerificationResult) + //Batch API which parallelizes expression verification calls + BatchVerifyExpressions(ctx context.Context, spannerClient spannerclient.SpannerClient, dbURI string, conv *internal.Conv, expressionDetails []internal.ExpressionDetail) (internal.BatchVerificationResult) +} + +type ExpressionVerificationAccessorImpl struct{} + +func (ev *ExpressionVerificationAccessorImpl) CreateStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string) (bool, error) { + return true, nil +} + +func (ev *ExpressionVerificationAccessorImpl) InitializeStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string, conv *internal.Conv, force bool) (bool, error) { + return true, nil +} + +func (ev *ExpressionVerificationAccessorImpl) DeleteStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string) (bool, error) { + return true, nil +} + +func (ev *ExpressionVerificationAccessorImpl) VerifyExpression(ctx context.Context, spannerClient spannerclient.SpannerClient, dbURI string, conv *internal.Conv, expressionDetail internal.ExpressionDetail) (internal.VerificationResult) { + return internal.VerificationResult{} +} + +func (ev *ExpressionVerificationAccessorImpl) BatchVerifyExpressions(ctx context.Context, spannerClient spannerclient.SpannerClient, dbURI string, conv *internal.Conv, expressionDetails []internal.ExpressionDetail) (internal.BatchVerificationResult) { + return internal.BatchVerificationResult{} +} + + + + diff --git a/internal/convert.go b/internal/convert.go index 6b089053d..5ef9bac85 100644 --- a/internal/convert.go +++ b/internal/convert.go @@ -290,6 +290,27 @@ type TableDetails struct { TableName string `json:TableName` } +type ExpressionDetail struct { + ReferenceElement ReferenceElement + Expression string + Type string + Metadata map[string]string +} + +type ReferenceElement struct { + Id string + Name string +} + +type VerificationResult struct { + Result bool + err error +} + +type BatchVerificationResult struct { + VerificationResultList []VerificationResult +} + // MakeConv returns a default-configured Conv. func MakeConv() *Conv { return &Conv{ From 8df7775fd8e1cbce5e60cc1fa85fb6b4cdcba19a Mon Sep 17 00:00:00 2001 From: Manit Gupta Date: Fri, 8 Nov 2024 22:26:48 +0530 Subject: [PATCH 2/4] Update signature --- accessors/spanner/expression_verify.go | 17 +++++++++-------- internal/convert.go | 5 +++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/accessors/spanner/expression_verify.go b/accessors/spanner/expression_verify.go index 41c5ebf13..35ccb3999 100644 --- a/accessors/spanner/expression_verify.go +++ b/accessors/spanner/expression_verify.go @@ -2,24 +2,25 @@ package spanneraccessor import ( "context" + "sync" spanneradmin "github.com/GoogleCloudPlatform/spanner-migration-tool/accessors/clients/spanner/admin" - spannerclient "github.com/GoogleCloudPlatform/spanner-migration-tool/accessors/clients/spanner/client" "github.com/GoogleCloudPlatform/spanner-migration-tool/internal" + "github.com/GoogleCloudPlatform/spanner-migration-tool/sources/common" ) type ExpressionVerificationAccessor interface { - //Creates an empty staging database if it does not exist. + //Creates an empty staging database if it does not exist. CreateStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string) (bool, error) //Initialize an empty database (or force initializes a non-empty one) with a conv object InitializeStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string, conv *internal.Conv, force bool) (bool, error) //Deletes a staging database DeleteStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string) (bool, error) - //Verifies an expression by making a call to Spanner - VerifyExpression(ctx context.Context, spannerClient spannerclient.SpannerClient, dbURI string, conv *internal.Conv, expressionDetail internal.ExpressionDetail) (internal.VerificationResult) + //Internal API which verifies an expression by making a call to Spanner + VerifyExpression(verificationInput internal.VerificationInput, mutex *sync.Mutex) common.TaskResult[internal.VerificationResult] //Batch API which parallelizes expression verification calls - BatchVerifyExpressions(ctx context.Context, spannerClient spannerclient.SpannerClient, dbURI string, conv *internal.Conv, expressionDetails []internal.ExpressionDetail) (internal.BatchVerificationResult) + BatchVerifyExpressions(ctx context.Context, verificationInputList []internal.VerificationInput) internal.BatchVerificationResult } type ExpressionVerificationAccessorImpl struct{} @@ -36,11 +37,11 @@ func (ev *ExpressionVerificationAccessorImpl) DeleteStagingDb(ctx context.Contex return true, nil } -func (ev *ExpressionVerificationAccessorImpl) VerifyExpression(ctx context.Context, spannerClient spannerclient.SpannerClient, dbURI string, conv *internal.Conv, expressionDetail internal.ExpressionDetail) (internal.VerificationResult) { - return internal.VerificationResult{} +func (ev *ExpressionVerificationAccessorImpl) VerifyExpression(verificationInput internal.VerificationInput, mutex *sync.Mutex) common.TaskResult[internal.VerificationResult] { + return common.TaskResult[internal.VerificationResult]{} } -func (ev *ExpressionVerificationAccessorImpl) BatchVerifyExpressions(ctx context.Context, spannerClient spannerclient.SpannerClient, dbURI string, conv *internal.Conv, expressionDetails []internal.ExpressionDetail) (internal.BatchVerificationResult) { +func (ev *ExpressionVerificationAccessorImpl) BatchVerifyExpressions(ctx context.Context, verificationInputList []internal.VerificationInput) (internal.BatchVerificationResult) { return internal.BatchVerificationResult{} } diff --git a/internal/convert.go b/internal/convert.go index 5ef9bac85..b1949ed8a 100644 --- a/internal/convert.go +++ b/internal/convert.go @@ -302,6 +302,11 @@ type ReferenceElement struct { Name string } +type VerificationInput struct { + DbURI string + ExpressionDetail ExpressionDetail +} + type VerificationResult struct { Result bool err error From c66ac096942e72b9fdf93f891a83583d92cba23b Mon Sep 17 00:00:00 2001 From: Manit Gupta Date: Fri, 8 Nov 2024 22:31:24 +0530 Subject: [PATCH 3/4] Add context to VerifyExpression API --- accessors/spanner/expression_verify.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accessors/spanner/expression_verify.go b/accessors/spanner/expression_verify.go index 35ccb3999..1ad0f242a 100644 --- a/accessors/spanner/expression_verify.go +++ b/accessors/spanner/expression_verify.go @@ -18,7 +18,7 @@ type ExpressionVerificationAccessor interface { //Deletes a staging database DeleteStagingDb(ctx context.Context, adminClient spanneradmin.AdminClient, dbURI string) (bool, error) //Internal API which verifies an expression by making a call to Spanner - VerifyExpression(verificationInput internal.VerificationInput, mutex *sync.Mutex) common.TaskResult[internal.VerificationResult] + VerifyExpression(ctx context.Context, verificationInput internal.VerificationInput, mutex *sync.Mutex) common.TaskResult[internal.VerificationResult] //Batch API which parallelizes expression verification calls BatchVerifyExpressions(ctx context.Context, verificationInputList []internal.VerificationInput) internal.BatchVerificationResult } @@ -37,7 +37,7 @@ func (ev *ExpressionVerificationAccessorImpl) DeleteStagingDb(ctx context.Contex return true, nil } -func (ev *ExpressionVerificationAccessorImpl) VerifyExpression(verificationInput internal.VerificationInput, mutex *sync.Mutex) common.TaskResult[internal.VerificationResult] { +func (ev *ExpressionVerificationAccessorImpl) VerifyExpression(ctx context.Context, verificationInput internal.VerificationInput, mutex *sync.Mutex) common.TaskResult[internal.VerificationResult] { return common.TaskResult[internal.VerificationResult]{} } From bebe58d39426410c8a237350bdeb4a7442211a38 Mon Sep 17 00:00:00 2001 From: Manit Gupta Date: Fri, 8 Nov 2024 22:35:15 +0530 Subject: [PATCH 4/4] Remove uneeded interface --- accessors/clients/spanner/client/interface.go | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 accessors/clients/spanner/client/interface.go diff --git a/accessors/clients/spanner/client/interface.go b/accessors/clients/spanner/client/interface.go deleted file mode 100644 index 451dfbc03..000000000 --- a/accessors/clients/spanner/client/interface.go +++ /dev/null @@ -1,23 +0,0 @@ -package spannerclient - -import ( - "context" - - sp "cloud.google.com/go/spanner" -) - - -type SpannerClient interface {} - -// This implements the SpannerClient interface. This is the primary implementation that should be used in all places other than tests. -type SpannerCLientImpl struct { - spannerClient *sp.Client -} - -func NewSpannerClientImpl(ctx context.Context, dbURI string) (*SpannerCLientImpl, error) { - c, err := GetOrCreateClient(ctx, dbURI) - if err != nil { - return nil, err - } - return &SpannerCLientImpl{spannerClient: c}, nil -} \ No newline at end of file