Reputation: 758
How can I use index with Object
type?
My model have one index field
public class Model implements Serializable {
......
.....
@QuerySqlField(index = true)
private Object sortField;
}
Following command works properly-
cache.query(new SqlQuery<>(Model.class, "ORDER BY sortField")).getAll();
But when I want to do some filtering, for example:
cache.query(new SqlQuery<>(Model.class, "sortField= ?").setArgs(10)).getAll();
It brings following CacheException: Failed to run map query remotely
When I change Object
to Integer
everything works properly.
But I don't understand why ORDER BY
works but WHERE
doe not with an Object
field.
For more information you can see: http://apache-ignite-users.70518.x6.nabble.com/Cache-queries-Failed-to-run-map-query-remotely-td18378.html
Upvotes: 0
Views: 264
Reputation: 3591
Well, the lesson to learn here is that you shouldn't use Object as a field type :)
I looked through the code, so when you do that, values are treated as some "hexadimal strings". So, I guess, when you do "order by", you are actually sorting binary representations of stored values. It won't work correctly for all types, obviously, but H2 (which is an underlying SQL engine in Ignite), allows it for some reason.
And then, when you try to do filtering, using "where" clause, the argument, that you provide is also treated as a "hexadimal" string, and it fails, because "10" is not a correct hexadiamal representation of any object.
I didn't really go into the details of the whole procedure, but I hope, you get the idea.
So, if you are going to store integers in some field, just declare it as Integer
or int
.
Upvotes: 3