Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create sink with key statemets #358

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:

- uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: '1.20'

- run: go mod download

- run: go generate ./...

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Terraform Docs
commit_message: Terraform Docs
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:

- uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: '1.20'

- run: go mod download

- run: go test -v -cover ./...
- run: go test -v -cover ./...
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine
FROM golang:1.20-alpine

COPY --from=hashicorp/terraform:1.3.1 /bin/terraform /bin/terraform

Expand All @@ -11,4 +11,4 @@ COPY . .

RUN go build -o ~/.terraform.d/plugins/materialize.com/devex/materialize/0.1/linux_amd64/terraform-provider-materialize

WORKDIR /usr/src/app/integration
WORKDIR /usr/src/app/integration
1 change: 1 addition & 0 deletions integration/sink.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ resource "materialize_sink_kafka" "sink_kafka" {
envelope {
debezium = true
}
key = ["counter"]
}

output "qualified_sink_kafka" {
Expand Down
8 changes: 4 additions & 4 deletions pkg/materialize/sink_kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ func (b *SinkKafkaBuilder) Create() error {
q.WriteString(fmt.Sprintf(` INTO KAFKA CONNECTION %s`, b.kafkaConnection.QualifiedName()))
}

if b.topic != "" {
q.WriteString(fmt.Sprintf(` (TOPIC %s)`, QuoteString(b.topic)))
}

if len(b.key) > 0 {
o := strings.Join(b.key[:], ", ")
q.WriteString(fmt.Sprintf(` KEY (%s)`, o))
}

if b.topic != "" {
q.WriteString(fmt.Sprintf(` (TOPIC %s)`, QuoteString(b.topic)))
}

if b.format.Json {
q.WriteString(` FORMAT JSON`)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/materialize/sink_kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestSinkKafkaCreate(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(
`CREATE SINK "database"."schema"."sink" FROM "database"."schema"."table" INTO KAFKA CONNECTION "database"."schema"."kafka_connection" KEY \(key_1, key_2\) \(TOPIC 'test_avro_topic'\) FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION "database"."public"."csr_connection" ENVELOPE UPSERT WITH \( SIZE = 'xsmall' SNAPSHOT = false\);`,
`CREATE SINK "database"."schema"."sink" FROM "database"."schema"."table" INTO KAFKA CONNECTION "database"."schema"."kafka_connection" \(TOPIC 'test_avro_topic'\) KEY \(key_1, key_2\) FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION "database"."public"."csr_connection" ENVELOPE UPSERT WITH \( SIZE = 'xsmall' SNAPSHOT = false\);`,
).WillReturnResult(sqlmock.NewResult(1, 1))

o := MaterializeObject{Name: "sink", SchemaName: "schema", DatabaseName: "database"}
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/resource_sink_kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestResourceSinkKafkaCreate(t *testing.T) {
testhelpers.WithMockDb(t, func(db *sqlx.DB, mock sqlmock.Sqlmock) {
// Create
mock.ExpectExec(
`CREATE SINK "database"."schema"."sink" IN CLUSTER "cluster" FROM "database"."public"."item" INTO KAFKA CONNECTION "database"."schema"."kafka_conn" KEY \(key_1, key_2\) \(TOPIC 'topic'\) FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION "database"."schema"."csr_conn" WITH \(AVRO KEY FULLNAME 'avro_key_fullname' AVRO VALUE FULLNAME 'avro_value_fullname'\) ENVELOPE UPSERT WITH \( SIZE = 'small' SNAPSHOT = false\);`,
`CREATE SINK "database"."schema"."sink" IN CLUSTER "cluster" FROM "database"."public"."item" INTO KAFKA CONNECTION "database"."schema"."kafka_conn" \(TOPIC 'topic'\) KEY \(key_1, key_2\) FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION "database"."schema"."csr_conn" WITH \(AVRO KEY FULLNAME 'avro_key_fullname' AVRO VALUE FULLNAME 'avro_value_fullname'\) ENVELOPE UPSERT WITH \( SIZE = 'small' SNAPSHOT = false\);`,
).WillReturnResult(sqlmock.NewResult(1, 1))

// Query Id
Expand Down