-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathsource.go
More file actions
63 lines (51 loc) · 1.84 KB
/
Copy pathsource.go
File metadata and controls
63 lines (51 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package connbigquery
import (
"context"
"errors"
"fmt"
"net/http"
"cloud.google.com/go/storage"
"google.golang.org/api/iterator"
"github.com/PeerDB-io/peerdb/flow/generated/protos"
"github.com/PeerDB-io/peerdb/flow/pkg/common"
)
func (c *BigQueryConnector) ValidateMirrorSource(ctx context.Context, cfg *protos.FlowConnectionConfigsCore) error {
if !cfg.InitialSnapshotOnly || !cfg.DoInitialSnapshot {
return fmt.Errorf("BigQuery source connector only supports initial snapshot flows. CDC is not supported")
}
var missingTables []common.QualifiedTable
for _, tableMapping := range cfg.TableMappings {
dstDatasetTable, err := c.convertToDatasetTable(tableMapping.SourceTableIdentifier)
if err != nil {
return err
}
table := c.client.DatasetInProject(c.projectID, dstDatasetTable.dataset).Table(dstDatasetTable.table)
if _, err := table.Metadata(ctx); err != nil {
if c.isApiErrorWithStatusCode(err, http.StatusNotFound) {
missingTables = append(missingTables, common.QualifiedTable{
Namespace: dstDatasetTable.dataset,
Table: dstDatasetTable.table,
})
continue
}
return fmt.Errorf("failed to get metadata for table %s: %w", tableMapping.DestinationTableIdentifier, err)
}
}
if len(missingTables) > 0 {
return common.NewSourceTablesMissingError(missingTables)
}
if cfg.SnapshotStagingPath == "" {
return fmt.Errorf("snapshot bucket is required for BigQuery source connector")
}
stagingPath, err := parseGCSPath(cfg.SnapshotStagingPath)
if err != nil {
return fmt.Errorf("invalid snapshot bucket: %w", err)
}
bucket := c.storageClient.Bucket(stagingPath.Bucket())
it := bucket.Objects(ctx, &storage.Query{Prefix: stagingPath.QueryPrefix()})
_, err = it.Next()
if err != nil && !errors.Is(err, iterator.Done) {
return fmt.Errorf("failed to access staging bucket: %w", err)
}
return nil
}