/** */ @Test public void testQueryMultipleStatementsFailed() { final SqlFieldsQuery qry = new SqlFieldsQuery("select 1; select 1;").setSchema("PUBLIC"); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { node.context().query().querySqlFields(qry, true, true); return null; } }, IgniteSQLException.class, "Multiple statements queries are not supported"); }
/** * @param sql SQL query. * @return Results. */ private List<FieldsQueryCursor<List<?>>> sql(String sql) { GridQueryProcessor qryProc = node.context().query(); SqlFieldsQuery qry = new SqlFieldsQuery(sql).setSchema("PUBLIC"); return qryProc.querySqlFields(qry, true, false); } }
/** * Executes SQL command. * * @param sql SQL command. */ private void execute(String sql) { jcache().query(new SqlFieldsQuery(sql).setSchema("PUBLIC")).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(); }
/** {@inheritDoc} */ @Override protected List<List<?>> execute(Ignite node, String sql) { return node.cache("ints").query(new SqlFieldsQuery(sql).setSchema(QueryUtils.DFLT_SCHEMA)).getAll(); }
/** {@inheritDoc} */ @Override protected List<List<?>> execute(Ignite node, String sql) { return node.cache("ints").query(new SqlFieldsQuery(sql).setSchema(QueryUtils.DFLT_SCHEMA)).getAll(); }
/** * Test query without caches. * * @throws Exception If failed. */ @Test public void testQueryWithoutCacheOnPublicSchema() throws Exception { GridQueryProcessor qryProc = node.context().query(); SqlFieldsQuery qry = new SqlFieldsQuery("SELECT 1").setSchema("PUBLIC"); List<List<?>> res = qryProc.querySqlFields(qry, true).getAll(); assertEquals(1, res.size()); assertEquals(1, res.get(0).size()); assertEquals(1, res.get(0).get(0)); Iterator<List<?>> iter = qryProc.querySqlFields(qry, true).iterator(); assertTrue(iter.hasNext()); List<?> row = iter.next(); assertEquals(1, row.size()); assertEquals(1, row.get(0)); assertFalse(iter.hasNext()); }
/** * @throws Exception In case of an error. */ @Test public void testEntryReadCreateTable() throws Exception { Ignite ignite = startGrid(0); IgniteCache def = ignite.createCache("default"); def.query(new SqlFieldsQuery("CREATE TABLE binary (id INT PRIMARY KEY, str VARCHAR) " + "WITH \"cache_name=binary, key_type=IdKey, value_type=Payload\"").setSchema("PUBLIC")); def.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (1, 'foo');").setSchema("PUBLIC")); def.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (2, 'bar');").setSchema("PUBLIC")); GridTestUtils.assertThrowsAnyCause( log, new Callable<Object>() { @Override public Object call() { return ignite.cache("binary").iterator().next(); } }, BinaryInvalidTypeException.class, "IdKey"); }
/** * @throws Exception In case of an error. */ @Test public void testValueReadCreateTable() throws Exception { Ignite ignite = startGrid(0); IgniteCache def = ignite.createCache("default"); def.query(new SqlFieldsQuery("CREATE TABLE binary (id INT PRIMARY KEY, str VARCHAR) " + "WITH \"cache_name=binary, value_type=Payload\"").setSchema("PUBLIC")); def.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (1, 'foo');").setSchema("PUBLIC")); def.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (2, 'bar');").setSchema("PUBLIC")); GridTestUtils.assertThrowsAnyCause( log, new Callable<Object>() { @Override public Object call() { return ignite.cache("binary").get(1); } }, BinaryInvalidTypeException.class, "Payload"); }
/** * Execute DDL statement on given node. * * @param node Node. * @param sql Statement. */ private List<List<?>> execute(Ignite node, String sql, Object... args) { SqlFieldsQuery qry = new SqlFieldsQuery(sql) .setArgs(args) .setSchema("PUBLIC"); return queryProcessor(node).querySqlFields(qry, true).getAll(); }
/** * @param sql SQL query. * @return Results. */ private List<List<?>> sql(String sql) { GridQueryProcessor qryProc = node.context().query(); SqlFieldsQuery qry = new SqlFieldsQuery(sql).setSchema("PUBLIC"); return qryProc.querySqlFields(qry, true).getAll(); } }
/** * Execute SQL command and return resulting dataset. * @param cache Cache to initiate query from. * @param sql Statement. * @return result. */ protected List<List<?>> run(IgniteCache<?, ?> cache, String sql, Object... args) { SqlFieldsQuery qry = new SqlFieldsQuery(sql).setSchema(QueryUtils.DFLT_SCHEMA).setArgs(args) .setDistributedJoins(true); return cache.query(qry).getAll(); }
/** * @param sql SQL query. * @return Results. */ private List<List<?>> sql(String sql) { GridQueryProcessor qryProc = node.context().query(); SqlFieldsQuery qry = new SqlFieldsQuery(sql).setSchema("PUBLIC"); return qryProc.querySqlFields(qry, true).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(); }
/** * Execute sql query with PUBLIC schema and specified positional arguments of sql query. * * @param sql query. * @param args positional arguments if sql query got ones. * @return fetched result set. */ private static List<List<?>> execute(String sql, Object... args) { SqlFieldsQuery qry = new SqlFieldsQuery(sql).setSchema("PUBLIC"); if (!F.isEmpty(args)) qry.setArgs(args); return cache.query(qry).getAll(); }
/** * Test query without caches. * * @throws Exception If failed. */ @Test public void testQueryWithoutCacheOnCacheSchema() throws Exception { node.createCache(new CacheConfiguration<PersonKey, Person>() .setName(CACHE_PERSON) .setIndexedTypes(PersonKey.class, Person.class)); GridQueryProcessor qryProc = node.context().query(); SqlFieldsQuery qry = new SqlFieldsQuery("SELECT 1").setSchema(CACHE_PERSON); List<List<?>> res = qryProc.querySqlFields(qry, true).getAll(); assertEquals(1, res.size()); assertEquals(1, res.get(0).size()); assertEquals(1, res.get(0).get(0)); Iterator<List<?>> iter = qryProc.querySqlFields(qry, true).iterator(); assertTrue(iter.hasNext()); List<?> row = iter.next(); assertEquals(1, row.size()); assertEquals(1, row.get(0)); assertFalse(iter.hasNext()); }
/** */ private List<List<?>> executeSql(IgniteEx grid, String qry, Object...args) { return grid.context().query().querySqlFields( new SqlFieldsQuery(qry).setSchema("PUBLIC").setArgs(args), true).getAll(); }
/** * Create dynamic index and column. * @param node Node. * @param schema Schema name. */ private void makeDynamicSchemaChanges(IgniteEx node, String schema) { node.context().query().querySqlFields( new SqlFieldsQuery("create index \"my_idx\" on \"Person\" (\"id\", \"name\")").setSchema(schema), false) .getAll(); node.context().query().querySqlFields( new SqlFieldsQuery("alter table \"Person\" add column (\"age\" int, \"city\" char)") .setSchema(schema), false).getAll(); node.context().query().querySqlFields( new SqlFieldsQuery("alter table \"Person\" drop column \"city\"").setSchema(schema), false) .getAll(); }
/** * @throws Exception In case of an error. */ @Test public void testEntryWriteCreateTable() throws Exception { Ignite ignite = startGridWithLogCapture(); IgniteCache def = ignite.createCache("default"); def.query(new SqlFieldsQuery("CREATE TABLE binary (id INT PRIMARY KEY, str VARCHAR) " + "WITH \"cache_name=binary, key_type=IdKey, value_type=Payload\"").setSchema("PUBLIC")); IgniteCache<Integer, Payload> binary = ignite.cache("binary"); binary.put(1, new Payload("foo")); binary.put(2, new Payload("bar")); assertEquals(0, countRows(binary)); assertContainsExactlyOnce(capture.toString(), MESSAGE_PAYLOAD_VALUE); capture.reset(); def.query(new SqlFieldsQuery("CREATE TABLE binary2 (id INT PRIMARY KEY, str VARCHAR) " + "WITH \"cache_name=binary2, key_type=IdKey, value_type=Payload\"").setSchema("PUBLIC")); IgniteCache<Integer, Payload> binary2 = ignite.cache("binary2"); binary2.put(1, new Payload("foo")); binary2.put(2, new Payload("bar")); assertEquals(0, countRows(binary2)); assertContainsExactlyOnce(capture.toString(), MESSAGE_PAYLOAD_VALUE); }
/** * @throws Exception In case of an error. */ @Test public void testValueWriteCreateTable() throws Exception { Ignite ignite = startGridWithLogCapture(); IgniteCache def = ignite.createCache("default"); def.query(new SqlFieldsQuery("CREATE TABLE binary (id INT PRIMARY KEY, str VARCHAR) " + "WITH \"cache_name=binary, value_type=Payload\"").setSchema("PUBLIC")); IgniteCache<Integer, Payload> binary = ignite.cache("binary"); binary.put(1, new Payload("foo")); binary.put(2, new Payload("bar")); assertEquals(0, countRows(binary)); String capturedMessages = this.capture.toString(); assertContainsExactlyOnce(capturedMessages, "Key-value pair is not inserted into any SQL table [cacheName=binary, " + MESSAGE_PAYLOAD_VALUE + "]"); assertContainsExactlyOnce(capturedMessages, "Value type(s) are specified via CacheConfiguration.indexedTypes or CacheConfiguration.queryEntities"); assertContainsExactlyOnce(capturedMessages, "Make sure that same type(s) used when adding Object or BinaryObject to cache"); assertContainsExactlyOnce(capturedMessages, "Otherwise, entries will be stored in cache, but not appear as SQL Table rows"); }