Skip to content

Commit 5baea40

Browse files
authored
fix(deps): Update module github.com/cloudquery/plugin-sdk to v1.21.0 (#6382)
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/cloudquery/plugin-sdk](https://togithub.com/cloudquery/plugin-sdk) | require | minor | `v1.20.0` -> `v1.21.0` | --- ### Release Notes <details> <summary>cloudquery/plugin-sdk</summary> ### [`v1.21.0`](https://togithub.com/cloudquery/plugin-sdk/releases/tag/v1.21.0) [Compare Source](https://togithub.com/cloudquery/plugin-sdk/compare/v1.20.0...v1.21.0) ##### Features - **testing:** Add test for migrations ([#&#8203;574](https://togithub.com/cloudquery/plugin-sdk/issues/574)) ([071a4e5](https://togithub.com/cloudquery/plugin-sdk/commit/071a4e5d4f91110345c69a1b787c4712ee2e7009)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC43Ny4wIiwidXBkYXRlZEluVmVyIjoiMzQuNzcuMCJ9-->
1 parent 876cc16 commit 5baea40

File tree

80 files changed

+134
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+134
-214
lines changed

cli/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cloudquery/cloudquery/cli
33
go 1.19
44

55
require (
6-
github.com/cloudquery/plugin-sdk v1.20.0
6+
github.com/cloudquery/plugin-sdk v1.21.0
77
github.com/getsentry/sentry-go v0.16.0
88
github.com/google/uuid v1.3.0
99
github.com/rs/zerolog v1.28.0

cli/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
github.com/avast/retry-go/v4 v4.3.1 h1:Mtg11F9PdAIMkMiio2RKcYauoVHjl2aB3zQJJlzD4cE=
22
github.com/avast/retry-go/v4 v4.3.1/go.mod h1:rg6XFaiuFYII0Xu3RDbZQkxCofFwruZKW8oEF1jpWiU=
33
github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=
4-
github.com/cloudquery/plugin-sdk v1.20.0 h1:hp6F/TrQWY5qpKDfEgsk2RZyaeynBhMiCj9QdAQuDos=
5-
github.com/cloudquery/plugin-sdk v1.20.0/go.mod h1:teMPyCON3uPdMsHvzpSiOg+IK2sOR5Tf9dYLreoURzI=
4+
github.com/cloudquery/plugin-sdk v1.21.0 h1:Oon4fFeUpc/QNkSwLPaoHcv9EVzcXK/6Y3ZaAcg7VOk=
5+
github.com/cloudquery/plugin-sdk v1.21.0/go.mod h1:teMPyCON3uPdMsHvzpSiOg+IK2sOR5Tf9dYLreoURzI=
66
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
77
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
88
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=

plugins/destination/azblob/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0
77
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.6.1
88
github.com/cloudquery/filetypes v1.0.2
9-
github.com/cloudquery/plugin-sdk v1.20.0
9+
github.com/cloudquery/plugin-sdk v1.19.0
1010
github.com/google/uuid v1.3.0
1111
github.com/rs/zerolog v1.28.0
1212
)

plugins/destination/azblob/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
5252
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5353
github.com/cloudquery/filetypes v1.0.2 h1:UxZ6aoZld2EQZzPgE8JIzmn98V6Px0cmK7rsJy+BoFg=
5454
github.com/cloudquery/filetypes v1.0.2/go.mod h1:d9YllN+dlQNrT/+fFLwdjeXXE3a2Mj9kffO9aMwzOrg=
55-
github.com/cloudquery/plugin-sdk v1.20.0 h1:hp6F/TrQWY5qpKDfEgsk2RZyaeynBhMiCj9QdAQuDos=
56-
github.com/cloudquery/plugin-sdk v1.20.0/go.mod h1:teMPyCON3uPdMsHvzpSiOg+IK2sOR5Tf9dYLreoURzI=
55+
github.com/cloudquery/plugin-sdk v1.19.0 h1:rA2FHLgon5J+VB6tK+w3LLJyegsL/vAkj3Xi9N1Xk1c=
56+
github.com/cloudquery/plugin-sdk v1.19.0/go.mod h1:teMPyCON3uPdMsHvzpSiOg+IK2sOR5Tf9dYLreoURzI=
5757
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
5858
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
5959
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=

plugins/destination/bigquery/client/migrate.go

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,21 @@ func (c *Client) waitForTableToExist(ctx context.Context, client *bigquery.Clien
9696
func (c *Client) waitForSchemaToMatch(ctx context.Context, client *bigquery.Client, table *schema.Table) error {
9797
c.logger.Debug().Str("table", table.Name).Msg("Waiting for schemas to match")
9898
wantSchema := c.bigQuerySchemaForTable(table)
99+
want, err := wantSchema.ToJSONFields()
100+
if err != nil {
101+
return fmt.Errorf("failed to convert schema to JSON: %v", err)
102+
}
99103
for i := 0; i < maxTableChecks; i++ {
100104
md, err := client.Dataset(c.pluginSpec.DatasetID).Table(table.Name).Metadata(ctx)
101105
if err != nil {
102106
return err
103107
}
104-
haveSchema := md.Schema
105-
if schemasMatch(haveSchema, wantSchema) {
106-
c.logger.Debug().Str("table", table.Name).Msg("Schemas match")
108+
got, err := md.Schema.ToJSONFields()
109+
if err != nil {
110+
return fmt.Errorf("failed to convert schema to JSON: %v", err)
111+
}
112+
if string(got) == string(want) {
113+
c.logger.Debug().Str("table", table.Name).Msg("Schemas matched")
107114
return nil
108115
}
109116
c.logger.Debug().Str("table", table.Name).Int("i", i).Msg("Waiting for schemas to match")
@@ -113,78 +120,14 @@ func (c *Client) waitForSchemaToMatch(ctx context.Context, client *bigquery.Clie
113120
}
114121

115122
func (c *Client) autoMigrateTable(ctx context.Context, client *bigquery.Client, table *schema.Table) error {
116-
bqTable := client.Dataset(c.pluginSpec.DatasetID).Table(table.Name)
117-
md, err := bqTable.Metadata(ctx)
118-
if err != nil {
119-
return fmt.Errorf("failed to get table metadata: %w", err)
120-
}
121-
haveSchema := md.Schema
122-
wantSchema := c.bigQuerySchemaForTable(table)
123-
wantSchema, err = mergeSchemas(haveSchema, wantSchema)
124-
if err != nil {
125-
return fmt.Errorf("failed to migrate table schema: %w", err)
126-
}
123+
bqSchema := c.bigQuerySchemaForTable(table)
127124
tm := bigquery.TableMetadataToUpdate{
128125
Name: table.Name,
129126
Description: table.Description,
130-
Schema: wantSchema,
131-
}
132-
_, err = bqTable.Update(ctx, tm, "")
133-
if err != nil {
134-
return fmt.Errorf("failed to update table schema: %w", err)
135-
}
136-
return nil
137-
}
138-
139-
func schemasMatch(haveSchema, wantSchema bigquery.Schema) bool {
140-
// Schemas are considered a match if everything in the want schema is in the have schema,
141-
// and they have the same types.
142-
// We don't mind if there are extra fields in the have schema.
143-
haveMap := make(map[string]*bigquery.FieldSchema)
144-
for _, f := range haveSchema {
145-
haveMap[f.Name] = f
146-
}
147-
for _, wf := range wantSchema {
148-
if hf, ok := haveMap[wf.Name]; !ok {
149-
return false
150-
} else if hf.Type != wf.Type {
151-
return false
152-
}
153-
}
154-
return true
155-
}
156-
157-
// mergeSchemas merges the schema we want with the schema we have, to avoid
158-
// losing any existing data
159-
func mergeSchemas(haveSchema, wantSchema bigquery.Schema) (bigquery.Schema, error) {
160-
haveMap := make(map[string]*bigquery.FieldSchema)
161-
for _, f := range haveSchema {
162-
haveMap[f.Name] = f
163-
}
164-
wantMap := make(map[string]*bigquery.FieldSchema)
165-
for _, f := range wantSchema {
166-
wantMap[f.Name] = f
167-
}
168-
merged := make(bigquery.Schema, 0, len(wantSchema))
169-
// keep everything in the schema we have, as long as the types didn't change
170-
// or an unknown column isn't required
171-
for _, f := range haveSchema {
172-
if want, ok := wantMap[f.Name]; ok {
173-
if want.Type != f.Type {
174-
return nil, fmt.Errorf("field %v changed type from %v to %v", f.Name, f.Type, want.Type)
175-
}
176-
} else if f.Required {
177-
return nil, fmt.Errorf("field %v is required but not in new schema", f.Name)
178-
}
179-
merged = append(merged, f)
180-
}
181-
// add anything new
182-
for _, f := range wantSchema {
183-
if _, ok := haveMap[f.Name]; !ok {
184-
merged = append(merged, f)
185-
}
127+
Schema: bqSchema,
186128
}
187-
return merged, nil
129+
_, err := client.Dataset(c.pluginSpec.DatasetID).Table(table.Name).Update(ctx, tm, "")
130+
return err
188131
}
189132

190133
func (c *Client) createTable(ctx context.Context, client *bigquery.Client, table *schema.Table) error {

plugins/destination/bigquery/client/read.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"database/sql"
66
"fmt"
7-
"strings"
87
"time"
98

109
"cloud.google.com/go/bigquery"
@@ -13,7 +12,7 @@ import (
1312
)
1413

1514
const (
16-
readSQL = "SELECT %s FROM `%s.%s.%s` WHERE `_cq_source_name` = @cq_source_name order by _cq_sync_time asc"
15+
readSQL = "SELECT * FROM `%s.%s.%s` WHERE `_cq_source_name` = @cq_source_name order by _cq_sync_time asc"
1716
)
1817

1918
func (*Client) createResultsArray(table *schema.Table) []bigquery.Value {
@@ -79,12 +78,7 @@ func (*Client) createResultsArray(table *schema.Table) []bigquery.Value {
7978
}
8079

8180
func (c *Client) Read(ctx context.Context, table *schema.Table, sourceName string, res chan<- []any) error {
82-
colNames := make([]string, 0, len(table.Columns))
83-
for _, col := range table.Columns {
84-
colNames = append(colNames, col.Name)
85-
}
86-
cols := "`" + strings.Join(colNames, "`, `") + "`"
87-
stmt := fmt.Sprintf(readSQL, cols, c.pluginSpec.ProjectID, c.pluginSpec.DatasetID, table.Name)
81+
stmt := fmt.Sprintf(readSQL, c.pluginSpec.ProjectID, c.pluginSpec.DatasetID, table.Name)
8882
q := c.client.Query(stmt)
8983
q.Parameters = []bigquery.QueryParameter{
9084
{

plugins/destination/bigquery/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
cloud.google.com/go/bigquery v1.44.0
7-
github.com/cloudquery/plugin-sdk v1.20.0
7+
github.com/cloudquery/plugin-sdk v1.19.0
88
github.com/rs/zerolog v1.28.0
99
golang.org/x/sync v0.1.0
1010
google.golang.org/api v0.103.0

plugins/destination/bigquery/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR
5353
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
5454
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
5555
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
56-
github.com/cloudquery/plugin-sdk v1.20.0 h1:hp6F/TrQWY5qpKDfEgsk2RZyaeynBhMiCj9QdAQuDos=
57-
github.com/cloudquery/plugin-sdk v1.20.0/go.mod h1:teMPyCON3uPdMsHvzpSiOg+IK2sOR5Tf9dYLreoURzI=
56+
github.com/cloudquery/plugin-sdk v1.19.0 h1:rA2FHLgon5J+VB6tK+w3LLJyegsL/vAkj3Xi9N1Xk1c=
57+
github.com/cloudquery/plugin-sdk v1.19.0/go.mod h1:teMPyCON3uPdMsHvzpSiOg+IK2sOR5Tf9dYLreoURzI=
5858
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
5959
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
6060
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=

plugins/destination/file/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/cloudquery/filetypes v1.0.2
7-
github.com/cloudquery/plugin-sdk v1.20.0
7+
github.com/cloudquery/plugin-sdk v1.19.0
88
github.com/google/uuid v1.3.0
99
github.com/rs/zerolog v1.28.0
1010
)

plugins/destination/file/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
4242
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
4343
github.com/cloudquery/filetypes v1.0.2 h1:UxZ6aoZld2EQZzPgE8JIzmn98V6Px0cmK7rsJy+BoFg=
4444
github.com/cloudquery/filetypes v1.0.2/go.mod h1:d9YllN+dlQNrT/+fFLwdjeXXE3a2Mj9kffO9aMwzOrg=
45-
github.com/cloudquery/plugin-sdk v1.20.0 h1:hp6F/TrQWY5qpKDfEgsk2RZyaeynBhMiCj9QdAQuDos=
46-
github.com/cloudquery/plugin-sdk v1.20.0/go.mod h1:teMPyCON3uPdMsHvzpSiOg+IK2sOR5Tf9dYLreoURzI=
45+
github.com/cloudquery/plugin-sdk v1.19.0 h1:rA2FHLgon5J+VB6tK+w3LLJyegsL/vAkj3Xi9N1Xk1c=
46+
github.com/cloudquery/plugin-sdk v1.19.0/go.mod h1:teMPyCON3uPdMsHvzpSiOg+IK2sOR5Tf9dYLreoURzI=
4747
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
4848
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
4949
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=

0 commit comments

Comments
 (0)