【问题标题】:How to create the persistence settings for Apache Ignite from existing Cassandra DDL?如何从现有的 Cassandra DDL 创建 Apache Ignite 的持久性设置?
【发布时间】:2020-11-18 20:07:06
【问题描述】:

我正在将 Ignite 缓存与 Cassandra 集成。对于现有的 Cassandra 表,我有以下 DDL:

 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>

但是对这个 persistence_settings.xml 文件使用 Ignite Cassandra DDLGenerator 我得到了以下与我现有的 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 表所需的结果?

【问题讨论】:

    标签: cassandra ignite


    【解决方案1】:

    您需要单独的键和值类。考虑将sensoridtimestamp 拆分为SensorDataKey 类并更新您的XML。

    【讨论】:

      猜你喜欢
      • 2021-04-28
      • 2018-05-19
      • 2020-02-05
      • 2022-01-15
      • 2018-07-04
      • 2023-03-19
      • 1970-01-01
      • 2017-05-06
      • 1970-01-01
      相关资源
      最近更新 更多