Dear all,

I am trying to use the SqlFieldsQuery sdk to insert data to one cache on Ignite.

I can insert one data into one cache at a time.

However, I have no idea to insert multiple rows/data into the cache once.

For example, I would like to insert 1000 rows/data into the cache once.

Here, I provide my code to everyone to reproduce my situation.
public class IgniteCreateServer {
public class Person {
 @QuerySqlField
 private String firstName;
  @QuerySqlField
  private String lastName;
  public Person(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
  }
}
public static void main(String[] args) {
cacheConf.setName("igniteCache");
cacheConf.setIndexedTypes(String.class, String.class);
cacheConf.setCacheMode(CacheMode.REPLICATED);
cacheConf.setAtomicityMode(CacheAtomicityMode.ATOMIC);
  cfg.setCacheConfiguration(cacheConf);
  Ignite igniteNode = Ignition.getOrStart(cfg);
  IgniteCache cacheKeyvalue = igniteNode.getOrCreateCache(cacheConf);

long starttime, endtime;
starttime = System.currentTimeMillis();
int datasize = 100000;
for (int i = 0; i < datasize; i++) {
    cacheKeyvalue.put("key " + Integer.toString(i), Integer.toString(i));
}
  endtime = System.currentTimeMillis();
  System.out.println("write " + datasize + " pairkeyvalue data: spend " + 
(endtime - starttime)  + "milliseconds");
//=================================================================================================================

cacheCfg.setName("personCache");
cacheCfg.setIndexedTypes(String.class, Person.class);
cacheCfg.setCacheMode(CacheMode.REPLICATED);
cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
IgniteCache cacheKeyTable = igniteNode.getOrCreateCache(cacheCfg);

long starttime1, endtime1;
starttime1 = System.currentTimeMillis();
for (int i = 0; i < datasize; i++) {
cacheKeyTable.query(new SqlFieldsQuery("INSERT INTO 
Person(_key,firstName,lastName) VALUES(?,?,?)")
.setArgs(i, "key " + Integer.toString(i), Integer.toString(i)));
}
endtime1 = System.currentTimeMillis();
System.out.println("write" + datasize + " table data: spend " + (endtime1 - 
starttime1)  + "milliseconds");
}

The my code show as:
“write 100000 pairkeyvalue data: spend 4734 milliseconds
write 100000 table data: spend 2846 milliseconds”

From the above result, I feel that using the SQL to insert data to cache is 
faster than using cache.getall().

I am not sure if this is correct or not?

In addition, that is important for me to insert data into cache via the use of 
SQL,
so I would like to insert multiple rows/data to accelerate it.

if any further information is needed, I am glad to be informed and will provide 
to you as soon as possible.

Thanks

Rick







--
本信件可能包含工研院機密資訊,非指定之收件者,請勿使用或揭露本信件內容,並請銷毀此信件。 This email may contain 
confidential information. Please do not use or disclose it in any way and 
delete it if you are not the intended recipient.

Reply via email to