本文整理汇总了Java中org.apache.ignite.cache.query.SqlFieldsQuery.setPartitions方法的典型用法代码示例。如果您正苦于以下问题:Java SqlFieldsQuery.setPartitions方法的具体用法?Java SqlFieldsQuery.setPartitions怎么用?Java SqlFieldsQuery.setPartitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ignite.cache.query.SqlFieldsQuery
的用法示例。
在下文中一共展示了SqlFieldsQuery.setPartitions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryDistributedSql
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public <K, V> QueryCursor<Cache.Entry<K, V>> queryDistributedSql(String schemaName, String cacheName,
SqlQuery qry, boolean keepBinary, int mainCacheId) {
String type = qry.getType();
H2TableDescriptor tblDesc = tableDescriptor(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 = generateQuery(qry.getSql(), qry.getAlias(), tblDesc);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
SqlFieldsQuery fqry = new SqlFieldsQuery(sql);
fqry.setArgs(qry.getArgs());
fqry.setPageSize(qry.getPageSize());
fqry.setDistributedJoins(qry.isDistributedJoins());
fqry.setPartitions(qry.getPartitions());
fqry.setLocal(qry.isLocal());
if (qry.getTimeout() > 0)
fqry.setTimeout(qry.getTimeout(), TimeUnit.MILLISECONDS);
final QueryCursor<List<?>> res =
queryDistributedSqlFields(schemaName, fqry, keepBinary, null, mainCacheId, true).get(0);
final Iterable<Cache.Entry<K, V>> converted = new Iterable<Cache.Entry<K, V>>() {
@Override public Iterator<Cache.Entry<K, V>> iterator() {
final Iterator<List<?>> iter0 = res.iterator();
return new Iterator<Cache.Entry<K, V>>() {
@Override public boolean hasNext() {
return iter0.hasNext();
}
@Override public Cache.Entry<K, V> next() {
List<?> l = iter0.next();
return new CacheEntryImpl<>((K)l.get(0), (V)l.get(1));
}
@Override public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
// No metadata for SQL queries.
return new QueryCursorImpl<Cache.Entry<K, V>>(converted) {
@Override public void close() {
res.close();
}
};
}
示例2: testPartitions
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/** Tests partition validation. */
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());
}
开发者ID:apache,项目名称:ignite,代码行数:51,代码来源:IgniteCacheDistributedPartitionQueryConfigurationSelfTest.java
示例3: testLocalQuery
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/** Tests local query over partitions. */
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)));
}