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: re-allow empty pk.fields with pk.mode set to record_key #360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jclarysse
Copy link

Recently added validations (see PR #335) are preventing the support of schema evolution use-cases, e.g.

Documentation:

If 'pk.mode' is 'record_key' and 'pk.fields' is empty,
then all fields from the key struct will be used.

Configuration:

"pk.mode": "record_key",
"auto.create": "true",
"auto.evolve": "true",

Validation rule:

Primary key fields must be set when pkMode is 'record_key'.

The purpose of this PR is to re-enable this feature for record_key mode.

Recently added validations (see PR Aiven-Open#335) are preventing the
support of schema evolution use-cases, e.g.

Documentation:
```
If 'pk.mode' is 'record_key' and 'pk.fields' is empty,
then all fields from the key struct will be used.
```

Configuration:
```
"pk.mode": "record_key",
"auto.create": "true",
"auto.evolve": "true",
```

Validation rule:
```
Primary key fields must be set when pkMode is 'record_key'.
```

The purpose of this PR is to re-enable this feature
for `record_key` mode.
@jclarysse jclarysse requested a review from a team as a code owner January 31, 2025 13:30
@jclarysse
Copy link
Author

jclarysse commented Jan 31, 2025

Create connector:

curl -X POST http://localhost:8083/connectors \
   -H "Content-Type: application/json" \
   -H "Accept: application/json" \
   -d \
  '{
    "name": "julien-jdbc-sink",
    "config": {
        "connector.class": "io.aiven.connect.jdbc.JdbcSinkConnector",
        "connection.url": "jdbc:postgresql://localhost:5432/defaultdb",
        "connection.user": "postgres",
        "connection.password": "postgres",
        "topics": "test-topic-avro",
        "key.converter": "io.confluent.connect.avro.AvroConverter",
        "key.converter.schema.registry.url": "http://localhost:8081",
        "value.converter": "io.confluent.connect.avro.AvroConverter",
        "value.converter.schema.registry.url": "http://localhost:8081",
        "pk.mode": "record_key",
        "auto.create": "true",
        "auto.evolve": "true"
    }
  }'

Produce record with Avro key via Karapace:

curl -H "Content-Type: application/vnd.kafka.avro.v2+json" -X POST -d \
  '{
      "key_schema": "{
        \"namespace\": \"example.avro\", \"type\": \"record\", \"name\": \"simplekey\",
        \"fields\": [{\"name\": \"id\", \"type\": \"int\"},{\"name\": \"code\", \"type\": \"int\"}]
      }",
      "value_schema": "{
        \"namespace\": \"example.avro\", \"type\": \"record\", \"name\": \"simplevalue\",
        \"fields\": [{\"name\": \"name\", \"type\": \"string\"}]
      }",
      "records": [{"key": {"id": 0, "code": 10}, "value": {"name": "julien"}}]
  }' https://localhost:8082/topics/test-topic-avro

Verify that the table is created with the 2 key fields as PK:

=> \d test-topic-avro
          Table "public.test-topic-avro"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 name   | text    |           | not null | 
 code   | integer |           | not null | 
 id     | integer |           | not null | 
Indexes:
    "test-topic-avro_pkey" PRIMARY KEY, btree (code, id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant