Refine search
private static int querySize(IgniteCache<?, ?> cache, String qry) { return cache.query(new SqlFieldsQuery(qry)).getAll().size(); }
/** * @param cache Cache. * @param type Value type. * @param expCnt Expected count. */ private void checkCount1(IgniteCache cache, Class type, long expCnt) { SqlFieldsQuery qry = new SqlFieldsQuery("select _key, _val from " + type.getSimpleName()); List<List<?>> res = cache.query(qry).getAll(); assertEquals(expCnt, res.size()); for (List<?> res0 : res) assertEquals(type, res0.get(1).getClass()); }
/** * @param cache Cache. * @param type Value type. * @param expCnt Expected count. */ private void checkCount2(IgniteCache cache, Class type, long expCnt) { SqlFieldsQuery qry = new SqlFieldsQuery("select _key, _val from " + type.getSimpleName() + " where name='a'"); List<List<?>> res = cache.query(qry).getAll(); assertEquals(expCnt, res.size()); for (List<?> res0 : res) assertEquals(type, res0.get(1).getClass()); }
/** */ private void checkSelect(IgniteCache<?, ?> cache, String selectQry, Object ... expected) { QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(selectQry)); List<List<?>> results = cursor.getAll(); assertEquals(1, results.size()); List<?> row0 = results.get(0); for(int col = 0; col < expected.length; ++col) assertEquals(expected[col], row0.get(col)); }
/** */ private GridCacheVersion getVersion(IgniteCache<?, ?> cache, int key) { QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select _ver from Person where id = ?").setArgs(key)); List<List<?>> results = cursor.getAll(); assertEquals(1, results.size()); return ((GridCacheVersion) results.get(0).get(0)); }
/** * @param ignite Ignite. * @param orgId Organization id. * @return Count of found Person object with specified orgId */ private static int getPersonsCountBySqlFieldLocalQuery(final IgniteEx ignite, int orgId) { List res = ignite.cache(Person.class.getSimpleName()) .query(new SqlFieldsQuery( String.format("SELECT p.id FROM \"%s\".Person as p " + "WHERE p.orgId = " + orgId, Person.class.getSimpleName())).setLocal(true)) .getAll(); return res.size(); }
/** * Tests that selection for a {@link LocalTime} field returns {@link Time}. * * @throws Exception If failed. */ @Test public void testSelectLocalTimeFieldReturnsTime() throws Exception { SqlFieldsQuery qry = new SqlFieldsQuery("select locTime from EntityWithDateTimeFields"); List<List<?>> qryResults = cache.query(qry).getAll(); assertEquals(1, qryResults.size()); assertEquals(Time.class, qryResults.get(0).get(0).getClass()); }
/** * Tests that selection for a {@link LocalDate} field returns {@link Date}. * * @throws Exception If failed. */ @Test public void testSelectLocalDateFieldReturnsDate() throws Exception { SqlFieldsQuery qry = new SqlFieldsQuery("select locDate from EntityWithDateTimeFields"); List<List<?>> qryResults = cache.query(qry).getAll(); assertEquals(1, qryResults.size()); assertEquals(Date.class, qryResults.get(0).get(0).getClass()); }
/** * Tests that selection for a {@link LocalDateTime} field returns {@link Timestamp}. * * @throws Exception If failed. */ @Test public void testSelectLocalDateTimeFieldReturnsTimestamp() throws Exception { SqlFieldsQuery qry = new SqlFieldsQuery("select locDateTime from EntityWithDateTimeFields"); List<List<?>> qryResults = cache.query(qry).getAll(); assertEquals(1, qryResults.size()); assertEquals(Timestamp.class, qryResults.get(0).get(0).getClass()); }
/** * Tests that DATEDIFF SQL function works for {@link LocalDateTime} * fields with the time part set to midnight. * * @throws Exception If failed. */ @Test public void testDateDiffForLocalDateTimeFieldAtMidnight() throws Exception { SqlFieldsQuery qry = new SqlFieldsQuery("select DATEDIFF('DAY', locDateTime, CURRENT_DATE ()) from EntityWithDateTimeFields"); List<List<?>> qryResults = cache.query(qry).getAll(); assertEquals(1, qryResults.size()); assertTrue((Long)qryResults.get(0).get(0) >= DAYS_BEFORE_NOW); }
/** Check min() and max() on empty cache */ @Test public void testQueryMinMaxEmptyCache() throws Exception { try (Ignite client = startGrid("client")) { IgniteCache<Integer, ValueObj> cache = client.cache(CACHE_NAME_2); QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select min(idxVal), max(idxVal) from ValueObj")); List<List<?>> result = cursor.getAll(); assertEquals(1, result.size()); assertEquals(2, result.get(0).size()); assertNull(result.get(0).get(0)); assertNull(result.get(0).get(1)); } }
@Override public boolean apply() { return cache.query(new SqlQuery<Integer, Integer>(Integer.class, "1=1")).getAll().size() == 5 && cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll().size() == 5; } }, 5000);
/** * @param nodeIdx Node index. * @param sql Sql query. */ private void userSql(int nodeIdx, String sql) { List<List<?>> res = grid(nodeIdx).context().query().querySqlFields( new SqlFieldsQuery(sql), false).getAll(); assertEquals(1, res.size()); assertEquals(1, res.get(0).size()); assertEquals(0L, res.get(0).get(0)); } }
/** */ @Test public void testUnicastQueryKeyTypeConversionConstant() throws Exception { IgniteCache<Integer, Person> cache = grid(NODE_CLIENT).cache(CACHE_PERSON); // Use string within expression against integer key List<List<?>> result = runQueryEnsureUnicast(cache, new SqlFieldsQuery("select name, age from Person where _key = '5'"), 1); Person person = cache.get(5); assertEquals(1, result.size()); assertEquals(person.name, result.get(0).get(0)); assertEquals(person.age, result.get(0).get(1)); }
/** * @throws Exception If failed. */ @Test public void testApiQueries() throws Exception { IgniteCache<Object,Object> c = ignite.cache(PART_CACHE_NAME); c.query(new SqlFieldsQuery("select cast(? as varchar) from FactPurchase").setArgs("aaa")).getAll(); List<List<?>> res = c.query(new SqlFieldsQuery("select cast(? as varchar), id " + "from FactPurchase order by id limit ? offset ?").setArgs("aaa", 1, 1)).getAll(); assertEquals(1, res.size()); assertEquals("aaa", res.get(0).get(0)); }
/** */ private void checkSelectAll(IgniteCache<Key, Val> cache) { List<List<?>> data = cache.query(new SqlFieldsQuery("select _key, _val from Val")).getAll(); assertEquals(100, data.size()); for (List<?> row : data) { Key key = (Key) row.get(0); Val val = (Val) row.get(1); long i = key.keyLong; assertEquals(key(i), key); assertEquals(val(i), val); } }
/** */ private void checkSelectStringEqual(IgniteCache<Key, Val> cache) { final String STR = "foo011"; final long LONG = 11; List<List<?>> data = cache.query(new SqlFieldsQuery("select _key, _val from Val where keyStr = ?") .setArgs(STR)) .getAll(); assertEquals(1, data.size()); List<?> row = data.get(0); assertEquals(key(LONG), row.get(0)); assertEquals(val(LONG), row.get(1)); }
/** */ private void checkSelectLongEqual(IgniteCache<Key, Val> cache) { final long LONG = 42; List<List<?>> data = cache.query(new SqlFieldsQuery("select _key, _val from Val where valLong = ?") .setArgs(LONG)) .getAll(); assertEquals(1, data.size()); List<?> row = data.get(0); assertEquals(key(LONG), row.get(0)); assertEquals(val(LONG), row.get(1)); }
/** * @throws Exception if failed. */ private void checkCache(IgniteCache<Integer, IndexedType> cache) throws Exception { for (int i = 0; i < 1000; i++) cache.put(i, new IndexedType(i)); List<List<?>> res = cache.query(new SqlFieldsQuery("select avg(iVal) from IndexedType where iVal > ?") .setArgs(499)).getAll(); assertEquals(1, res.size()); assertEquals(1, res.get(0).size()); }
/** */ private void checkQuery(IgniteCache<Object, Object> cache, String sql, Object arg) { SqlFieldsQuery qry = new SqlFieldsQuery(sql).setArgs(arg); QueryCursor<List<?>> query = cache.query(qry); List<List<?>> res = query.getAll(); assertEquals(1, res.size()); Object val = res.get(0).get(0); assertNotNull(val); assertTrue(val instanceof Student); assertEquals(VALUE_OBJ, val); }