Skip to content

Commit 86a5b18

Browse files
authored
Merge pull request #743 from k1LoW/fix-lint-warn
2 parents ef9332c + 7beb84f commit 86a5b18

File tree

6 files changed

+87
-42
lines changed

6 files changed

+87
-42
lines changed

datasource/aws.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"os"
88
"strings"
99

10-
"github.com/aws/aws-sdk-go/aws"
11-
"github.com/aws/aws-sdk-go/aws/session"
12-
"github.com/aws/aws-sdk-go/service/dynamodb"
10+
"github.com/aws/aws-sdk-go-v2/aws"
11+
"github.com/aws/aws-sdk-go-v2/config"
12+
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
1313
"github.com/k1LoW/tbls/drivers/dynamo"
1414
"github.com/k1LoW/tbls/schema"
1515
)
@@ -30,16 +30,16 @@ func AnalyzeDynamodb(urlstr string) (*schema.Schema, error) {
3030

3131
region := u.Host
3232

33-
sess := session.Must(session.NewSessionWithOptions(session.Options{
34-
SharedConfigState: session.SharedConfigEnable,
35-
}))
33+
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
34+
if err != nil {
35+
return s, err
36+
}
3637

37-
config := aws.NewConfig().WithRegion(region)
3838
if os.Getenv("AWS_ENDPOINT_URL") != "" {
39-
config = config.WithEndpoint(os.Getenv("AWS_ENDPOINT_URL"))
39+
cfg.BaseEndpoint = aws.String(os.Getenv("AWS_ENDPOINT_URL"))
4040
}
4141

42-
client := dynamodb.New(sess, config)
42+
client := dynamodb.NewFromConfig(cfg)
4343
ctx := context.Background()
4444

4545
driver, err := dynamo.New(ctx, client)

drivers/databricks/databricks.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88

99
"github.com/k1LoW/errors"
1010
"github.com/k1LoW/tbls/schema"
11-
12-
_ "github.com/databricks/databricks-sql-go"
1311
)
1412

