@Override public Void call() throws Exception { clientCache.query(new SqlFieldsQuery("SELECT * FROM INTEGER ORDER BY _val")).getAll(); return null; } }, CacheServerNotFoundException.class, "Failed to find data nodes for cache");
@Override public Void call() throws Exception { clientCache.query(new SqlFieldsQuery("UPDATE Integer SET _val=42 WHERE _key IN (SELECT DISTINCT _val FROM INTEGER)")).getAll(); return null; } }, CacheServerNotFoundException.class, "Failed to find data nodes for cache");
/** * @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()); }
/** * 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()); }
/** * Executes sql query using native sql api. * * @param sql sql query. * @param local perform local or non-local query. * @return fully fetched result of query. */ private List<List<?>> execute(String sql, boolean local) { return cache.query(new SqlFieldsQuery(sql).setLocal(local)).getAll(); }
/** * @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)); }
/** * Test non-colocated join. * * @throws Exception If failed. */ @Test public void testJoinNonCollocated() throws Exception { SqlFieldsQuery qry = new SqlFieldsQuery("SELECT COUNT(*) FROM PartValue p, RepValue r WHERE p.repId=r.id"); long cnt = (Long)grid(NODE_CLI).cache(CACHE_PARTITIONED).query(qry).getAll().get(0).get(0); assertEquals(PART_CNT, cnt); }
/** * @throws SQLException If failed. */ @Test public void testExecuteUpdate() throws SQLException { conn.createStatement().executeUpdate("update Person set firstName = 'Jack' where " + "cast(substring(_key, 2, 1) as int) % 2 = 0"); assertEquals(Arrays.asList(F.asList("John"), F.asList("Jack"), F.asList("Mike")), jcache(0).query(new SqlFieldsQuery("select firstName from Person order by _key")).getAll()); } }
/** * Executes SQL command. * * @param sql SQL command. */ private void execute(String sql) { jcache().query(new SqlFieldsQuery(sql).setSchema("PUBLIC")).getAll(); }
/** * @param c Cache. * @param qry Query. * @param args Arguments. * @return Column as list. */ private static <X> List<X> columnQuery(IgniteCache<?, ?> c, String qry, Object... args) { return column(0, c.query(new SqlFieldsQuery(qry).setArgs(args)).getAll()); }
/** * Execute SQL statement on given node. * * @param node Node. * @param sql Statement. */ protected List<List<?>> execute(Ignite node, String sql) { return queryProcessor(node).querySqlFields(new SqlFieldsQuery(sql).setSchema("PUBLIC"), true).getAll(); }
/** * Execute prepared SQL fields query. * * @param qry Query. * @return Result. */ private List<List<?>> executeSqlFieldsQuery(SqlFieldsQuery qry) { return client().context().query().querySqlFields(qry, false).getAll(); }
/** * */ private void createIndex(IgniteEx ignite, T3<String, String, String> pair) { IgniteCache<?, ?> cache = ignite.getOrCreateCache(pair.get1()); String createIdxQryStr = String.format("CREATE INDEX %S on %s (city_id)", pair.get3(), pair.get2()); cache.query(new SqlFieldsQuery(createIdxQryStr)).getAll(); }
@Override public Void call() throws Exception { try (Transaction tx = node.transactions().txStart(OPTIMISTIC, READ_COMMITTED)) { mvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll(); tx.commit(); } return null; } }, CacheException.class, "Only pessimistic transactions are supported when MVCC is enabled");
@Override public Void call() throws Exception { try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) { mvccCache.query(new SqlFieldsQuery("SELECT * FROM Integer")).getAll(); tx.commit(); } return null; } }, CacheException.class, "Only pessimistic transactions are supported when MVCC is enabled");
/** * Run SQL statement on specified node. * * @param node node to execute query. * @param stmt Statement to run. * @param args arguments of statements * @return Run result. */ private List<List<?>> executeSql(IgniteEx node, String stmt, Object... args) { return node.context().query().querySqlFields(new SqlFieldsQuery(stmt).setArgs(args), true).getAll(); }
/** * Run query locally. * * @param node Node. * @param sqlText Query. * @return Results. */ private List<List<?>> runSqlLocal(Ignite node, String sqlText) { GridQueryProcessor qryProc = ((IgniteEx)node).context().query(); return qryProc.querySqlFields(new SqlFieldsQuery(sqlText).setLocal(true), false).getAll(); } }
/** * Execute SQL command and return resulting dataset. * @param node Node to run query from. * @param sql Statement. * @return result. */ protected List<List<?>> run(Ignite node, String sql) { return ((IgniteEx)node).context().query() .querySqlFields(new SqlFieldsQuery(sql).setSchema(QueryUtils.DFLT_SCHEMA), true).getAll(); }
@Override public Object call() throws Exception { try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = cache.query(qry)) { try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { for (int i = 0; i < TX_SIZE_THRESHOLD + 1; i++) cache.query(new SqlFieldsQuery("INSERT INTO Integer (_key, _val) values (" + i + ", 1)")).getAll(); tx.commit(); } } return null; } }, CacheException.class, "Failed to run update. Transaction is too large. Consider reducing transaction size");
@Override public Object call() throws Exception { try (Transaction tx = updateNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { tx.timeout(TX_TIMEOUT); SqlFieldsQuery qry = new SqlFieldsQuery("INSERT INTO Integer (_key, _val) values (1,1),(1,2),(1,3)"); IgniteCache<Object, Object> cache0 = updateNode.cache(DEFAULT_CACHE_NAME); cache0.query(qry).getAll(); tx.commit(); } return null; } }, CacheException.class, "Duplicate key during INSERT [key=KeyCacheObjectImpl");