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

Can FromJson handle "additionalProperties": true? #22

Open
mdommett opened this issue Jan 29, 2024 · 1 comment
Open

Can FromJson handle "additionalProperties": true? #22

mdommett opened this issue Jan 29, 2024 · 1 comment

Comments

@mdommett
Copy link

Reopening #12 since was never fully resolved and I am having similar issues.

As a toy example, I have an event in which one of fields is an object with ever-changing fields. For example:

data":{
"createdAt":"2024-01-29T17:49:53.388901Z"
"id":"154e1153-dd94-4138-a198-d5c4c41fa47d"
"changingField": {"value_1": true, "value_2": true}
}

I will never know what the keys of changingField will be, but i know that they will be of boolean type.

So, i create a schema:

{
  "title": "mySchema",
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "additionalProperties": False,
      "properties": {
        "createdAt": {
          "type": "string",
          "format": "date-time",
          "description": "The date of creation"
        },
        "id": {
          "type": "string",
          "format": "uuid",
          "description": "The unique ID"
        },
        "changingField": {
          "type": "object",
          "additionalProperties": {
            "type": "boolean"
          }
        },
      }
    }
  }
}

I then have a JDBC sink connector that I would define as following:

connector.class=io.confluent.connect.jdbc.JdbcSinkConnector
table.name.format=orders_test
transforms.FromJson.json.schema.validation.enabled=false
tasks.max=3
topics=mytopic
transforms.ExtractData.field=data
transforms=FromJson,ExtractData
transforms.FromJson.type=com.github.jcustenborder.kafka.connect.json.FromJson$Value
transforms.FromJson.json.schema.location=Inline
transforms.ExtractData.type=org.apache.kafka.connect.transforms.ExtractField$Value
connection.user=postgres
transforms.FromJson.json.schema.inline=<<schema defined above>>
auto.create=true
connection.url=XXX
value.converter=org.apache.kafka.connect.storage.StringConverter
insert.mode=upsert
pk.mode=record_value
key.converter=org.apache.kafka.connect.storage.StringConverter
transforms.fieldtojson.type=kafka.connect.smt.FieldToJson$Value
pk.fields=id

However, this will create an error:

null (STRUCT) type doesn't have a mapping to the SQL database column type

Since the changingField has not been given a valid Struct.

Any help on how I can use the connector for this use-case?

Thanks!

@morokin
Copy link

morokin commented Feb 23, 2024

Came to this because of similar reasons.

Confirming issue, same case - field with variable number of keys of same type with schema like below:
"Header": { "type": "object", "additionalProperties": { "type": "array", "items": { "type": "string" } } },

is not working as expected, I'm converting to Avro with s3 sink connector and resulting avro schema part is:

{ "name": "Header", "type": { "name": "properties.Header", "type": "record", "fields": [] } },
"additionalProperties" are not affecting anything

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

No branches or pull requests

2 participants