Map basic messages
When messages are created using a basic or primitive serializer, the message contains a key-value pair. Map the key and value to table columns.
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.
Basic mapping example
In this example, a Pulsar topic named world_topic contains five records with a key-value pair in each.
The key is an integer and the value is text.
-
Create a keyspace in your database.
This example creates a keyspace named
world_keyspace:cqlsh -e "CREATE KEYSPACE world_keyspace \ WITH replication = {'class': 'NetworkTopologyStrategy', \ 'Cassandra': 1};"For DSE and Cassandra clusters, make sure that the keyspace is replicated to a datacenter set in the connector’s
contactPointsparameter. DSE datacenter names are case sensitive. Usenodetool ringto get a list of datacenters. -
Create a table.
This example creates a table named
world_tablewith two columns:cqlsh -e "CREATE TABLE world_table (recordid int PRIMARY KEY, continent text);" -
For DSE, verify that all nodes have the same schema version using
nodetool describering.For example, this command verifies the schema for
world_keyspace:nodetool describering -- world_keyspace -
In the DataStax connector configuration file, add the Pulsar topic name to
topics, and define the field-to-column mapping.The following example is maps the
world_topicto theworld_tableusing the minimum required settings:tasks.max: 1 topics: world_topic topic: world_topic: world_keyspace: world_table: mapping: 'recordid=key, continent=value' -
Use
pulsar-admin sinks updateto apply the new configuration.