阿帕奇点燃查询
apache ignite query
我使用自动持久性创建了一个缓存,连接到 Mysql 数据库。
100 万行在启动时填充到该节点中。节点处于分区模式
当我尝试使用 SQL 查询从缓存中检索数据时,它总是 returns 空数组。
我已经使用 "CacheTypeMetadata".
对缓存进行了索引
请任何人指出我遗漏或做错了什么。我一直在关注教程,但我无法弄清楚为什么我的查询无法正常工作。
提前致谢!
缓存:
CacheConfiguration<Dataloadermd5Key, DataLoaderMd5> cfg =
CacheConfigMd5.cache("DataMd5Cache",
new JDBCFactory<Dataloadermd5Key, DataLoaderMd5>());
DataLoaderMd5Key:
public class Dataloadermd5Key implements Serializable {
/** */
private static final long serialVersionUID = 0L;
/** Value for idClient. */
private int idClient;
/** Value for clientPropId. */
private String clientPropId;
//...
}
DataLoaderMd5:
public class DataLoaderMd5 implements Serializable {
/** */
private static final long serialVersionUID = 0L;
/** Value for idClient. */
private int idClient;
/** Value for clientPropId. */
private String clientPropId;
/** Value for md5. */
private String md5;
//...
}
CacheConfigMd5:
public static <K, V> CacheConfiguration<K, V> cache(String name,
Factory<CacheStore<K, V>> storeFactory) {
if (storeFactory == null)
throw new IllegalArgumentException("Cache store factory cannot be null.");
CacheConfiguration<K, V> ccfg = new CacheConfiguration<>(name);
ccfg.setCacheStoreFactory(storeFactory);
ccfg.setReadThrough(true);
ccfg.setWriteThrough(true);
// Configure cache types.
Collection<CacheTypeMetadata> meta = new ArrayList<>();
// DataLoaderMd5.
CacheTypeMetadata type = new CacheTypeMetadata();
meta.add(type);
type.setDatabaseSchema("abc");
type.setDatabaseTable("dfg");
type.setKeyType(Dataloadermd5Key.class.getName());
type.setValueType(DataLoaderMd5.class.getName());
// Key fields for DataLoaderMd5.
Collection<CacheTypeFieldMetadata> keys = new ArrayList<>();
keys.add(new CacheTypeFieldMetadata("id_client", Types.INTEGER,
"idclient", int.class));
keys.add(new CacheTypeFieldMetadata("client_prop_id", Types.VARCHAR,
"clientPropId", String.class));
type.setKeyFields(keys);
// Value fields for DataLoaderMd5.
Collection<CacheTypeFieldMetadata> vals = new ArrayList<>();
vals.add(new CacheTypeFieldMetadata("id_client", Types.INTEGER,
"idclient", int.class));
vals.add(new CacheTypeFieldMetadata("client_prop_id", Types.VARCHAR,
"clientPropId", String.class));
vals.add(new CacheTypeFieldMetadata("Md5", Types.VARCHAR,
"md5", String.class));
type.setValueFields(vals);
// Query fields for DataLoaderMd5.
Map<String, Class<?>> qryFlds = new LinkedHashMap<>();
qryFlds.put("idclient", int.class);
qryFlds.put("clientPropId", String.class);
qryFlds.put("md5", String.class);
type.setQueryFields(qryFlds);
// Groups for DataLoaderMd5.
Map<String, LinkedHashMap<String,
IgniteBiTuple<Class<?>, Boolean>>> grps = new LinkedHashMap<>();
LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> grpItems =
new LinkedHashMap<>();
grpItems.put("idclient", new IgniteBiTuple<Class<?>,
Boolean>(int.class, false));
grpItems.put("clientPropId", new IgniteBiTuple<Class<?>,
Boolean>(String.class, false));
grps.put("PRIMARY", grpItems);
type.setGroups(grps);
ccfg.setTypeMetadata(meta);
return ccfg;
}
查询:
Ignite ignite = Ignition.start("examples/config/example-cache.xml");
IgniteCache<Dataloadermd5Key, DataLoaderMd5> cache = ignite.cache(CACHE_NAME);
Dataloadermd5Key key = new Dataloadermd5Key();
key.setIdClient(98255);
key.setClientPropId("1000008");
SqlQuery<Dataloadermd5Key, DataLoaderMd5> qry =
new SqlQuery<Dataloadermd5Key, DataLoaderMd5>(
DataLoaderMd5.class, "idClient = ? and clientPropId = ?");
//Excecute query
System.out.println("sqlQuery Lookup result :: " +
cache.query(qry).getAll());
System.out.println("sqlQuery Lookup result :: " +
cache.query(qry.setArgs(key.getIdClient(), key.getClientPropId())).getAll());
我发现了问题。这是因为我的 Ignite 版本。
我将 maven 上的版本更新为 1.1.0,代码开始正常运行。
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>1.1.0-incubating</version>
</dependency>
我使用自动持久性创建了一个缓存,连接到 Mysql 数据库。 100 万行在启动时填充到该节点中。节点处于分区模式
当我尝试使用 SQL 查询从缓存中检索数据时,它总是 returns 空数组。 我已经使用 "CacheTypeMetadata".
对缓存进行了索引请任何人指出我遗漏或做错了什么。我一直在关注教程,但我无法弄清楚为什么我的查询无法正常工作。
提前致谢!
缓存:
CacheConfiguration<Dataloadermd5Key, DataLoaderMd5> cfg =
CacheConfigMd5.cache("DataMd5Cache",
new JDBCFactory<Dataloadermd5Key, DataLoaderMd5>());
DataLoaderMd5Key:
public class Dataloadermd5Key implements Serializable {
/** */
private static final long serialVersionUID = 0L;
/** Value for idClient. */
private int idClient;
/** Value for clientPropId. */
private String clientPropId;
//...
}
DataLoaderMd5:
public class DataLoaderMd5 implements Serializable {
/** */
private static final long serialVersionUID = 0L;
/** Value for idClient. */
private int idClient;
/** Value for clientPropId. */
private String clientPropId;
/** Value for md5. */
private String md5;
//...
}
CacheConfigMd5:
public static <K, V> CacheConfiguration<K, V> cache(String name,
Factory<CacheStore<K, V>> storeFactory) {
if (storeFactory == null)
throw new IllegalArgumentException("Cache store factory cannot be null.");
CacheConfiguration<K, V> ccfg = new CacheConfiguration<>(name);
ccfg.setCacheStoreFactory(storeFactory);
ccfg.setReadThrough(true);
ccfg.setWriteThrough(true);
// Configure cache types.
Collection<CacheTypeMetadata> meta = new ArrayList<>();
// DataLoaderMd5.
CacheTypeMetadata type = new CacheTypeMetadata();
meta.add(type);
type.setDatabaseSchema("abc");
type.setDatabaseTable("dfg");
type.setKeyType(Dataloadermd5Key.class.getName());
type.setValueType(DataLoaderMd5.class.getName());
// Key fields for DataLoaderMd5.
Collection<CacheTypeFieldMetadata> keys = new ArrayList<>();
keys.add(new CacheTypeFieldMetadata("id_client", Types.INTEGER,
"idclient", int.class));
keys.add(new CacheTypeFieldMetadata("client_prop_id", Types.VARCHAR,
"clientPropId", String.class));
type.setKeyFields(keys);
// Value fields for DataLoaderMd5.
Collection<CacheTypeFieldMetadata> vals = new ArrayList<>();
vals.add(new CacheTypeFieldMetadata("id_client", Types.INTEGER,
"idclient", int.class));
vals.add(new CacheTypeFieldMetadata("client_prop_id", Types.VARCHAR,
"clientPropId", String.class));
vals.add(new CacheTypeFieldMetadata("Md5", Types.VARCHAR,
"md5", String.class));
type.setValueFields(vals);
// Query fields for DataLoaderMd5.
Map<String, Class<?>> qryFlds = new LinkedHashMap<>();
qryFlds.put("idclient", int.class);
qryFlds.put("clientPropId", String.class);
qryFlds.put("md5", String.class);
type.setQueryFields(qryFlds);
// Groups for DataLoaderMd5.
Map<String, LinkedHashMap<String,
IgniteBiTuple<Class<?>, Boolean>>> grps = new LinkedHashMap<>();
LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> grpItems =
new LinkedHashMap<>();
grpItems.put("idclient", new IgniteBiTuple<Class<?>,
Boolean>(int.class, false));
grpItems.put("clientPropId", new IgniteBiTuple<Class<?>,
Boolean>(String.class, false));
grps.put("PRIMARY", grpItems);
type.setGroups(grps);
ccfg.setTypeMetadata(meta);
return ccfg;
}
查询:
Ignite ignite = Ignition.start("examples/config/example-cache.xml");
IgniteCache<Dataloadermd5Key, DataLoaderMd5> cache = ignite.cache(CACHE_NAME);
Dataloadermd5Key key = new Dataloadermd5Key();
key.setIdClient(98255);
key.setClientPropId("1000008");
SqlQuery<Dataloadermd5Key, DataLoaderMd5> qry =
new SqlQuery<Dataloadermd5Key, DataLoaderMd5>(
DataLoaderMd5.class, "idClient = ? and clientPropId = ?");
//Excecute query
System.out.println("sqlQuery Lookup result :: " +
cache.query(qry).getAll());
System.out.println("sqlQuery Lookup result :: " +
cache.query(qry.setArgs(key.getIdClient(), key.getClientPropId())).getAll());
我发现了问题。这是因为我的 Ignite 版本。 我将 maven 上的版本更新为 1.1.0,代码开始正常运行。
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>1.1.0-incubating</version>
</dependency>