.. meta:: :description: This document provides usage information for the Apache Kafka SMT org.apache.kafka.connect.transforms.Cast. .. _cast: ==== Cast ==== The following provides usage information for the |ak-tm| SMT ``org.apache.kafka.connect.transforms.Cast`` Description ----------- Cast fields (or the entire key or value) to a specific type, updating the schema if one is present. For example, this can be used to force an integer field into an integer of smaller width. Only simple primitive types are supported, such as integer, float, boolean, and string. Use the concrete transformation type designed for the record key (``org.apache.kafka.connect.transforms.Cast$Key``) or value (``org.apache.kafka.connect.transforms.Cast$Value``). Examples -------- ``Cast`` can transform an entire primitive key/value or one or more fields of a complex (Struct or Map) key or value. The two configuration snippet examples below show how to use ``Cast`` in these two scenarios. ----------- Cast Value ----------- This example shows how to use ``Cast`` to transform a 64-bit floating point value into a string. .. code-block:: json "transforms": "Cast", "transforms.Cast.type": "org.apache.kafka.connect.transforms.Cast$Value", "transforms.Cast.spec": "string" Before: ``63521704.02`` After: ``"63521704.02"`` ---------------------------- Cast Comma-Separated Values ---------------------------- This example shows how to use ``Cast`` with a complex key or value. It shows a comma-separated ``field:type`` pair, where ``field`` is the name of the field to cast and ``type`` is the type to cast the field into. .. code-block:: json "transforms": "Cast", "transforms.Cast.type": "org.apache.kafka.connect.transforms.Cast$Value", "transforms.Cast.spec": "ID:string,score:float64" The before and after example below shows a Map or Struct with an ``ID`` field of ``46290`` and a ``score`` field of ``4761``. The ``ID`` field is cast into a string and the ``score`` field is cast into a 64-bit floating point value. Before: .. code-block:: json {"ID": 46920,"score": 4761} After: .. code-block:: json {"ID": "46290","score": 4761.0} .. tip:: For additional examples, see `Cast `__ for managed connectors. Properties ---------- .. list-table:: :header-rows: 1 :widths: 15 30 10 10 10 10 * - Name - Description - Type - Default - Valid Values - Importance * - ``spec`` - A single type to cast the entire value, or for Maps and Structs the comma-separated list of field names and the type to which they should be cast, of the form ``field1:type1,field2:type2``. Valid types are ``int8``, ``int16``, ``int32``, ``int64``, ``float32``, ``float64``, ``boolean``, and ``string``. - list - - comma-separated list of colon-delimited pairs of field:type, e.g. ``foo:int32,bar:string`` - high .. include:: includes/predicate.rst