I have created a simple Apache Ignite setup that I hope to use for SQL later, but I want to construct it via the Java API for now. It is intended to be dynamic, so I can’t use a POJO class for insertion. Unfortunately, I get this warning, and stepping through the GridQueryProcessor
code in a debugger reveals no obvious fixes. I suspect that part of it is that my type()
call is always null (variable b
, printed as b=null
), but I’m not sure.
Log output:
...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
And the full source code:
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();
}
}