Issue with running SQL Scan queries in Apache Ignite in clientmode -
i trying start testing sql in apache ignite using following code.
public void testsqldatabase(){ cacheconfiguration<long, person> cachecfg = new cacheconfiguration<>(); cachecfg.setname("mycache"); cachecfg.setcachemode(cachemode.partitioned); cachecfg.setindexedtypes(long.class, person.class); // setting query entity. queryentity queryentity = new queryentity(); queryentity.setkeytype(long.class.getname()); queryentity.setvaluetype(person.class.getname()); // listing query fields. linkedhashmap<string, string> fields = new linkedhashmap(); fields.put("id", long.class.getname()); fields.put("orgid", long.class.getname()); fields.put("firstname", string.class.getname()); fields.put("lastname", string.class.getname()); fields.put("resume", string.class.getname()); fields.put("salary", double.class.getname()); queryentity.setfields(fields); // listing indexes. collection<queryindex> indexes = new arraylist<>(3); indexes.add(new queryindex("id")); indexes.add(new queryindex("orgid")); indexes.add(new queryindex("salary")); queryentity.setindexes(indexes); cachecfg.setqueryentities(arrays.aslist(queryentity)); ignitecache<long, person> cache = ignite.getorcreatecache(cachecfg); cache.clear(); for(long icount = 0; icount < 10000; icount++) { person person = new person(); person.setvalues(icount, 0, "a", "a", "asdf", icount*100); cache.put(icount, person); system.out.println("got " + cache.get(icount).tostring()); } ignitebipredicate<long, person> filter = new ignitebipredicate<long, person>() { @override public boolean apply(long key, person p) { return p.getsalary() > 10000d; } }; try (querycursor cursor = cache.query(new scanquery(filter))) { system.out.println(cursor.tostring()); (object p : cursor) system.out.println(p.tostring()); } } public class person implements serializable { /** * person id (indexed). */ @querysqlfield(index = true) private long id; /** * organization id (indexed). */ @querysqlfield(index = true) private long orgid; /** * first name (not-indexed). */ @querysqlfield private string firstname; /** * last name (not indexed). */ @querysqlfield private string lastname; /** * resume text (create lucene-based text index field). */ @querytextfield private string resume; /** * salary (indexed). */ @querysqlfield(index = true) private double salary; public void setvalues(long id, long orgid, string firstname, string lastname, string resume, double salary){ this.id = id; this.orgid = orgid; this.firstname = firstname; this.lastname = lastname; this.resume = resume; this.salary = salary; } public long getid() { return id; } public void setid(long id) { this.id = id; } public long getorgid() { return orgid; } public void setorgid(long orgid) { this.orgid = orgid; } public string getfirstname() { return firstname; } public void setfirstname(string firstname) { this.firstname = firstname; } public string getlastname() { return lastname; } public void setlastname(string lastname) { this.lastname = lastname; } public string getresume() { return resume; } public void setresume(string resume) { this.resume = resume; } public double getsalary() { return salary; } public void setsalary(double salary) { this.salary = salary; } }
but exception thrown in last try go on cursor after scan query.
java.lang.reflect.invocationtargetexception @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) ... caused by: javax.cache.cacheexception: class org.apache.ignite.ignitecheckedexception: query execution failed: gridcachequerybean [qry=gridcachequeryadapter [type=scan, clsname=null, clause=null, filter=co.near.ignite.mainexperiment$1@4c1d79bc, part=null, incmeta=false, metrics=gridcachequerymetricsadapter [mintime=0, maxtime=0, sumtime=0, avgtime=0.0, execs=0, completed=0, fails=0], pagesize=1024, timeout=0, keepall=true, incbackups=false, dedup=false, prj=null, keepbinary=false, subjid=ca184604-5d57-4549-a2a2-b8601d9062ab, taskhash=0], rdc=null, trans=null] @ org.apache.ignite.internal.processors.cache.gridcacheutils.converttocacheexception(gridcacheutils.java:1618) ... 6 more caused by: class org.apache.ignite.ignitecheckedexception: query execution failed: gridcachequerybean [qry=gridcachequeryadapter [type=scan, clsname=null, clause=null, filter=co.near.ignite.mainexperiment$1@4c1d79bc, part=null, incmeta=false, metrics=gridcachequerymetricsadapter [mintime=0, maxtime=0, sumtime=0, avgtime=0.0, execs=0, completed=0, fails=0], pagesize=1024, timeout=0, keepall=true, incbackups=false, dedup=false, prj=null, keepbinary=false, subjid=ca184604-5d57-4549-a2a2-b8601d9062ab, taskhash=0], rdc=null, trans=null] @ org.apache.ignite.internal.processors.cache.query.gridcachequeryfutureadapter.checkerror(gridcachequeryfutureadapter.java:267) @ org.apache.ignite.internal.processors.cache.query.gridcachequeryfutureadapter.internaliterator(gridcachequeryfutureadapter.java:325) @ org.apache.ignite.internal.processors.cache.query.gridcachequeryfutureadapter.next(gridcachequeryfutureadapter.java:171) ... 11 more caused by: class org.apache.ignite.ignitecheckedexception: failed execute query on node [query=gridcachequerybean [qry=gridcachequeryadapter [type=scan, clsname=null, clause=null, filter=co.near.ignite.mainexperiment$1@4c1d79bc, part=null, incmeta=false, metrics=gridcachequerymetricsadapter [mintime=0, maxtime=0, sumtime=0, avgtime=0.0, execs=0, completed=0, fails=0], pagesize=1024, timeout=0, keepall=true, incbackups=false, dedup=false, prj=null, keepbinary=false, subjid=ca184604-5d57-4549-a2a2-b8601d9062ab, taskhash=0], rdc=null, trans=null], nodeid=06118f33-33b0-4483-bab2-fcc2306a4053] @ org.apache.ignite.internal.processors.cache.query.gridcachequeryfutureadapter.onpage(gridcachequeryfutureadapter.java:390) @ org.apache.ignite.internal.managers.communication.gridiomanager.access$1800(gridiomanager.java:103) @ org.apache.ignite.internal.managers.communication.gridiomanager$6.run(gridiomanager.java:972) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) ... 1 more caused by: class org.apache.ignite.ignitecheckedexception: co.near.ignite.mainexperiment$person @ org.apache.ignite.internal.util.igniteutils.cast(igniteutils.java:7005) @ org.apache.ignite.internal.util.future.gridfutureadapter.get0(gridfutureadapter.java:166) @ org.apache.ignite.internal.util.future.gridfutureadapter.get(gridfutureadapter.java:115) @ org.apache.ignite.internal.processors.cache.query.gridcachequerymanager$cachedresult.iterator(gridcachequerymanager.java:2825) @ org.apache.ignite.internal.processors.cache.query.gridcachequerymanager.runquery(gridcachequerymanager.java:1390) ... 3 more caused by: java.lang.classnotfoundexception: co.near.ignite.mainexperiment$person @ java.net.urlclassloader.findclass(urlclassloader.java:381) ... 14 more
since started trying out apache ignite, doing wrong. great if let me know how fix this.
also running code in client mode , not server. 3-node cluster running separately.
you're running predicate-based scan query. query invokes filter provide on server nodes, data you're interested in returned. implementation expects person class there, error. there 2 options fix it:
- (recommended) use
withkeepbinary()
flag ,binaryobject
instead ofperson
object. seescanquery()
method in [1] example. - add
person
class classpath of server nodes.
Comments
Post a Comment