1513
type Databricks struct {

drivers/dynamo/dynamo.go

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,45 @@ package dynamo
33
import (
44
"context"
55
"fmt"
6-
"regexp"
76

8-
"github.com/aws/aws-sdk-go/service/dynamodb"
7+
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
8+
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
99
"github.com/k1LoW/errors"
1010
"github.com/k1LoW/tbls/dict"
1111
"github.com/k1LoW/tbls/schema"
1212
)
1313

14-
var re = regexp.MustCompile(`(?s)\n\s*`)
14+
// formatKeySchema formats KeySchemaElement slice to expected string format.
15+
func formatKeySchema(keySchema []types.KeySchemaElement) string {
16+
if len(keySchema) == 0 {
17+
return "[]"
18+
}
19+
20+
result := "["
21+
for i, k := range keySchema {
22+
if i > 0 {
23+
result += " "
24+
}
25+
result += fmt.Sprintf("{ AttributeName: \"%s\", KeyType: \"%s\" }", *k.AttributeName, string(k.KeyType))
26+
}
27+
result += "]"
28+
return result
29+
}
30+
31+
// formatProjection formats Projection to expected string format.
32+
func formatProjection(projection *types.Projection) string {
33+
if projection == nil {
34+
return "{ ProjectionType: \"\" }"
35+
}
36+
return fmt.Sprintf("{ ProjectionType: \"%s\" }", string(projection.ProjectionType))
37+
}
1538

1639
type Dynamodb struct {
1740
ctx context.Context
18-
client *dynamodb.DynamoDB
41+
client *dynamodb.Client
1942
}
2043

21-
func New(ctx context.Context, client *dynamodb.DynamoDB) (*Dynamodb, error) {
44+
func New(ctx context.Context, client *dynamodb.Client) (*Dynamodb, error) {
2245
return &Dynamodb{
2346
ctx: ctx,
2447
client: client,
@@ -38,16 +61,16 @@ func (d *Dynamodb) Analyze(s *schema.Schema) error {
3861
tables := []*schema.Table{}
3962
tableType := "BASIC TABLE"
4063
for {
41-
list, err := d.client.ListTablesWithContext(d.ctx, input)
64+
list, err := d.client.ListTables(d.ctx, input)
4265
if err != nil {
4366
return err
4467
}
4568

4669
for _, t := range list.TableNames {
4770
input := &dynamodb.DescribeTableInput{
48-
TableName: t,
71+
TableName: &t,
4972
}
50-
desc, err := d.client.DescribeTableWithContext(d.ctx, input)
73+
desc, err := d.client.DescribeTable(d.ctx, input)
5174
if err != nil {
5275
return err
5376
}
@@ -73,28 +96,28 @@ func (d *Dynamodb) Analyze(s *schema.Schema) error {
7396
return nil
7497
}
7598

76-
func listColumns(td *dynamodb.TableDescription) []*schema.Column {
99+
func listColumns(td *types.TableDescription) []*schema.Column {
77100
columns := []*schema.Column{}
78101
for _, ad := range td.AttributeDefinitions {
79102
column := &schema.Column{
80103
Name: *ad.AttributeName,
81-
Type: *ad.AttributeType,
104+
Type: string(ad.AttributeType),
82105
Nullable: false,
83106
}
84107
columns = append(columns, column)
85108
}
86109
return columns
87110
}
88111

89-
func listConstraints(td *dynamodb.TableDescription) []*schema.Constraint {
112+
func listConstraints(td *types.TableDescription) []*schema.Constraint {
90113
constraints := []*schema.Constraint{}
91114
switch {
92115
case len(td.KeySchema) == 2:
93116
columns := []string{}
94117
for _, k := range td.KeySchema {
95118
columns = append(columns, *k.AttributeName)
96119
}
97-
def := re.ReplaceAllString(fmt.Sprintf("%v", td.KeySchema), " ")
120+
def := formatKeySchema(td.KeySchema)
98121
constraint := &schema.Constraint{
99122
Name: "Primary Key",
100123
Type: "Partition key and sort key",
@@ -107,7 +130,7 @@ func listConstraints(td *dynamodb.TableDescription) []*schema.Constraint {
107130
for _, k := range td.KeySchema {
108131
columns = append(columns, *k.AttributeName)
109132
}
110-
def := re.ReplaceAllString(fmt.Sprintf("%v", td.KeySchema), " ")
133+
def := formatKeySchema(td.KeySchema)
111134
constraint := &schema.Constraint{
112135
Name: "Primary Key",
113136
Type: "Partition key",
@@ -119,18 +142,18 @@ func listConstraints(td *dynamodb.TableDescription) []*schema.Constraint {
119142
return constraints
120143
}
121144

122-
func listIndexes(td *dynamodb.TableDescription) []*schema.Index {
145+
func listIndexes(td *types.TableDescription) []*schema.Index {
123146
indexes := []*schema.Index{}
124147
for _, lsi := range td.LocalSecondaryIndexes {
125-
def := re.ReplaceAllString(fmt.Sprintf("LocalSecondaryIndex { %s, %s }", lsi.KeySchema, lsi.Projection.String()), " ")
148+
def := fmt.Sprintf("LocalSecondaryIndex { %s, %s }", formatKeySchema(lsi.KeySchema), formatProjection(lsi.Projection))
126149
Index := &schema.Index{
127150
Name: *lsi.IndexName,
128151
Def: def,
129152
}
130153
indexes = append(indexes, Index)
131154
}
132155
for _, gsi := range td.GlobalSecondaryIndexes {
133-
def := re.ReplaceAllString(fmt.Sprintf("GlobalSecondaryIndex { %s, %s }", gsi.KeySchema, gsi.Projection.String()), " ")
156+
def := fmt.Sprintf("GlobalSecondaryIndex { %s, %s }", formatKeySchema(gsi.KeySchema), formatProjection(gsi.Projection))
134157
Index := &schema.Index{
135158
Name: *gsi.IndexName,
136159
Def: def,

drivers/dynamo/dynamo_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"fmt"
88
"testing"
99

10-
"github.com/aws/aws-sdk-go/aws"
11-
"github.com/aws/aws-sdk-go/aws/session"
12-
"github.com/aws/aws-sdk-go/service/dynamodb"
10+
"github.com/aws/aws-sdk-go-v2/aws"
11+
"github.com/aws/aws-sdk-go-v2/config"
12+
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
1313
"github.com/k1LoW/tbls/schema"
1414
)
1515

1616
var region = "ap-northeast-1"
1717
var ctx context.Context
18-
var client *dynamodb.DynamoDB
18+
var client *dynamodb.Client
1919

2020
func TestAnalyze(t *testing.T) {
2121
ctx, client := initClient(t)
@@ -40,12 +40,20 @@ func TestAnalyze(t *testing.T) {
4040
}
4141
}
4242

43-
func initClient(t *testing.T) (context.Context, *dynamodb.DynamoDB) {
44-
sess := session.Must(session.NewSessionWithOptions(session.Options{
45-
SharedConfigState: session.SharedConfigEnable,
46-
}))
47-
config := aws.NewConfig().WithRegion(region).WithEndpoint("http://localhost:18000")
48-
client = dynamodb.New(sess, config)
43+
func initClient(t *testing.T) (context.Context, *dynamodb.Client) {
44+
cfg, err := config.LoadDefaultConfig(context.TODO(),
45+
config.WithRegion(region),
46+
config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
47+
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
48+
return aws.Endpoint{
49+
URL: "http://localhost:18000",
50+
}, nil
51+
})),
52+
)
53+
if err != nil {
54+
t.Fatalf("unable to load SDK config, %v", err)
55+
}
56+
client = dynamodb.NewFromConfig(cfg)
4957
ctx = context.Background()
5058
return ctx, client
5159
}

go.mod

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,27 @@ require (
6868
github.com/apache/arrow/go/v12 v12.0.1 // indirect
6969
github.com/apache/arrow/go/v15 v15.0.2 // indirect
7070
github.com/apache/thrift v0.21.0 // indirect
71-
github.com/aws/aws-sdk-go-v2 v1.32.7 // indirect
71+
github.com/aws/aws-sdk-go-v2 v1.39.0 // indirect
7272
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
7373
github.com/aws/aws-sdk-go-v2/config v1.28.7 // indirect
7474
github.com/aws/aws-sdk-go-v2/credentials v1.17.48 // indirect
7575
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.22 // indirect
7676
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.44 // indirect
77-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 // indirect
78-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 // indirect
77+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.7 // indirect
78+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.7 // indirect
7979
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
8080
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.26 // indirect
81-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
81+
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.50.3 // indirect
82+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1 // indirect
8283
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.7 // indirect
84+
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.7 // indirect
8385
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.7 // indirect
8486
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7 // indirect
8587
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1 // indirect
8688
github.com/aws/aws-sdk-go-v2/service/sso v1.24.8 // indirect
8789
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.7 // indirect
8890
github.com/aws/aws-sdk-go-v2/service/sts v1.33.3 // indirect
89-
github.com/aws/smithy-go v1.22.1 // indirect
91+
github.com/aws/smithy-go v1.23.0 // indirect
9092
github.com/bradleyfalzon/ghinstallation/v2 v2.16.0 // indirect
9193
github.com/buildkite/interpolate v0.1.5 // indirect
9294
github.com/cespare/xxhash/v2 v2.3.0 // indirect

go.sum

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ github.com/aws/aws-sdk-go v1.55.8 h1:JRmEUbU52aJQZ2AjX4q4Wu7t4uZjOu71uyNmaWlUkJQ
685685
github.com/aws/aws-sdk-go v1.55.8/go.mod h1:ZkViS9AqA6otK+JBBNH2++sx1sgxrPKcSzPPvQkUtXk=
686686
github.com/aws/aws-sdk-go-v2 v1.32.7 h1:ky5o35oENWi0JYWUZkB7WYvVPP+bcRF5/Iq7JWSb5Rw=
687687
github.com/aws/aws-sdk-go-v2 v1.32.7/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U=
688+
github.com/aws/aws-sdk-go-v2 v1.39.0 h1:xm5WV/2L4emMRmMjHFykqiA4M/ra0DJVSWUkDyBjbg4=
689+
github.com/aws/aws-sdk-go-v2 v1.39.0/go.mod h1:sDioUELIUO9Znk23YVmIk86/9DOpkbyyVb1i/gUNFXY=
688690
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 h1:lL7IfaFzngfx0ZwUGOZdsFFnQ5uLvR0hWqqhyE7Q9M8=
689691
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7/go.mod h1:QraP0UcVlQJsmHfioCrveWOC1nbiWUl3ej08h4mXWoc=
690692
github.com/aws/aws-sdk-go-v2/config v1.28.7 h1:GduUnoTXlhkgnxTD93g1nv4tVPILbdNQOzav+Wpg7AE=
@@ -697,16 +699,26 @@ github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.44 h1:2zxMLXLedpB4K1ilbJFx
697699
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.44/go.mod h1:VuLHdqwjSvgftNC7yqPWyGVhEwPmJpeRi07gOgOfHF8=
698700
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26 h1:I/5wmGMffY4happ8NOCuIUEWGUvvFp5NSeQcXl9RHcI=
699701
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.26/go.mod h1:FR8f4turZtNy6baO0KJ5FJUmXH/cSkI9fOngs0yl6mA=
702+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.7 h1:UCxq0X9O3xrlENdKf1r9eRJoKz/b0AfGkpp3a7FPlhg=
703+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.7/go.mod h1:rHRoJUNUASj5Z/0eqI4w32vKvC7atoWR0jC+IkmVH8k=
700704
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26 h1:zXFLuEuMMUOvEARXFUVJdfqZ4bvvSgdGRq/ATcrQxzM=
701705
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.26/go.mod h1:3o2Wpy0bogG1kyOPrgkXA8pgIfEEv0+m19O9D5+W8y8=
706+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.7 h1:Y6DTZUn7ZUC4th9FMBbo8LVE+1fyq3ofw+tRwkUd3PY=
707+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.7/go.mod h1:x3XE6vMnU9QvHN/Wrx2s44kwzV2o2g5x/siw4ZUJ9g8=
702708
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
703709
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
704710
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.26 h1:GeNJsIFHB+WW5ap2Tec4K6dzcVTsRbsT1Lra46Hv9ME=
705711
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.26/go.mod h1:zfgMpwHDXX2WGoG84xG2H+ZlPTkJUU4YUvx2svLQYWo=
712+
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.50.3 h1:fbhq/XgBDNAVreNMY8E7JWxlqeHH8O3UAunPvV9XY5A=
713+
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.50.3/go.mod h1:lXFSTFpnhgc8Qb/meseIt7+UXPiidZm0DbiDqmPHBTQ=
706714
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 h1:iXtILhvDxB6kPvEXgsDhGaZCSC6LQET5ZHSdJozeI0Y=
707715
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1/go.mod h1:9nu0fVANtYiAePIBh2/pFUSwtJ402hLnp854CNoDOeE=
716+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1 h1:oegbebPEMA/1Jny7kvwejowCaHz1FWZAQ94WXFNCyTM=
717+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1/go.mod h1:kemo5Myr9ac0U9JfSjMo9yHLtw+pECEHsFtJ9tqCEI8=
708718
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.7 h1:tB4tNw83KcajNAzaIMhkhVI2Nt8fAZd5A5ro113FEMY=
709719
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.7/go.mod h1:lvpyBGkZ3tZ9iSsUIcC2EWp+0ywa7aK3BLT+FwZi+mQ=
720+
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.7 h1:VN9u746Erhm6xnVSmaUd1Saxs1MVZVum6v2yPOqj8xQ=
721+
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.7/go.mod h1:j0BhJWTdVsYsllEfO0E8EXtLToU8U7QeA7Gztxrl/8g=
710722
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.7 h1:8eUsivBQzZHqe/3FE+cqwfH+0p5Jo8PFM/QYQSmeZ+M=
711723
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.7/go.mod h1:kLPQvGUmxn/fqiCrDeohwG33bq2pQpGeY62yRO6Nrh0=
712724
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7 h1:Hi0KGbrnr57bEHWM0bJ1QcBzxLrL/k2DHvGYhb8+W1w=
@@ -721,6 +733,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.33.3 h1:Xgv/hyNgvLda/M9l9qxXc4UFSgpp
721733
github.com/aws/aws-sdk-go-v2/service/sts v1.33.3/go.mod h1:5Gn+d+VaaRgsjewpMvGazt0WfcFO+Md4wLOuBfGR9Bc=
722734
github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro=
723735
github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
736+
github.com/aws/smithy-go v1.23.0 h1:8n6I3gXzWJB2DxBDnfxgBaSX6oe0d/t10qGz7OKqMCE=
737+
github.com/aws/smithy-go v1.23.0/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
724738
github.com/beta/freetype v0.0.1 h1:/t8b5+N9FlAMOF0d1aZPa83oufB2dU/YDqA0cq/QwyU=
725739
github.com/beta/freetype v0.0.1/go.mod h1:IwMJ63oxprtqBiFXQiJTMyGLdsap+CKsO8ZzQut194I=
726740
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=

0 commit comments

Comments
 (0)