Is it possible to stream data into a table created by a query? For example,
consider the following modified example. If I had a Person object, how would I
replace the insert loop to improve speed?
Thanks,
Mike
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.configuration.CacheConfiguration;
public class Test {
private static final String DUMMY_CACHE_NAME = "dummy_cache";
public static void main(String[] args)
{
Ignite ignite = Ignition.start();
{
// Create dummy cache to act as an entry point for SQL queries (new
SQL API which do not require this
// will appear in future versions, JDBC and ODBC drivers do not
require it already).
CacheConfiguration<?, ?> cacheCfg = new
CacheConfiguration<>(DUMMY_CACHE_NAME).setSqlSchema("PUBLIC");
try (IgniteCache<?, ?> cache = ignite.getOrCreateCache(cacheCfg))
{
// Create reference City table based on REPLICATED template.
cache.query(new SqlFieldsQuery("CREATE TABLE city (id LONG
PRIMARY KEY, name VARCHAR) WITH \"template=replicated\"")).getAll();
// Create table based on PARTITIONED template with one backup.
cache.query(new SqlFieldsQuery("CREATE TABLE person (id LONG,
name VARCHAR, city_id LONG, PRIMARY KEY (id, city_id)) WITH
\"template=replicated\"")).getAll();
// Create an index.
cache.query(new SqlFieldsQuery("CREATE INDEX on Person
(city_id)")).getAll();
SqlFieldsQuery qry = new SqlFieldsQuery("INSERT INTO city (id,
name) VALUES (?, ?)");
cache.query(qry.setArgs(1L, "Forest Hill")).getAll();
cache.query(qry.setArgs(2L, "Denver")).getAll();
cache.query(qry.setArgs(3L, "St. Petersburg")).getAll();
qry = new SqlFieldsQuery("INSERT INTO person (id, name,
city_id) values (?, ?, ?)");
for(long i = 0; i < 100_000;++i)
{
cache.query(qry.setArgs(i, "John Doe", 3L)).getAll();
}
System.out.print("HI!");
}}}}
From: Denis Magda [mailto:[email protected]]
Sent: Thursday, February 08, 2018 7:33 PM
To: [email protected]
Subject: Re: Cat Example
Hi Mike,
If SQL indexes/configuration is set with the annotation and setIndexedTypes
method then you have to use the type name (Cat in your case) as the SQL table
name. It’s explained here:
https://apacheignite-sql.readme.io/docs/schema-and-indexes#section-annotation-based-configuration<https://urldefense.proofpoint.com/v2/url?u=https-3A__apacheignite-2Dsql.readme.io_docs_schema-2Dand-2Dindexes-23section-2Dannotation-2Dbased-2Dconfiguration&d=DwMFaQ&c=9g4MJkl2VjLjS6R4ei18BA&r=ipRRuqPnuP3BWnXGSOR_sLoARpltax56uFYU6n57c3GFvMdyEV-dz2ez2lZZpYl0&m=Nrv7gL0zYS9bFUir2zKHmI30_jJzYTzlic8Vk0kWonQ&s=UZWx1Uz419uytrzu-xRfSiuRqc3rszCQr5rJqNjT8TI&e=>
The cache name is used for IgniteCache APIs and other related methods.
—
Denis
On Feb 8, 2018, at 3:48 PM, Williams, Michael
<[email protected]<mailto:[email protected]>>
wrote:
Hi,
Quick question, submitted a ticket earlier. How would I modify the below code
such that, when viewed through Sql (dbeaver, eg) it behaves as if it had been
created through a CREATE TABLE statement, where the name of the table was
catCache? I’m trying to directly populate a series of tables that will be used
downstream primarily through SQL. I’d like to be able to go into dBeaver,
browse the tables, and see 10 cats named Fluffy, if this is working correctly.
import org.apache.ignite.cache.query.annotations.*;
import
java.io<https://urldefense.proofpoint.com/v2/url?u=http-3A__java.io_&d=DwMFaQ&c=9g4MJkl2VjLjS6R4ei18BA&r=ipRRuqPnuP3BWnXGSOR_sLoARpltax56uFYU6n57c3GFvMdyEV-dz2ez2lZZpYl0&m=Nrv7gL0zYS9bFUir2zKHmI30_jJzYTzlic8Vk0kWonQ&s=oFi3ym9G_GwhhFWtyRu--rylVH_5Vs2w_77tNCIb1Ls&e=>.*;
public class Cat implements Serializable {
@QuerySqlField
int legs;
@QuerySqlField
String name;
Cat(int l, String n)
{
legs = l;
name = n;
}
}
import org.apache.ignite.Ignition;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.QueryCursor;
import java.util.List;
public class Test {
public static void main(String[] args)
{
Ignite ignite = Ignition.start();
CacheConfiguration<Integer,Cat> cfg= new
CacheConfiguration("catCache");
cfg.setCacheMode(CacheMode.REPLICATED);
cfg.setSqlEscapeAll(true);
cfg.setSqlSchema("PUBLIC");
cfg.setIndexedTypes(Integer.class,Cat.class);
try(IgniteCache<Integer, Cat> cache = ignite.getOrCreateCache(cfg))
{
for (int i = 0; i < 10; ++i) {
cache.put(i, new Cat(i + 1,"Fluffy"));
}/*
SqlFieldsQuery sql = new SqlFieldsQuery("select * from
catCache");
try (QueryCursor<List<?>> cursor = cache.query(sql)) {
for (List<?> row : cursor)
System.out.println("cat=" + row.get(0));
}*/
}
System.out.print("Got It!");
}}
Thanks,
Mike Williams