Как создать настройки сохранения для Apache Ignite из существующего Cassandra DDL?

#cassandra #ignite

#кассандра #ignite

Вопрос:

Я интегрирую Ignite cache с Cassandra. И у меня есть следующий DDL для существующей таблицы Cassandra:

  CREATE TABLE IF NOT EXISTS ignite.wgs_measurements
    (
     "conValue" double,
     "location" text,
     "rawValue" double,
     "sensorid" text,
     "timestamp" timestamp,
     "type" text,
     primary key (sensorid, timestamp)
    ) WITH CLUSTERING ORDER BY (timestamp DESC);
 

Я создал следующее persistence_settings.xml файл, чтобы попытаться сопоставить таблицу cassandra.

 <persistence keyspace="ignite" table="wgs_measurements" ttl="86400">
    <keyspaceOptions>
        REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 3}
        AND DURABLE_WRITES = true
    </keyspaceOptions>
    <tableOption>
        comment = 'Cache test'
        AND read_repair_chance = 0.2
    </tableOption>
    <!-- Persistent settings for Ignite cache keys -->
    <keyPersistence class="ignite.SensorData" strategy="POJO">
        <!-- Partition key fields if POJO strategy used -->
        <partitionKey>
            <!-- Mapping from POJO field to Cassandra table column -->
            <field name="sensorId" column="sensorid" />
            <field name="timestamp" column="timestamp" />
        </partitionKey>
    </keyPersistence>
    <valuePersistence class="ignite.SensorData"
                      strategy="POJO">
        <!-- Mapping from POJO field to Cassandra table column -->
        <field name="conValue" />
        <field name="rawValue" />
        <field name="location" />
        <field name="type" />
    </valuePersistence>
</persistence>
 

Но для этого используйте Ignite Cassandra DDLGenerator persistence_settings.xml файл Я получаю следующий DDL, который не соответствует моему существующему DDL.

 create table if not exists "ignite"."wgs_measurements"
(
 "sensorid" text,
 "timestamp" timestamp,
 "convalue" double,
 "location" text,
 "rawvalue" double,
 "type" text,
 primary key (("sensorid", "timestamp"), "convalue", "location", "rawvalue", "type")
);
 

Здесь вы также можете увидеть класс SensorData:

 public class SensorData {
    public String type     = "UNKNOWN";
    public String sensorId;
    public Date   timestamp;
    public String location = "UNKNOWN";
    public double rawValue;
    public double conValue = -1D;
    
    /*All getters and setters are included here*/
}
 

Как настроить параметры сохранения, чтобы получить результаты, необходимые для создания существующей таблицы Cassandra, которая у меня есть?

Ответ №1:

Вам нужны отдельные классы для ключа и значения. Рассмотрите возможность разделения sensorid и timestamp в классе SensorDataKey и обновления вашего XML.