Skip to content

Commit

Permalink
Merge branch 'master' into improve-snowflake-idle
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored Sep 17, 2024
2 parents 56a4828 + 46eab86 commit c2cb7d7
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 115 deletions.
3 changes: 1 addition & 2 deletions clients/bigquery/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/mocks"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
"github.com/artie-labs/transfer/lib/typing/ext"
Expand All @@ -28,7 +27,7 @@ func TestBigQueryDialect_DataTypeForKind(t *testing.T) {
assert.Equal(t, "string", BigQueryDialect{}.DataTypeForKind(typing.String, false))
}
{
assert.Equal(t, "string", BigQueryDialect{}.DataTypeForKind(typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: ptr.ToInt32(12345)}, true))
assert.Equal(t, "string", BigQueryDialect{}.DataTypeForKind(typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: typing.ToPtr(int32(12345))}, true))
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions clients/mssql/dialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
mssql "github.com/microsoft/go-mssqldb"

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/sql"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
Expand Down Expand Up @@ -92,7 +91,7 @@ func (MSSQLDialect) KindForDataType(rawType string, stringPrecision string) (typ
var strPrecision *int32
precision, err := strconv.ParseInt(stringPrecision, 10, 32)
if err == nil {
strPrecision = ptr.ToInt32(int32(precision))
strPrecision = typing.ToPtr(int32(precision))
}

// precision of -1 means it's MAX.
Expand Down
3 changes: 1 addition & 2 deletions clients/mssql/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/mocks"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
"github.com/artie-labs/transfer/lib/typing/ext"
Expand Down Expand Up @@ -34,7 +33,7 @@ func TestMSSQLDialect_DataTypeForKind(t *testing.T) {
{
kd: typing.KindDetails{
Kind: typing.String.Kind,
OptionalStringPrecision: ptr.ToInt32(12345),
OptionalStringPrecision: typing.ToPtr(int32(12345)),
},
expected: "VARCHAR(12345)",
expectedIsPk: "VARCHAR(900)",
Expand Down
4 changes: 1 addition & 3 deletions clients/mssql/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/artie-labs/transfer/lib/config/constants"

"github.com/artie-labs/transfer/lib/ptr"

"github.com/artie-labs/transfer/lib/typing"

"github.com/artie-labs/transfer/lib/typing/columns"
Expand All @@ -31,7 +29,7 @@ func TestParseValue(t *testing.T) {

// If the string precision exceeds the value, we'll need to insert an exceeded value.
stringCol := columns.NewColumn("foo", typing.String)
stringCol.KindDetails.OptionalStringPrecision = ptr.ToInt32(25)
stringCol.KindDetails.OptionalStringPrecision = typing.ToPtr(int32(25))

val, err = parseValue(`abcdefabcdefabcdefabcdef113321`, stringCol)
assert.NoError(t, err)
Expand Down
4 changes: 1 addition & 3 deletions clients/redshift/cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package redshift
import (
"fmt"

"github.com/artie-labs/transfer/lib/ptr"

"github.com/artie-labs/transfer/lib/stringutil"

"github.com/artie-labs/transfer/lib/config/constants"
Expand All @@ -22,7 +20,7 @@ func (r *RedshiftTestSuite) TestReplaceExceededValues() {
// Masked, reached the string precision limit
stringKd := typing.KindDetails{
Kind: typing.String.Kind,
OptionalStringPrecision: ptr.ToInt32(3),
OptionalStringPrecision: typing.ToPtr(int32(3)),
}

assert.Equal(r.T(), constants.ExceededValueMarker, replaceExceededValues("hello", stringKd))
Expand Down
3 changes: 1 addition & 2 deletions clients/redshift/dialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/sql"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (RedshiftDialect) KindForDataType(rawType string, stringPrecision string) (

return typing.KindDetails{
Kind: typing.String.Kind,
OptionalStringPrecision: ptr.ToInt32(int32(precision)),
OptionalStringPrecision: typing.ToPtr(int32(precision)),
}, nil
}

Expand Down
5 changes: 2 additions & 3 deletions clients/redshift/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/mocks"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
"github.com/artie-labs/transfer/lib/typing/ext"
Expand All @@ -27,7 +26,7 @@ func TestRedshiftDialect_DataTypeForKind(t *testing.T) {
assert.Equal(t, "VARCHAR(MAX)", RedshiftDialect{}.DataTypeForKind(typing.String, true))
}
{
assert.Equal(t, "VARCHAR(12345)", RedshiftDialect{}.DataTypeForKind(typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: ptr.ToInt32(12345)}, false))
assert.Equal(t, "VARCHAR(12345)", RedshiftDialect{}.DataTypeForKind(typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: typing.ToPtr(int32(12345))}, false))
}
}
}
Expand Down Expand Up @@ -92,7 +91,7 @@ func TestRedshiftDialect_KindForDataType(t *testing.T) {
// String with precision
kd, err := dialect.KindForDataType("character varying", "65535")
assert.NoError(t, err)
assert.Equal(t, typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: ptr.ToInt32(65535)}, kd)
assert.Equal(t, typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: typing.ToPtr(int32(65535))}, kd)
}
{
// Times
Expand Down
24 changes: 10 additions & 14 deletions clients/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@ import (
"os"
"strings"

"github.com/artie-labs/transfer/lib/kafkalib"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/sql"

"github.com/artie-labs/transfer/lib/stringutil"

"github.com/artie-labs/transfer/lib/typing/ext"

"github.com/artie-labs/transfer/lib/s3lib"

"github.com/xitongsys/parquet-go-source/local"
"github.com/xitongsys/parquet-go/parquet"
"github.com/xitongsys/parquet-go/writer"

"github.com/artie-labs/transfer/lib/config"
"github.com/artie-labs/transfer/lib/kafkalib"
"github.com/artie-labs/transfer/lib/optimization"
"github.com/artie-labs/transfer/lib/parquetutil"
"github.com/xitongsys/parquet-go-source/local"
"github.com/xitongsys/parquet-go/writer"
"github.com/artie-labs/transfer/lib/s3lib"
"github.com/artie-labs/transfer/lib/sql"
"github.com/artie-labs/transfer/lib/stringutil"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/ext"
)

type Store struct {
Expand Down Expand Up @@ -135,8 +131,8 @@ func (s *Store) Merge(tableData *optimization.TableData) error {
Bucket: s.config.S3.Bucket,
OptionalS3Prefix: s.ObjectPrefix(tableData),
FilePath: fp,
OverrideAWSAccessKeyID: ptr.ToString(s.config.S3.AwsAccessKeyID),
OverrideAWSAccessKeySecret: ptr.ToString(s.config.S3.AwsSecretAccessKey),
OverrideAWSAccessKeyID: typing.ToPtr(s.config.S3.AwsAccessKeyID),
OverrideAWSAccessKeySecret: typing.ToPtr(s.config.S3.AwsSecretAccessKey),
}); err != nil {
return fmt.Errorf("failed to upload file to s3: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions clients/shared/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/artie-labs/transfer/lib/destination/types"
"github.com/artie-labs/transfer/lib/jitter"
"github.com/artie-labs/transfer/lib/optimization"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
)

Expand Down Expand Up @@ -92,7 +92,7 @@ func Merge(dwh destination.DataWarehouse, tableData *optimization.TableData, opt
backfillErr = BackfillColumn(dwh, col, tableID)
if backfillErr == nil {
tableConfig.Columns().UpsertColumn(col.Name(), columns.UpsertColumnArg{
Backfilled: ptr.ToBool(true),
Backfilled: typing.ToPtr(true),
})
break
}
Expand Down
3 changes: 1 addition & 2 deletions clients/snowflake/dialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/sql"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
Expand Down Expand Up @@ -89,7 +88,7 @@ func (SnowflakeDialect) KindForDataType(snowflakeType string, _ string) (typing.

return typing.KindDetails{
Kind: typing.String.Kind,
OptionalStringPrecision: ptr.ToInt32(int32(precision)),
OptionalStringPrecision: typing.ToPtr(int32(precision)),
}, nil
default:
return typing.Invalid, fmt.Errorf("expected at most one type parameters, received %d", len(parameters))
Expand Down
3 changes: 1 addition & 2 deletions clients/snowflake/dialect/dialect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/mocks"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
"github.com/artie-labs/transfer/lib/typing/ext"
Expand All @@ -27,7 +26,7 @@ func TestSnowflakeDialect_DataTypeForKind(t *testing.T) {
assert.Equal(t, "string", SnowflakeDialect{}.DataTypeForKind(typing.String, false))
}
{
assert.Equal(t, "string", SnowflakeDialect{}.DataTypeForKind(typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: ptr.ToInt32(12345)}, false))
assert.Equal(t, "string", SnowflakeDialect{}.DataTypeForKind(typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: typing.ToPtr(int32(12345))}, false))
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions clients/snowflake/staging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/artie-labs/transfer/clients/shared"
"github.com/artie-labs/transfer/lib/config"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing/columns"

"github.com/artie-labs/transfer/lib/destination/types"
Expand All @@ -30,12 +29,12 @@ func (s *SnowflakeTestSuite) TestReplaceExceededValues() {
// String + OptionalStringPrecision set + equal to OptionalStringPrecision:
assert.Equal(s.T(),
strings.Repeat("a", 100),
replaceExceededValues(strings.Repeat("a", 100), typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: ptr.ToInt32(100)}),
replaceExceededValues(strings.Repeat("a", 100), typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: typing.ToPtr(int32(100))}),
)
// String + OptionalStringPrecision set + larger than OptionalStringPrecision:
assert.Equal(s.T(),
constants.ExceededValueMarker,
replaceExceededValues(strings.Repeat("a", 101), typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: ptr.ToInt32(100)}),
replaceExceededValues(strings.Repeat("a", 101), typing.KindDetails{Kind: typing.String.Kind, OptionalStringPrecision: typing.ToPtr(int32(100))}),
)
}

