Map a topic to multiple tables
The DataStax Apache Pulsar™ connector allows for mapping a single topic to multiple tables for a single connector instance.
In the example stocks_topic, the key is a basic string and the value is regular JSON.
| key | value |
|---|---|
|
|
|
|
|
|
|
|
|
|
In the DataStax keyspace stocks_keyspace, create three different tables that optimized with different schemas.
-
stocks_table_by_symbolCREATE TABLE stocks_keyspace.stocks_table_by_symbol ( symbol text, ts timestamp, exchange text, industry text, name text, value double, PRIMARY KEY (symbol, ts)); -
stocks_table_by_exhangeCREATE TABLE stocks_keyspace.stocks_table_by_exchange ( symbol text, ts timestamp, exchange text, industry text, name text, value double, PRIMARY KEY (exchange, ts)); -
stocks_table_by_industryCREATE TABLE stocks_keyspace.stocks_table_by_industry ( symbol text, ts timestamp, exchange text, industry text, name text, value double, PRIMARY KEY (industry, ts));
Configure the connector and add all the map specifications:
-
stocks_topictostocks_table_by_symboltopic: stocks_topic: stocks_keyspace: stocks_table_by_symbol: mapping: 'symbol=value.symbol, ts=value.ts, exchange=value.exchange, industry=value.industry, name=key.name, value=value.value' -
stocks_topictostocks_table_by_exchange“topic: stocks_topic: stocks_keyspace: stocks_table_by_exchange: mapping: 'symbol=value.symbol, ts=value.ts, exchange=value.exchange, industry=value.industry, name=key.name, value=value.value' -
stocks_topictostocks_table_by_industrytopic: stocks_topic: stocks_keyspace: stocks_table_by_industry: mapping: 'symbol=value.symbol, ts=value.ts, exchange=value.exchange, industry=value.industry, name=key.name, value=value.value'