use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest method testUpdateAllJsr310Fields.
/**
* Tests updating of all JSR-310 fields.
*/
public void testUpdateAllJsr310Fields() {
EntityWithJsr310Fields expEntity = new EntityWithJsr310Fields(entity);
expEntity.setLocalTime(expEntity.getLocalTime().plusHours(1));
expEntity.setLocalDate(expEntity.getLocalDate().plusDays(1));
expEntity.setLocalDateTime(LocalDateTime.of(expEntity.getLocalDate(), expEntity.getLocalTime()));
SqlFieldsQuery qry = new SqlFieldsQuery("update EntityWithJsr310Fields set locTime = ?, locDate = ?, locDateTime = ? where id = ?").setArgs(expEntity.getLocalTime(), expEntity.getLocalDate(), expEntity.getLocalDateTime(), entity.getId());
List<List<?>> qryResults = cache.query(qry).getAll();
assertEquals(1, qryResults.size());
assertEquals(1L, qryResults.get(0).get(0));
assertEquals(expEntity, cache.get(expEntity.getId()));
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest method testDateDiffForLocalDateTimeFieldAtMidnight.
/**
* Tests that DATEDIFF SQL function works for {@link LocalDateTime}
* fields with the time part set to midnight.
*
* @throws Exception If failed.
*/
public void testDateDiffForLocalDateTimeFieldAtMidnight() throws Exception {
SqlFieldsQuery qry = new SqlFieldsQuery("select DATEDIFF('DAY', locDateTime, CURRENT_DATE ()) from EntityWithJsr310Fields");
List<List<?>> qryResults = cache.query(qry).getAll();
assertEquals(1, qryResults.size());
assertTrue((Long) qryResults.get(0).get(0) >= DAYS_BEFORE_NOW);
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest method testSelectLocalTimeFieldReturnsTime.
/**
* Tests that selection for a {@link LocalTime} field returns {@link Time}.
*
* @throws Exception If failed.
*/
public void testSelectLocalTimeFieldReturnsTime() throws Exception {
SqlFieldsQuery qry = new SqlFieldsQuery("select locTime from EntityWithJsr310Fields");
List<List<?>> qryResults = cache.query(qry).getAll();
assertEquals(1, qryResults.size());
assertEquals(Time.class, qryResults.get(0).get(0).getClass());
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class GAGrid method getChromosomesByFittest.
/**
* helper routine to retrieve Chromosome keys in order of fittest
*
* @return List of primary keys for chromosomes.
*/
private List<Long> getChromosomesByFittest() {
List<Long> orderChromKeysByFittest = new ArrayList();
String orderDirection = "desc";
if (config.isHigherFitnessValueFitter() == false) {
orderDirection = "asc";
}
String fittestSQL = "select _key from Chromosome order by fitnessScore " + orderDirection;
// Execute query to retrieve keys for ALL Chromosomes by fittnessScore
QueryCursor<List<?>> cursor = populationCache.query(new SqlFieldsQuery(fittestSQL));
List<List<?>> res = cursor.getAll();
for (List row : res) {
Long key = (Long) row.get(0);
orderChromKeysByFittest.add(key);
}
return orderChromKeysByFittest;
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class IgniteSqlSplitterSelfTest method checkQueryWithGroupsAndAggrs.
/**
* Query with aggregates and groups
*/
private void checkQueryWithGroupsAndAggrs(IgniteCache<Integer, Value> cache) {
try (QueryCursor<List<?>> qry = cache.query(new SqlFieldsQuery("SELECT fst, count(snd), sum(snd), avg(snd), avg(CAST(snd AS DOUBLE)), " + "min(snd), max(snd) FROM Value GROUP BY fst ORDER BY fst"))) {
List<List<?>> result = qry.getAll();
assertEquals(6, result.size());
List<?> row = result.get(0);
assertEquals("fst", 1, ((Number) row.get(0)).intValue());
assertEquals("count", 3L, ((Number) row.get(1)).longValue());
assertEquals("sum", 9L, ((Number) row.get(2)).longValue());
assertEquals("avg", 3, ((Number) row.get(3)).doubleValue(), 0.001);
assertEquals("avg dbl", 3d, ((Number) row.get(4)).doubleValue(), 0.001);
assertEquals("min", 3, ((Integer) row.get(5)).intValue());
assertEquals("max", 3, ((Integer) row.get(6)).intValue());
row = result.get(1);
assertEquals("fst", 2, ((Number) row.get(0)).intValue());
assertEquals("count", 3L, ((Number) row.get(1)).longValue());
assertEquals("sum", 6L, ((Number) row.get(2)).longValue());
assertEquals("avg", 2, ((Number) row.get(3)).doubleValue(), 0.001);
assertEquals("avg dbl", 2d, ((Number) row.get(4)).doubleValue(), 0.001);
assertEquals("min", 1, ((Integer) row.get(5)).intValue());
assertEquals("max", 3, ((Integer) row.get(6)).intValue());
row = result.get(2);
assertEquals("fst", 3, ((Number) row.get(0)).intValue());
assertEquals("count", 6L, ((Number) row.get(1)).longValue());
assertEquals("sum", 9L, ((Number) row.get(2)).longValue());
assertEquals("avg", 1, ((Integer) row.get(3)).intValue());
assertEquals("avg dbl", 1.5d, ((Number) row.get(4)).doubleValue(), 0.001);
assertEquals("min", 1, ((Integer) row.get(5)).intValue());
assertEquals("max", 2, ((Integer) row.get(6)).intValue());
}
}
Aggregations