Expand Down
7 changes: 3 additions & 4 deletions lib/config/snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"fmt"

"github.com/artie-labs/transfer/lib/crypto"

"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/snowflakedb/gosnowflake"
)

Expand All @@ -32,10 +31,10 @@ func (s Snowflake) ToConfig() (*gosnowflake.Config, error) {
Params: map[string]*string{
// This parameter will cancel in-progress queries if connectivity is lost.
// https://docs.snowflake.com/en/sql-reference/parameters#abort-detached-query
"ABORT_DETACHED_QUERY": ptr.ToString("true"),
"ABORT_DETACHED_QUERY": typing.ToPtr("true"),
// This parameter must be set to prevent the auth token from expiring after 4 hours.
// https://docs.snowflake.com/en/user-guide/session-policies#considerations
"CLIENT_SESSION_KEEP_ALIVE": ptr.ToString("true"),
"CLIENT_SESSION_KEEP_ALIVE": typing.ToPtr("true"),
},
}

Expand Down
3 changes: 1 addition & 2 deletions lib/debezium/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/artie-labs/transfer/lib/debezium/converters"
"github.com/artie-labs/transfer/lib/maputil"
"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/decimal"
)
Expand Down Expand Up @@ -76,7 +75,7 @@ func (f Field) GetScaleAndPrecision() (int32, *int32, error) {
return 0, nil, precisionErr
}

