Skip to content

Commit

Permalink
migration bigquerydataset to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoweim committed Nov 8, 2024
1 parent 4fba7df commit 4802096
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 192 deletions.
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apache/arrow/go/v15 v15.0.2 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
Expand Down Expand Up @@ -136,11 +137,13 @@ require (
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gobuffalo/flect v0.2.3 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/flatbuffers v23.5.26+incompatible // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cpy v0.0.0-20211218193943-a9c933c06932 // indirect
github.com/google/gofuzz v1.2.0 // indirect
Expand Down Expand Up @@ -177,6 +180,8 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -200,6 +205,7 @@ require (
github.com/oklog/run v1.0.0 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
Expand All @@ -214,6 +220,7 @@ require (
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
Expand All @@ -224,12 +231,14 @@ require (
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
27 changes: 27 additions & 0 deletions go.sum

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

37 changes: 37 additions & 0 deletions mockgcp/mockbigquery/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,43 @@ func (s *datasetsServer) UpdateDataset(ctx context.Context, req *pb.UpdateDatase
return updated, err
}

func (s *datasetsServer) PatchDataset(ctx context.Context, req *pb.PatchDatasetRequest) (*pb.Dataset, error) {
name, err := s.buildDatasetName(req.GetProjectId(), req.GetDatasetId())
if err != nil {
return nil, err
}

fqn := name.String()

existing := &pb.Dataset{}
if err := s.storage.Get(ctx, fqn, existing); err != nil {
return nil, err
}

now := time.Now()

updated := req.GetDataset()
updated.DatasetReference = existing.DatasetReference

updated.CreationTime = existing.CreationTime
updated.LastModifiedTime = PtrTo(now.UnixMilli())
updated.Id = PtrTo(existing.GetDatasetReference().GetProjectId() + ":" + existing.GetDatasetReference().GetDatasetId())
updated.Kind = PtrTo("bigquery#dataset")
updated.Location = existing.Location
updated.Type = existing.Type
updated.SelfLink = PtrTo("https://bigquery.googleapis.com/bigquery/v2/" + name.String())

sortAccess(updated)

updated.Etag = PtrTo(computeEtag(updated))

if err := s.storage.Update(ctx, fqn, updated); err != nil {
return nil, err
}

return updated, err
}

func (s *datasetsServer) DeleteDataset(ctx context.Context, req *pb.DeleteDatasetRequest) (*empty.Empty, error) {
name, err := s.buildDatasetName(req.GetProjectId(), req.GetDatasetId())
if err != nil {
Expand Down
Loading

0 comments on commit 4802096

Please sign in to comment.