'how to load the SQL tables data into ignite cache in table format?

Loading sql table data into ignite cache but its getting loaded in key value pairs but i would need to load in table format, can you please advise? Sample code snippet:

IgniteCache<Integer, BinaryObject> binaryCache = ignite.createCache(cacheName).withKeepBinary(); BinaryObjectBuilder builder = ignite.binary().builder(cacheName); builder.setField(columnsName, sourceResultSet.getString(values)); } binaryCache.put(resultSetRowCount, builder.build()); }



Solution 1:[1]

Ignite is a key-value database with SQL support. It's entirely valid to load data into a table using the key-value API and query it using SQL.

You need to define the table structure when you create your cache. Since you don't to use model classes/annotations, you'll need to use query entities.

Example from the documentation:

class Person implements Serializable {
    private long id;

    private String name;

    private int age;

    private float salary;
}

public static void main(String[] args) {
    Ignite ignite = Ignition.start();
    CacheConfiguration<Long, Person> personCacheCfg = new CacheConfiguration<Long, Person>();
    personCacheCfg.setName("Person");

    QueryEntity queryEntity = new QueryEntity(Long.class, Person.class)
            .addQueryField("id", Long.class.getName(), null).addQueryField("age", Integer.class.getName(), null)
            .addQueryField("salary", Float.class.getName(), null)
            .addQueryField("name", String.class.getName(), null);

    queryEntity.setIndexes(Arrays.asList(new QueryIndex("id"), new QueryIndex("salary", false)));

    personCacheCfg.setQueryEntities(Arrays.asList(queryEntity));

    IgniteCache<Long, Person> cache = ignite.createCache(personCacheCfg);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stephen Darlington