<a id="drop"></a>

# Kafka Connect Drop SMT Usage Reference for Confluent Cloud

The `io.confluent.connect.transforms.Drop` Confluent Single Message
Transformation (SMT) nullifies a record’s key or value.

Use the `schema.behavior` property to control schema modifications:

* `nullify`: Nullifies the target schema with the payload.
* `retain`: Retains the schema as-is.
* `validate`: Verifies that the schema is already optional.
* `force_optional`: Forces the schema to be optional.

Use the concrete transformation type designed for the record key
(`io.confluent.connect.transforms.Drop$Key`) or value
(`io.confluent.connect.transforms.Drop$Value`).

## Installation

This transformation is developed by Confluent and does not ship by
default with Apache Kafka® or Confluent Cloud. You can install this transformation
using the
[confluent connect plugin
install](https://docs.confluent.io/confluent-cli/current/command-reference/connect/plugin/confluent_connect_plugin_install.html)
command:

```properties
confluent connect plugin install confluentinc/connect-transforms:latest
```

## Examples

The configuration snippets below show how to use and configure the `Drop`
SMT.

Drop the key from the message, using the default behavior for schemas, which
nullifies the keys if they are not already null.

```json
"transforms": "dropKeyExample", "dropValueAndForceOptionalSchemaExample",
"transforms.dropKeyExample.type": "io.confluent.connect.transforms.Drop$Key"
```

Drop the value from the message. If the schema for the value isn’t already
optional, forcefully overwrite it to become optional.

```json
"transforms.dropValueAndForceOptionalSchemaExample.type": "io.confluent.connect.transforms.Drop$Value",
"transforms.dropValueAndForceOptionalSchemaExample.schema.behavior": "force_optional"
```

Record contents using `Drop$Key` with `schema.behavior` set to `nullify`:

```json
"transforms.dropValueAndForceOptionalSchemaExample.type": "io.confluent.connect.transforms.Drop$Key",
"transforms.dropValueAndForceOptionalSchemaExample.schema.behavior": "nullify"
```

* Before: `key: 24`, `schema: {"type": "integer"}`
* After: `key: null`, `schema: null`

<br/>

The key is nullified and the schema is nullified.

Record contents using `Drop$Key` with `schema.behavior` set to `retain`:

```json
"transforms.dropValueAndForceOptionalSchemaExample.type": "io.confluent.connect.transforms.Drop$Key",
"transforms.dropValueAndForceOptionalSchemaExample.schema.behavior": "retain"
```

* Before: `key: 24`, `schema: {"type": "integer"}`
* After: `key: null`, `schema: {"type": "integer"}`

<br/>

The key is nullified and the schema is unchanged.

Record contents using `Drop$Key` with `schema.behavior` set to `validate`
where the schema is not optional:

```json
"transforms.dropValueAndForceOptionalSchemaExample.type": "io.confluent.connect.transforms.Drop$Key",
"transforms.dropValueAndForceOptionalSchemaExample.schema.behavior": "validate"
```

* Before: `key: 24`, `schema: {"type": "integer"}`
* After: Throws exception because the schema is not optional.

<br/>

Record contents using `Drop$Key` with `schema.behavior` set to `validate`,
where the schema is optional:

```json
"transforms.dropValueAndForceOptionalSchemaExample.type": "io.confluent.connect.transforms.Drop$Key",
"transforms.dropValueAndForceOptionalSchemaExample.schema.behavior": "validate"
```

* Before: `key: 24`, `schema: {"type": "integer", "optional": true}`
* After: `key: null`, `schema: {"type": "integer", "optional": true}`

<br/>

The key is nullified and the schema is unchanged.

Record contents using `Drop$Key` with `schema.behavior` set to
`force_optional`, where the schema is not optional:

```json
"transforms.dropValueAndForceOptionalSchemaExample.type": "io.confluent.connect.transforms.Drop$Key",
"transforms.dropValueAndForceOptionalSchemaExample.schema.behavior": "force_optional"
```

* Before: `key: 24`, `schema: {"type": "integer"}`
* After: `key: null`, `schema: {"type": "integer", "optional": "true"}`

<br/>

The key is nullified and the schema is made optional.

Record contents using `Drop$Key` with `schema.behavior` set to
`force_optional`, where the schema is already optional:

```json
"transforms.dropValueAndForceOptionalSchemaExample.type": "io.confluent.connect.transforms.Drop$Key",
"transforms.dropValueAndForceOptionalSchemaExample.schema.behavior": "force_optional"
```

* Before: `key: 24`, `schema: {"type": "integer", "optional": true}`
* After: `key: null`, `schema: {"type": "integer", "optional": true}`

The key is nullified and the schema is unchanged.

## Properties

| Name              | Description                                                                                                                                                                                                                                                                                                                                                                                               | Type   | Default   | Valid Values                                | Importance   |
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|-----------|---------------------------------------------|--------------|
| `schema.behavior` | How to handle non-null schemas. If set to `nullify`, then the schema for the new record is null. If set to `retain`, the schema is used, regardless of whether it is optional. If set to `validate`, the schema is checked first, and if it is optional, it is used as-is; otherwise, an exception is thrown. If set to `force_optional`, the schema is overwritten to be optional, if it is not already. | string | nullify   | [nullify, retain, validate, force_optional] | medium       |

## Predicates

Transformations can be configured with *predicates* so that the transformation
is applied only to records which satisfy a condition. You can use predicates in
a transformation chain and, when combined with the [Kafka Connect Filter (Kafka) SMT Usage Reference for Confluent Cloud](filter-ak.md#ak-filter), predicates
can conditionally filter out specific records. For details and examples, see [Predicates](filter-ak.md#predicates).
