use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteCacheDistributedJoinTest method checkSameResult.
/**
* @param s Statement.
* @param c Cache.
* @param qry Query.
* @throws SQLException If failed.
*/
private <Z extends X> void checkSameResult(Statement s, IgniteCache<Integer, Z> c, String qry) throws SQLException {
s.executeUpdate("SET SCHEMA " + c.getName());
try (ResultSet rs1 = s.executeQuery(qry);
QueryCursor<List<?>> rs2 = c.query(new SqlFieldsQuery(qry).setDistributedJoins(true))) {
Iterator<List<?>> iter = rs2.iterator();
for (; ; ) {
if (!rs1.next()) {
assertFalse(iter.hasNext());
return;
}
assertTrue(iter.hasNext());
List<?> row = iter.next();
for (int i = 0; i < row.size(); i++) assertEquals(rs1.getLong(i + 1), row.get(i));
}
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteCacheInsertSqlQuerySelfTest method testInsertFromSubquery.
/**
*
*/
public void testInsertFromSubquery() {
IgniteCache p = ignite(0).cache("S2P").withKeepBinary();
p.query(new SqlFieldsQuery("insert into String (_key, _val) values ('s', ?), " + "('a', ?)").setArgs("Sergi", "Alex").setLocal(true));
assertEquals("Sergi", p.get("s"));
assertEquals("Alex", p.get("a"));
p.query(new SqlFieldsQuery("insert into Person(_key, id, firstName) " + "(select substring(lower(_val), 0, 2), cast(length(_val) as int), _val from String)"));
assertEquals(createPerson(5, "Sergi"), p.get("se"));
assertEquals(createPerson(4, "Alex"), p.get("al"));
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteCacheInsertSqlQuerySelfTest method testUuidHandling.
/**
*
*/
public void testUuidHandling() {
IgniteCache<UUID, Integer> p = ignite(0).cache("U2I");
UUID id = UUID.randomUUID();
p.query(new SqlFieldsQuery("insert into Integer(_key, _val) values (?, ?)").setArgs(id, 1));
assertEquals(1, (int) p.get(id));
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteCacheInsertSqlQuerySelfTest method testNestedFieldsHandling.
/**
*
*/
public void testNestedFieldsHandling() {
IgniteCache<Integer, AllTypes> p = ignite(0).cache("I2AT");
p.query(new SqlFieldsQuery("insert into AllTypes(_key, innerTypeCol, arrListCol, _val, innerStrCol) values (1, ?, ?, ?, 'sss')").setArgs(new AllTypes.InnerType(50L), new ArrayList<>(Arrays.asList(3L, 2L, 1L)), new AllTypes(1L)));
AllTypes res = p.get(1);
AllTypes.InnerType resInner = new AllTypes.InnerType(50L);
resInner.innerStrCol = "sss";
resInner.arrListCol = new ArrayList<>(Arrays.asList(3L, 2L, 1L));
assertEquals(resInner, res.innerTypeCol);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheAbstractQueryMetricsSelfTest method testSqlFieldsQueryMetrics.
/**
* Test metrics for SQL fields queries.
*
* @throws Exception In case of error.
*/
public void testSqlFieldsQueryMetrics() throws Exception {
IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
SqlFieldsQuery qry = new SqlFieldsQuery("select * from String");
checkQueryMetrics(cache, qry);
}
Aggregations