precisionPtr = ptr.ToInt32(precision)
precisionPtr = typing.ToPtr(int32(precision))
}

return scale, precisionPtr, nil
Expand Down
3 changes: 1 addition & 2 deletions lib/debezium/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/stretchr/testify/assert"

"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/decimal"
"github.com/artie-labs/transfer/lib/typing/ext"
Expand Down Expand Up @@ -38,7 +37,7 @@ func TestField_GetScaleAndPrecision(t *testing.T) {
KafkaDecimalPrecisionKey: 10,
},
expectedScale: 5,
expectedPrecision: ptr.ToInt32(10),
expectedPrecision: typing.ToPtr(int32(10)),
},
{
name: "Test Case 4: Invalid Scale Type",
Expand Down
3 changes: 1 addition & 2 deletions lib/optimization/event_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package optimization
import (
"testing"

"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
"github.com/artie-labs/transfer/lib/typing/decimal"
Expand Down Expand Up @@ -180,7 +179,7 @@ func TestTableData_UpdateInMemoryColumnsFromDestination(t *testing.T) {
// Testing string precision
stringKindWithPrecision := typing.KindDetails{
Kind: typing.String.Kind,
OptionalStringPrecision: ptr.ToInt32(123),
OptionalStringPrecision: typing.ToPtr(int32(123)),
}

assert.NoError(t, tableData.MergeColumnsFromDestination(columns.NewColumn(strCol, stringKindWithPrecision)))
Expand Down
14 changes: 6 additions & 8 deletions lib/parquetutil/generate_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package parquetutil
import (
"encoding/json"

"github.com/artie-labs/transfer/lib/ptr"
"github.com/artie-labs/transfer/lib/typing"
"github.com/artie-labs/transfer/lib/typing/columns"
)
Expand All @@ -20,13 +19,12 @@ func GenerateJSONSchema(columns []columns.Column) (string, error) {
fields = append(fields, *field)
}

schemaBytes, err := json.Marshal(typing.Field{
Tag: typing.FieldTag{
Name: "parquet-go-root",
RepetitionType: ptr.ToString("REQUIRED"),
}.String(),
Fields: fields,
})
schemaBytes, err := json.Marshal(
typing.Field{
Tag: typing.FieldTag{Name: "parquet-go-root", RepetitionType: typing.ToPtr("REQUIRED")}.String(),
Fields: fields,
},
)

if err != nil {
return "", err
Expand Down
27 changes: 0 additions & 27 deletions lib/ptr/ptr.go

This file was deleted.

Loading

0 comments on commit c2cb7d7

Please sign in to comment.