Re: Fwd: Re: Ignite cache query
Hello Shaleen, It looks like that you want that SQL engine would create table columns based on the hashmap which has a dynamic structure (obviously you can add and remove keys from the map simultaneously). So, every time when you add/remove a key from the map for a particular entry, SQL engine should automatically add/remove the corresponding column. I don't think it is possible. I see only the one way, that can be used here. This is a user-defined function [1] public class Pojo { @QuerySqlField private Map<String, Object> map; @QuerySqlFunction public static String get(Map<String, Object> field, String id) { return map.get(id); } ... } In that case, you can use this custom function as follows: select * from Pojo where get(map,?)=? Though you will not be able to use indexes this way. [1] https://apacheignite-sql.readme.io/docs/custom-sql-functions Thanks. 2018-04-24 9:00 GMT+03:00 Shaleen Sharma <sharma.shal...@hotmail.com>: > Hi All > > Is there anything anyone has to say about the below issue? > > Thanks > Shaleen > > *From:* Shaleen Sharma <sharma.shal...@hotmail.com> > *Sent:* Monday, April 23, 2018 4:04:13 PM > *To:* user@ignite.apache.org; user@ignite.apache.org > *Subject:* Re: Ignite cache query > > Thanks for your reply. > > Forgot to mention earlier that I am already using @QuerySqlField on each > field of my Pojo class so all the fields are appearing as table columns but > the hashmap doesn't. So how do i use @QuerySqlField on a hashmap so that > each key of hashmap also behaves as a table column which I can use to do an > "order by" in my sql. > > Thanks > Shaleen > > > > From: begineer > Sent: Monday, 23 April, 3:53 pm > Subject: Re: Ignite cache query > To: user@ignite.apache.org > > > e.g. public class Student { @QuerySqlField(index=true) int id; > @QuerySqlField String name ; @QuerySqlField LocalDateTime dob; > @QuerySqlField LocalDate dos; @QuerySqlField Map> map = new HashMap config > = new CacheConfiguration cache = ignite.getOrCreateCache(config); > DateTimeFormatter formatter = DateTimeFormatter.ofPattern("-MM-dd > H:mm"); LocalDateTime time1= LocalDateTime.now(); String s = > time1.format(formatter); LocalDateTime time = LocalDateTime.parse(s, > formatter); Map> map = new HashMap query = new SqlQuery list = > cache.query(query).getAll().stream().map(Cache.Entry:: > getValue).collect(Collectors.toList()); -- Sent from: > http://apache-ignite-users.70518.x6.nabble.com/ > > > >
Re: Fwd: Re: Ignite cache query
Hi All Is there anything anyone has to say about the below issue? Thanks Shaleen From: Shaleen Sharma <sharma.shal...@hotmail.com> Sent: Monday, April 23, 2018 4:04:13 PM To: user@ignite.apache.org; user@ignite.apache.org Subject: Re: Ignite cache query Thanks for your reply. Forgot to mention earlier that I am already using @QuerySqlField on each field of my Pojo class so all the fields are appearing as table columns but the hashmap doesn't. So how do i use @QuerySqlField on a hashmap so that each key of hashmap also behaves as a table column which I can use to do an "order by" in my sql. Thanks Shaleen From: begineer Sent: Monday, 23 April, 3:53 pm Subject: Re: Ignite cache query To: user@ignite.apache.org e.g. public class Student { @QuerySqlField(index=true) int id; @QuerySqlField String name ; @QuerySqlField LocalDateTime dob; @QuerySqlField LocalDate dos; @QuerySqlField Map> map = new HashMap config = new CacheConfiguration cache = ignite.getOrCreateCache(config); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("-MM-dd H:mm"); LocalDateTime time1= LocalDateTime.now(); String s = time1.format(formatter); LocalDateTime time = LocalDateTime.parse(s, formatter); Map> map = new HashMap query = new SqlQuery list = cache.query(query).getAll().stream().map(Cache.Entry::getValue).collect(Collectors.toList()); -- Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Ignite cache query
Thanks for your reply. Forgot to mention earlier that I am already using @QuerySqlField on each field of my Pojo class so all the fields are appearing as table columns but the hashmap doesn't. So how do i use @QuerySqlField on a hashmap so that each key of hashmap also behaves as a table column which I can use to do an "order by" in my sql. Thanks Shaleen From: begineer Sent: Monday, 23 April, 3:53 pm Subject: Re: Ignite cache query To: user@ignite.apache.org e.g. public class Student { @QuerySqlField(index=true) int id; @QuerySqlField String name ; @QuerySqlField LocalDateTime dob; @QuerySqlField LocalDate dos; @QuerySqlField Map> map = new HashMap config = new CacheConfiguration cache = ignite.getOrCreateCache(config); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("-MM-dd H:mm"); LocalDateTime time1= LocalDateTime.now(); String s = time1.format(formatter); LocalDateTime time = LocalDateTime.parse(s, formatter); Map> map = new HashMap query = new SqlQuery list = cache.query(query).getAll().stream().map(Cache.Entry::getValue).collect(Collectors.toList()); -- Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Ignite cache query
e.g. public class Student { @QuerySqlField(index=true) int id; @QuerySqlField String name ; @QuerySqlField LocalDateTime dob; @QuerySqlField LocalDate dos; @QuerySqlField Map> map = new HashMap<>(); } Now you can do something like this. Ignite ignite = Ignition.start("examples/config/example-ignite.xml"); CacheConfiguration config = new CacheConfiguration<>("mycache"); config.setIndexedTypes(Integer.class, Student.class); IgniteCache cache = ignite.getOrCreateCache(config); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("-MM-dd H:mm"); LocalDateTime time1= LocalDateTime.now(); String s = time1.format(formatter); LocalDateTime time = LocalDateTime.parse(s, formatter); Map > map = new HashMap<>(); map.put("Key1", Arrays.asList(new Serializable[]{"value1", "value2"})); Student s1 = new Student(time, 1, "joe",time.toLocalDate(),map); Student s2 = new Student(time, 2, "Lee",time.toLocalDate(),map); cache.put(s1.getId(), s1); cache.put(s2.getId(), s2); SqlQuery query = new SqlQuery<>(Student.class, "select * from student where dos =?"); query.setArgs(time.toLocalDate()); List list = cache.query(query).getAll().stream().map(Cache.Entry::getValue).collect(Collectors.toList()); -- Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Ignite cache query
You need to annotate you POJO fields with @QuerySqlField. This annotation will make them visible to SQL queries on the cache. Also, you can add indexes to these fields for better performance. Both, Java and XML configurations are available See https://apacheignite.readme.io/docs/cache-queries#sql-queries for details -- Sent from: http://apache-ignite-users.70518.x6.nabble.com/