我创建了一个简单的 Apache Ignite 设置,希望稍后将其用于 SQL,但现在我想通过 Java API 构建它。它是动态的,所以我不能使用 POJO 类进行插入。不幸的是,我收到了这个警告,并且在调试器中单步执行
GridQueryProcessor
代码没有发现明显的修复。我怀疑部分原因是我的 type()
调用始终为空(变量 b
,打印为 b=null
),但我不确定。
日志输出:
...snip
b=null
WARN GridQueryProcessor - Key-value pair is not inserted into any SQL table [cacheName=TestTable, valType=BinaryObject.TestTable_value]
WARN GridQueryProcessor - ^-- Value type(s) are specified via CacheConfiguration.indexedTypes or CacheConfiguration.queryEntities
WARN GridQueryProcessor - ^-- Make sure that same type(s) used when adding Object or BinaryObject to cache
WARN GridQueryProcessor - ^-- Otherwise, entries will be stored in cache, but not appear as SQL Table rows
--------Inserted
...snip
以及完整的源代码:
package snippet;
import java.util.*;
import javax.cache.Cache.Entry;
import org.apache.ignite.*;
import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.cache.*;
import org.apache.ignite.cache.query.*;
import org.apache.ignite.configuration.*;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder;
public class Snippet
{
public static void main(String... strings) throws InterruptedException
{
// Start up our node
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setDeploymentMode(DeploymentMode.CONTINUOUS);
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));
var ignite = Ignition.start(cfg);
System.err.println("--------Started");
Thread.sleep(1000);
///////// create table
var cachec = new CacheConfiguration<>("TestTable");
var qe = new QueryEntity();
qe.addQueryField("simpleId", Long.TYPE.getName(), null);
qe.addQueryField("stringField", String.class.getName(), null);
qe.setKeyType("TestTable_key");
qe.setIndexes(Collections.singleton(new QueryIndex("simpleId")));
qe.setValueType("TestTable_value");
// cachec.setStoreKeepBinary(true); // seems to have no effect
cachec.setQueryEntities(Collections.singleton(qe));
cachec.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
cachec.setQueryParallelism(6);
ignite.createCache(cachec);
System.err.println("--------Created");
Thread.sleep(1000);
/////// insert a row
var bb = ignite.binary().builder("BinaryObject.TestTable_value");
var b = ignite.binary().type("TestTable_value"); // always null for some reason
System.err.println(b == null ? "b=null" : "b=not null");
bb.setField("stringField", "it works!");
bb.setField("simpleId", 3l);
ignite.cache("TestTable").withKeepBinary().put(3l, bb.build());
System.err.println("--------Inserted");
Thread.sleep(1000);
/////// clean up
ignite.destroyCache("TestTable");
ignite.close();
}
}
我建议您查看有关创建和使用二进制对象的文档:https://www.gridgain.com/docs/latest/developers-guide/key-value-api/binary-objects
希望有帮助!