> For the complete documentation index, see [llms.txt](https://docs.selfuel.digital/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.selfuel.digital/data-integration-with-nexus/nexus-elements/connectors/sink/assert.md).

# Assert

> Assert sink connector

### Description[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#description) <a href="#description" id="description"></a>

A flink sink plugin which can assert illegal data by user defined rules

### Key Features[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#key-features) <a href="#key-features" id="key-features"></a>

* [ ] &#x20;exactly-once

### Options[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#options) <a href="#options" id="options"></a>

| Name                                                                                                    | Type                                            | Required | Default |
| ------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | -------- | ------- |
| rules                                                                                                   | ConfigMap                                       | yes      | -       |
| rules.field\_rules                                                                                      | string                                          | yes      | -       |
| rules.field\_rules.field\_name                                                                          | string\|ConfigMap                               | yes      | -       |
| rules.field\_rules.field\_type                                                                          | string                                          | no       | -       |
| rules.field\_rules.field\_value                                                                         | ConfigList                                      | no       | -       |
| rules.field\_rules.field\_value.rule\_type                                                              | string                                          | no       | -       |
| rules.field\_rules.field\_value.rule\_value                                                             | numeric                                         | no       | -       |
| rules.field\_rules.field\_value.equals\_to                                                              | boolean\|numeric\|string\|ConfigList\|ConfigMap | no       | -       |
| rules.row\_rules                                                                                        | string                                          | yes      | -       |
| rules.row\_rules.rule\_type                                                                             | string                                          | no       | -       |
| rules.row\_rules.rule\_value                                                                            | string                                          | no       | -       |
| rules.catalog\_table\_rule                                                                              | ConfigMap                                       | no       | -       |
| rules.catalog\_table\_rule.primary\_key\_rule                                                           | ConfigMap                                       | no       | -       |
| rules.catalog\_table\_rule.primary\_key\_rule.primary\_key\_name                                        | string                                          | no       | -       |
| rules.catalog\_table\_rule.primary\_key\_rule.primary\_key\_columns                                     | ConfigList                                      | no       | -       |
| rules.catalog\_table\_rule.constraint\_key\_rule                                                        | ConfigList                                      | no       | -       |
| rules.catalog\_table\_rule.constraint\_key\_rule.constraint\_key\_name                                  | string                                          | no       | -       |
| rules.catalog\_table\_rule.constraint\_key\_rule.constraint\_key\_type                                  | string                                          | no       | -       |
| rules.catalog\_table\_rule.constraint\_key\_rule.constraint\_key\_columns                               | ConfigList                                      | no       | -       |
| rules.catalog\_table\_rule.constraint\_key\_rule.constraint\_key\_columns.constraint\_key\_column\_name | string                                          | no       | -       |
| rules.catalog\_table\_rule.constraint\_key\_rule.constraint\_key\_columns.constraint\_key\_sort\_type   | string                                          | no       | -       |
| rules.catalog\_table\_rule.column\_rule                                                                 | ConfigList                                      | no       | -       |
| rules.catalog\_table\_rule.column\_rule.name                                                            | string                                          | no       | -       |
| rules.catalog\_table\_rule.column\_rule.type                                                            | string                                          | no       | -       |
| rules.catalog\_table\_rule.column\_rule.column\_length                                                  | int                                             | no       | -       |
| rules.catalog\_table\_rule.column\_rule.nullable                                                        | boolean                                         | no       | -       |
| rules.catalog\_table\_rule.column\_rule.default\_value                                                  | string                                          | no       | -       |
| rules.catalog\_table\_rule.column\_rule.comment                                                         | comment                                         | no       | -       |
| rules.table-names                                                                                       | ConfigList                                      | no       | -       |
| common-options                                                                                          |                                                 | no       | -       |

#### rules \[ConfigMap][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#rules-configmap) <a href="#rules-configmap" id="rules-configmap"></a>

Rule definition of user's available data. Each rule represents one field validation or row num validation.

#### field\_rules \[ConfigList][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#field_rules-configlist) <a href="#field_rules-configlist" id="field_rules-configlist"></a>

field rules for field validation

#### field\_name \[string][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#field_name-string) <a href="#field_name-string" id="field_name-string"></a>

field name（string）

#### field\_type \[string | ConfigMap][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#field_type-string--configmap) <a href="#field_type-string--configmap" id="field_type-string--configmap"></a>

Field type declarations should adhere to this [guide](https://seatunnel.apache.org/docs/2.3.7/concept/schema-feature#how-to-declare-type-supported).

#### field\_value \[ConfigList][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#field_value-configlist) <a href="#field_value-configlist" id="field_value-configlist"></a>

A list value rule define the data value validation

#### rule\_type \[string][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#rule_type-string) <a href="#rule_type-string" id="rule_type-string"></a>

The following rules are supported for now

* NOT\_NULL `value can't be null`
* NULL `value can be null`
* MIN `define the minimum value of data`
* MAX `define the maximum value of data`
* MIN\_LENGTH `define the minimum string length of a string data`
* MAX\_LENGTH `define the maximum string length of a string data`
* MIN\_ROW `define the minimun number of rows`
* MAX\_ROW `define the maximum number of rows`

#### rule\_value \[numeric][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#rule_value-numeric) <a href="#rule_value-numeric" id="rule_value-numeric"></a>

The value related to rule type. When the `rule_type` is `MIN`, `MAX`, `MIN_LENGTH`, `MAX_LENGTH`, `MIN_ROW` or `MAX_ROW`, users need to assign a value to the `rule_value`.

#### equals\_to \[boolean | numeric | string | ConfigList | ConfigMap][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#equals_to-boolean--numeric--string--configlist--configmap) <a href="#equals_to-boolean--numeric--string--configlist--configmap" id="equals_to-boolean--numeric--string--configlist--configmap"></a>

`equals_to` is used to compare whether the field value is equal to the configured expected value. You can assign values of all types to `equals_to`. These types are detailed [here](https://seatunnel.apache.org/docs/2.3.7/concept/schema-feature#what-type-supported-at-now). For instance, if one field is a row with three fields, and the declaration of row type is `{a = array<string>, b = map<string, decimal(30, 2)>, c={c_0 = int, b = string}}`, users can assign the value `[["a", "b"], { k0 = 9999.99, k1 = 111.11 }, [123, "abcd"]]` to `equals_to`.

> The way of defining field values is consistent with [FakeSource](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/FakeSource#customize-the-data-content-simple).
>
> `equals_to` cannot be applied to `null` type fields. However, users can use the rule type `NULL` for verification, such as `{rule_type = NULL}`.

#### catalog\_table\_rule \[ConfigMap][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#catalog_table_rule-configmap) <a href="#catalog_table_rule-configmap" id="catalog_table_rule-configmap"></a>

Used to assert the catalog table is same with the user defined table.

#### table-names \[ConfigList][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#table-names-configlist) <a href="#table-names-configlist" id="table-names-configlist"></a>

Used to assert the table should be in the data.

#### common options[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#common-options) <a href="#common-options" id="common-options"></a>

Sink plugin common parameters, please refer to [Sink Common Options](/data-integration-with-nexus/nexus-elements/connectors/sink/sink-common-options.md) for details

### Example[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/sink/Assert#example) <a href="#example" id="example"></a>

the whole config obey with `hocon` style

```
Assert {
    rules =
      {
        row_rules = [
          {
            rule_type = MAX_ROW
            rule_value = 10
          },
          {
            rule_type = MIN_ROW
            rule_value = 5
          }
        ],
        field_rules = [{
          field_name = name
          field_type = string
          field_value = [
            {
              rule_type = NOT_NULL
            },
            {
              rule_type = MIN_LENGTH
              rule_value = 5
            },
            {
              rule_type = MAX_LENGTH
              rule_value = 10
            }
          ]
        }, {
          field_name = age
          field_type = int
          field_value = [
            {
              rule_type = NOT_NULL
              equals_to = 23
            },
            {
              rule_type = MIN
              rule_value = 32767
            },
            {
              rule_type = MAX
              rule_value = 2147483647
            }
          ]
        }
        ]
        catalog_table_rule {
            primary_key_rule = {
                primary_key_name = "primary key"
                primary_key_columns = ["id"]
            }
            constraint_key_rule = [
                        {
                        constraint_key_name = "unique_name"
                        constraint_key_type = UNIQUE_KEY
                        constraint_key_columns = [
                            {
                                constraint_key_column_name = "id"
                                constraint_key_sort_type = ASC
                            }
                        ]
                        }
            ]
            column_rule = [
               {
                name = "id"
                type = bigint
               },
              {
                name = "name"
                type = string
              },
              {
                name = "age"
                type = int
              }
            ]
        }
      }

  }
```

Here is a more complex example about `equals_to`. The example involves FakeSource. You may want to learn it, please read this [document](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/FakeSource).

```
source {
  FakeSource {
    row.num = 1
    schema = {
      fields {
        c_null = "null"
        c_string = string
        c_boolean = boolean
        c_tinyint = tinyint
        c_smallint = smallint
        c_int = int
        c_bigint = bigint
        c_float = float
        c_double = double
        c_decimal = "decimal(30, 8)"
        c_date = date
        c_timestamp = timestamp
        c_time = time
        c_bytes = bytes
        c_array = "array<int>"
        c_map = "map<time, string>"
        c_map_nest = "map<string, {c_int = int, c_string = string}>"
        c_row = {
          c_null = "null"
          c_string = string
          c_boolean = boolean
          c_tinyint = tinyint
          c_smallint = smallint
          c_int = int
          c_bigint = bigint
          c_float = float
          c_double = double
          c_decimal = "decimal(30, 8)"
          c_date = date
          c_timestamp = timestamp
          c_time = time
          c_bytes = bytes
          c_array = "array<int>"
          c_map = "map<string, string>"
        }
      }
    }
    rows = [
      {
        kind = INSERT
        fields = [
          null, "AAA", false, 1, 1, 333, 323232, 3.1, 9.33333, 99999.99999999, "2012-12-21", "2012-12-21T12:34:56", "12:34:56",
          "bWlJWmo=",
          [0, 1, 2],
          "{ 12:01:26 = v0 }",
          { k1 = [123, "BBB-BB"]},
          [
            null, "AAA", false, 1, 1, 333, 323232, 3.1, 9.33333, 99999.99999999, "2012-12-21", "2012-12-21T12:34:56", "12:34:56",
            "bWlJWmo=",
            [0, 1, 2],
            { k0 = v0 }
          ]
        ]
      }
    ]
    result_table_name = "fake"
  }
}

sink{
  Assert {
    source_table_name = "fake"
    rules =
      {
        row_rules = [
          {
            rule_type = MAX_ROW
            rule_value = 1
          },
          {
            rule_type = MIN_ROW
            rule_value = 1
          }
        ],
        field_rules = [
            {
                field_name = c_null
                field_type = "null"
                field_value = [
                    {
                        rule_type = NULL
                    }
                ]
            },
            {
                field_name = c_string
                field_type = string
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = "AAA"
                    }
                ]
            },
            {
                field_name = c_boolean
                field_type = boolean
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = false
                    }
                ]
            },
            {
                field_name = c_tinyint
                field_type = tinyint
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = 1
                    }
                ]
            },
            {
                field_name = c_smallint
                field_type = smallint
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = 1
                    }
                ]
            },
            {
                field_name = c_int
                field_type = int
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = 333
                    }
                ]
            },
            {
                field_name = c_bigint
                field_type = bigint
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = 323232
                    }
                ]
            },
            {
                field_name = c_float
                field_type = float
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = 3.1
                    }
                ]
            },
            {
                field_name = c_double
                field_type = double
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = 9.33333
                    }
                ]
            },
            {
                field_name = c_decimal
                field_type = "decimal(30, 8)"
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = 99999.99999999
                    }
                ]
            },
            {
                field_name = c_date
                field_type = date
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = "2012-12-21"
                    }
                ]
            },
            {
                field_name = c_timestamp
                field_type = timestamp
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = "2012-12-21T12:34:56"
                    }
                ]
            },
            {
                field_name = c_time
                field_type = time
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = "12:34:56"
                    }
                ]
            },
            {
                field_name = c_bytes
                field_type = bytes
                field_value = [
                      {
                          rule_type = NOT_NULL
                          equals_to = "bWlJWmo="
                      }
                ]
            },
            {
                field_name = c_array
                field_type = "array<int>"
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = [0, 1, 2]
                    }
                ]
            },
            {
                field_name = c_map
                field_type = "map<time, string>"
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = "{ 12:01:26 = v0 }"
                    }
                ]
            },
            {
                field_name = c_map_nest
                field_type = "map<string, {c_int = int, c_string = string}>"
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = { k1 = [123, "BBB-BB"] }
                    }
                ]
            },
            {
                field_name = c_row
                field_type = {
                    c_null = "null"
                    c_string = string
                    c_boolean = boolean
                    c_tinyint = tinyint
                    c_smallint = smallint
                    c_int = int
                    c_bigint = bigint
                    c_float = float
                    c_double = double
                    c_decimal = "decimal(30, 8)"
                    c_date = date
                    c_timestamp = timestamp
                    c_time = time
                    c_bytes = bytes
                    c_array = "array<int>"
                    c_map = "map<string, string>"
                }
                field_value = [
                    {
                        rule_type = NOT_NULL
                        equals_to = [
                           null, "AAA", false, 1, 1, 333, 323232, 3.1, 9.33333, 99999.99999999, "2012-12-21", "2012-12-21T12:34:56", "12:34:56",
                           "bWlJWmo=",
                           [0, 1, 2],
                           { k0 = v0 }
                        ]
                    }
                ]
            }
        ]
    }
  }
}
```
