Java Code Examples for org.apache.ignite.cache.query.SqlFieldsQuery#setPartitions()
The following examples show how to use
org.apache.ignite.cache.query.SqlFieldsQuery#setPartitions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteH2Indexing.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @SuppressWarnings("deprecation") @Override public SqlFieldsQuery generateFieldsQuery(String cacheName, SqlQuery qry) { String schemaName = schema(cacheName); String type = qry.getType(); H2TableDescriptor tblDesc = schemaMgr.tableForType(schemaName, cacheName, type); if (tblDesc == null) throw new IgniteSQLException("Failed to find SQL table for type: " + type, IgniteQueryErrorCode.TABLE_NOT_FOUND); String sql; try { sql = generateFieldsQueryString(qry.getSql(), qry.getAlias(), tblDesc); } catch (IgniteCheckedException e) { throw new IgniteException(e); } SqlFieldsQuery res = new SqlFieldsQuery(sql); res.setArgs(qry.getArgs()); res.setDistributedJoins(qry.isDistributedJoins()); res.setLocal(qry.isLocal()); res.setPageSize(qry.getPageSize()); res.setPartitions(qry.getPartitions()); res.setReplicatedOnly(qry.isReplicatedOnly()); res.setSchema(schemaName); res.setSql(sql); if (qry.getTimeout() > 0) res.setTimeout(qry.getTimeout(), TimeUnit.MILLISECONDS); return res; }
Example 2
Source File: IndexingCachePartitionLossPolicySelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected List<?> runQuery(Ignite ig, String cacheName, boolean loc, int part) { IgniteCache cache = ig.cache(cacheName); SqlFieldsQuery qry = new SqlFieldsQuery("SELECT * FROM Integer"); if (part != -1) qry.setPartitions(part); // TODO https://issues.apache.org/jira/browse/IGNITE-7039 // if (loc) // qry.setLocal(true); return cache.query(qry).getAll(); }
Example 3
Source File: IgniteCacheDistributedPartitionQuerySelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** Tests local query over partitions. */ @Test public void testLocalQuery() { Affinity<Object> affinity = grid(0).affinity("cl"); int[] parts = affinity.primaryPartitions(grid(0).localNode()); Arrays.sort(parts); IgniteCache<ClientKey, Client> cl = grid(0).cache("cl"); SqlQuery<ClientKey, Client> qry1 = new SqlQuery<>(Client.class, "1=1"); qry1.setLocal(true); qry1.setPartitions(parts[0]); List<Cache.Entry<ClientKey, Client>> clients = cl.query(qry1).getAll(); for (Cache.Entry<ClientKey, Client> client : clients) assertEquals("Incorrect partition", parts[0], affinity.partition(client.getKey())); SqlFieldsQuery qry2 = new SqlFieldsQuery("select cl._KEY, cl._VAL from \"cl\".Client cl"); qry2.setLocal(true); qry2.setPartitions(parts[0]); List<List<?>> rows = cl.query(qry2).getAll(); for (List<?> row : rows) assertEquals("Incorrect partition", parts[0], affinity.partition(row.get(0))); }
Example 4
Source File: IgniteCacheDistributedPartitionQueryConfigurationSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** Tests partition validation. */ @Test public void testPartitions() { final SqlFieldsQuery qry = new SqlFieldsQuery("select 1"); // Empty set is not allowed. failIfNotThrown(new Runnable() { @Override public void run() { qry.setPartitions(); } }); // Duplicates are not allowed. failIfNotThrown(new Runnable() { @Override public void run() { qry.setPartitions(0, 1, 2, 1); } }); // Values out of range are not allowed. failIfNotThrown(new Runnable() { @Override public void run() { qry.setPartitions(-1, 0, 1); } }); // Duplicates with unordered input are not allowed. failIfNotThrown(new Runnable() { @Override public void run() { qry.setPartitions(3, 2, 2); } }); // Values out of range are not allowed. failIfNotThrown(new Runnable() { @Override public void run() { qry.setPartitions(-1, 0, 1); } }); // Expecting ordered set. int[] tmp = new int[] {6, 2, 3}; qry.setPartitions(tmp); assertTrue(Arrays.equals(new int[]{2, 3, 6}, tmp)); // If already ordered expecting same instance. qry.setPartitions((tmp = new int[] {0, 1, 2})); assertTrue(tmp == qry.getPartitions()); }