Map Avro messages

The DataStax Apache Pulsar™ connector supports mapping individual fields from Avro formatted key or values.

Mapping requirements

When mapping fields to columns, the following requirements apply:

  • The data in the Pulsar field must be compatible with the mapped column’s data type. For example, a string field cannot map to a number column.

  • A Pulsar field mapped to a table’s primary key (PK) column must always contain data because primary key columns don’t allow nulls.

  • All primary key columns must have a mapping because primary key columns don’t allow nulls.

Avro mapping example

In this example, the key is a basic string and the value is Avro format. The Pulsar topic name is users_topic and have the following records:

Key Value

user0

{"name": "chris", "favorite_number":14, "favorite_color": "blue"}

user1

{"name": "jack", "favorite_number":56, "favorite_color": "pink"}

user2

{"name": "shereen", "favorite_number":7, "favorite_color": "black"}

user3

{"name": "kimberly", "favorite_number":11, "favorite_color": "orange"}

user4

{"name": "taryn", "favorite_number":37, "favorite_color": "green"}

The value field uses the following Avro Schema:

{
 "namespace": "example.avro",
 "type": "record",
 "name": "user",
 "fields": [
     {"name": "name", "type": "string"},
     {"name": "favorite_number",  "type": "int"},
     {"name": "favorite_color", "type": "string"}
 ]
}

The following table describes the desired outcome from the mapping when the messages are written to the CQL table:

userid name favoritenumber favoritecolor

user0

chris

14

blue

user1

jack

56

pink

user2

shereen

7

black

user3

kimberly

11

orange

user4

taryn

37

green

To achieve this outcome, the connector’s mapping must be configured as follows. For this example, the topic name is users_topic, the keyspace name is users_keyspace, and the table name is users_table.

topic:
    users_topic:
        users_keyspace:
            users_table:
                mapping: 'userid=key, name=value.name, favoritenumber=value.favorite_number, favoritecolor=value.favorite_color'

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax, an IBM Company | Privacy policy | Terms of use | Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com