本文整理汇总了Java中org.apache.ignite.cache.query.SqlFieldsQuery.setDistributedJoins方法的典型用法代码示例。如果您正苦于以下问题:Java SqlFieldsQuery.setDistributedJoins方法的具体用法?Java SqlFieldsQuery.setDistributedJoins怎么用?Java SqlFieldsQuery.setDistributedJoins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ignite.cache.query.SqlFieldsQuery
的用法示例。
在下文中一共展示了SqlFieldsQuery.setDistributedJoins方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkQueryFails
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @param cache Cache.
* @param sql SQL.
* @param enforceJoinOrder Enforce join order flag.
*/
private void checkQueryFails(final IgniteCache<Object, Object> cache,
String sql,
boolean enforceJoinOrder) {
final SqlFieldsQuery qry = new SqlFieldsQuery(sql);
qry.setDistributedJoins(true);
qry.setEnforceJoinOrder(enforceJoinOrder);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override public Void call() throws Exception {
cache.query(qry);
return null;
}
}, CacheException.class, null);
}
示例2: checkQuery
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @param sql SQL.
* @param cache Cache.
* @param enforceJoinOrder Enforce join order flag.
* @param expSize Expected results size.
* @param args Arguments.
*/
private void checkQuery(String sql,
IgniteCache<Object, Object> cache,
boolean enforceJoinOrder,
int expSize,
Object... args) {
SqlFieldsQuery qry = new SqlFieldsQuery(sql);
qry.setDistributedJoins(true);
qry.setEnforceJoinOrder(enforceJoinOrder);
qry.setArgs(args);
log.info("Plan: " + queryPlan(cache, qry));
QueryCursor<List<?>> cur = cache.query(qry);
List<List<?>> res = cur.getAll();
if (expSize != res.size())
log.info("Results: " + res);
assertEquals(expSize, res.size());
}
示例3: checkQueryFails
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @param cache Cache.
* @param sql SQL.
* @param enforceJoinOrder Enforce join order flag.
*/
private void checkQueryFails(final IgniteCache<Object, Object> cache,
String sql,
boolean enforceJoinOrder) {
final SqlFieldsQuery qry = new SqlFieldsQuery(sql);
qry.setDistributedJoins(true);
qry.setEnforceJoinOrder(enforceJoinOrder);
Throwable err = GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override public Void call() throws Exception {
cache.query(qry);
return null;
}
}, CacheException.class, null);
assertTrue("Unexpected error message: " + err.getMessage(),
err.getMessage().contains("can not use distributed joins for cache with custom AffinityKeyMapper configured."));
}
示例4: checkQuery
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @param sql SQL.
* @param cache Cache.
* @param enforceJoinOrder Enforce join order flag.
* @param expSize Expected results size.
*/
private void checkQuery(String sql,
IgniteCache<Object, Object> cache,
boolean enforceJoinOrder,
int expSize) {
String plan = (String)cache.query(new SqlFieldsQuery("explain " + sql)
.setDistributedJoins(true)
.setEnforceJoinOrder(enforceJoinOrder))
.getAll().get(0).get(0);
log.info("Plan: " + plan);
SqlFieldsQuery qry = new SqlFieldsQuery(sql);
qry.setDistributedJoins(true);
qry.setEnforceJoinOrder(enforceJoinOrder);
QueryCursor<List<?>> cur = cache.query(qry);
List<List<?>> res = cur.getAll();
if (expSize != res.size())
log.info("Results: " + res);
assertEquals(expSize, res.size());
}
示例5: checkQuery
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @param sql SQL.
* @param cache Cache.
* @param enforceJoinOrder Enforce join order flag.
* @param expSize Expected results size.
* @param args Arguments.
* @return Results.
*/
private List<List<?>> checkQuery(String sql,
IgniteCache<Object, Object> cache,
boolean enforceJoinOrder,
int expSize,
Object... args) {
SqlFieldsQuery qry = new SqlFieldsQuery(sql);
qry.setDistributedJoins(true);
qry.setEnforceJoinOrder(enforceJoinOrder);
qry.setArgs(args);
log.info("Plan: " + queryPlan(cache, qry));
QueryCursor<List<?>> cur = cache.query(qry);
List<List<?>> res = cur.getAll();
if (expSize != res.size())
log.info("Results: " + res);
assertEquals(expSize, res.size());
return res;
}
示例6: checkQuery
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @param sql SQL.
* @param cache Cache.
* @param expSize Expected results size.
* @param args Arguments.
* @return Results.
*/
private List<List<?>> checkQuery(String sql,
IgniteCache<Object, Object> cache,
int expSize,
Object... args) {
SqlFieldsQuery qry = new SqlFieldsQuery(sql);
qry.setDistributedJoins(true);
qry.setArgs(args);
log.info("Plan: " + queryPlan(cache, qry));
QueryCursor<List<?>> cur = cache.query(qry);
List<List<?>> res = cur.getAll();
if (expSize != res.size())
log.info("Results: " + res);
assertEquals(expSize, res.size());
return res;
}
示例7: testIndexWithDifferentSegmentationLevelsFailure
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @throws Exception If failed.
*/
public void testIndexWithDifferentSegmentationLevelsFailure() throws Exception {
CacheConfiguration ccfg1 = cacheConfig("pers", true,
Integer.class, Person2.class).setQueryParallelism(4);
CacheConfiguration ccfg2 = cacheConfig("org", true,
Integer.class, Organization.class).setQueryParallelism(3);
final IgniteCache<Object, Object> c1 = ignite(0).getOrCreateCache(ccfg1);
final IgniteCache<Object, Object> c2 = ignite(0).getOrCreateCache(ccfg2);
try {
c2.put(1, new Organization("o1"));
c2.put(2, new Organization("o2"));
c1.put(3, new Person2(1, "p1"));
c1.put(4, new Person2(2, "p2"));
c1.put(5, new Person2(3, "p3"));
String select0 = "select o.name n1, p.name n2 from \"pers\".Person2 p, \"org\".Organization o where p.orgId = o._key and o._key=1";
final SqlFieldsQuery qry = new SqlFieldsQuery(select0);
qry.setDistributedJoins(true);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override public Void call() throws Exception {
c1.query(qry);
return null;
}
}, CacheException.class, "Using indexes with different parallelism levels in same query is forbidden.");
}
finally {
c1.destroy();
c2.destroy();
}
}
示例8: checkQueryPlan
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @param cache Cache.
* @param enforceJoinOrder Enforce join order flag.
* @param expBatchedJoins Expected batched joins count.
* @param qry Query.
* @param expText Expected text to find in plan.
*/
private void checkQueryPlan(IgniteCache<Object, Object> cache,
boolean enforceJoinOrder,
int expBatchedJoins,
SqlFieldsQuery qry,
String... expText) {
qry.setEnforceJoinOrder(enforceJoinOrder);
qry.setDistributedJoins(true);
String plan = queryPlan(cache, qry);
log.info("\n Plan:\n" + plan);
assertEquals("Unexpected number of batched joins in plan [plan=" + plan + ", qry=" + qry + ']',
expBatchedJoins,
StringUtils.countOccurrencesOf(plan, "batched"));
int startIdx = 0;
for (String exp : expText) {
int idx = plan.indexOf(exp, startIdx);
if (idx == -1) {
fail("Plan does not contain expected string [startIdx=" + startIdx +
", plan=" + plan +
", exp=" + exp + ']');
}
startIdx = idx + 1;
}
}
示例9: checkPersonOrganizationGroupBy
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @param cache Cache.
*/
private void checkPersonOrganizationGroupBy(IgniteCache cache) {
if (skipQuery(cache, PERSON_CACHE_NAME, ORG_CACHE_NAME))
return;
qry = "checkPersonOrganizationGroupBy";
// Max salary per organization.
SqlFieldsQuery q = new SqlFieldsQuery("select max(p.salary) " +
"from \"" + PERSON_CACHE_NAME + "\".Person p join \"" + ORG_CACHE_NAME + "\".Organization o " +
"on p.orgId = o.id " +
"group by o.name " +
"having o.id = ?");
q.setDistributedJoins(distributedJoins());
for (Map.Entry<Integer, Integer> e : data.maxSalaryPerOrg.entrySet()) {
Integer orgId = e.getKey();
Integer maxSalary = e.getValue();
q.setArgs(orgId);
List<List<?>> res = cache.query(q).getAll();
String errMsg = "Expected data [orgId=" + orgId + ", maxSalary=" + maxSalary + ", data=" + data + "]";
// MaxSalary == -1 means that there are no persons at organization.
if (maxSalary > 0) {
assertEquals(errMsg, 1, res.size());
assertEquals(errMsg, 1, res.get(0).size());
assertEquals(errMsg, maxSalary, res.get(0).get(0));
}
else
assertEquals(errMsg, 0, res.size());
}
}
示例10: checkPersonAccountGroupBy
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* @param cache Cache.
*/
private void checkPersonAccountGroupBy(IgniteCache cache) {
if (skipQuery(cache, PERSON_CACHE_NAME, ACC_CACHE_NAME))
return;
qry = "checkPersonAccountGroupBy";
// Count accounts per person.
SqlFieldsQuery q = new SqlFieldsQuery("select count(a.id) " +
"from \"" + PERSON_CACHE_NAME + "\".Person p join \"" + ACC_CACHE_NAME + "\".Account a " +
"on p.strId = a.personStrId " +
"group by p.name " +
"having p.id = ?");
q.setDistributedJoins(distributedJoins());
List<Integer> keys = new ArrayList<>(data.accountsPerPerson.keySet());
for (int i = 0; i < 10; i++) {
Integer personId = keys.get(rnd.nextInt(keys.size()));
Integer cnt = data.accountsPerPerson.get(personId);
q.setArgs(personId);
List<List<?>> res = cache.query(q).getAll();
String errMsg = "Expected data [personId=" + personId + ", cnt=" + cnt + ", data=" + data + "]";
// Cnt == 0 means that there are no accounts for the person.
if (cnt > 0) {
assertEquals(errMsg, 1, res.size());
assertEquals(errMsg, 1, res.get(0).size());
assertEquals(errMsg, (long)cnt, res.get(0).get(0));
}
else
assertEquals(errMsg, 0, res.size());
}
}
示例11: 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();
}
};
}
示例12: run
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected VisorEither<VisorQueryResult> run(final VisorQueryTaskArg arg) {
try {
UUID nid = ignite.localNode().id();
SqlFieldsQuery qry = new SqlFieldsQuery(arg.getQueryText());
qry.setPageSize(arg.getPageSize());
qry.setLocal(arg.isLocal());
qry.setDistributedJoins(arg.isDistributedJoins());
qry.setEnforceJoinOrder(arg.isEnforceJoinOrder());
qry.setReplicatedOnly(arg.isReplicatedOnly());
qry.setLazy(arg.getLazy());
long start = U.currentTimeMillis();
List<FieldsQueryCursor<List<?>>> qryCursors;
String cacheName = arg.getCacheName();
if (F.isEmpty(cacheName))
qryCursors = ignite.context().query().querySqlFieldsNoCache(qry, true, false);
else {
IgniteCache<Object, Object> c = ignite.cache(cacheName);
if (c == null)
throw new SQLException("Fail to execute query. Cache not found: " + cacheName);
qryCursors = ((IgniteCacheProxy)c.withKeepBinary()).queryMultipleStatements(qry);
}
// In case of multiple statements leave opened only last cursor.
for (int i = 0; i < qryCursors.size() - 1; i++)
U.closeQuiet(qryCursors.get(i));
// In case of multiple statements return last cursor as result.
VisorQueryCursor<List<?>> cur = new VisorQueryCursor<>(F.last(qryCursors));
Collection<GridQueryFieldMetadata> meta = cur.fieldsMeta();
if (meta == null)
return new VisorEither<>(
new VisorExceptionWrapper(new SQLException("Fail to execute query. No metadata available.")));
else {
List<VisorQueryField> names = new ArrayList<>(meta.size());
for (GridQueryFieldMetadata col : meta)
names.add(new VisorQueryField(col.schemaName(), col.typeName(),
col.fieldName(), col.fieldTypeName()));
List<Object[]> rows = fetchSqlQueryRows(cur, arg.getPageSize());
// Query duration + fetch duration.
long duration = U.currentTimeMillis() - start;
boolean hasNext = cur.hasNext();
// Generate query ID to store query cursor in node local storage.
String qryId = SQL_QRY_NAME + "-" + UUID.randomUUID();
if (hasNext) {
ignite.cluster().<String, VisorQueryCursor<List<?>>>nodeLocalMap().put(qryId, cur);
scheduleResultSetHolderRemoval(qryId, ignite);
}
else
cur.close();
return new VisorEither<>(new VisorQueryResult(nid, qryId, names, rows, hasNext, duration));
}
}
catch (Throwable e) {
return new VisorEither<>(new VisorExceptionWrapper(e));
}
}
示例13: doSingleUpdate
import org.apache.ignite.cache.query.SqlFieldsQuery; //导入方法依赖的package包/类
/**
* Performs update.
*
* @param cache Cache.
* @param sqlText SQL text.
* @param args Parameters.
* @return Update counter.
* @throws SQLException If failed.
*/
private Integer doSingleUpdate(IgniteCache<?, ?> cache, String sqlText, List<Object> args) throws SQLException {
SqlFieldsQuery qry = new SqlFieldsQueryEx(sqlText, false);
qry.setPageSize(fetchSize);
qry.setLocal(locQry);
qry.setCollocated(collocatedQry);
qry.setDistributedJoins(distributedJoins);
qry.setSchema(schemaName);
qry.setArgs(args == null ? null : args.toArray());
QueryCursorImpl<List<?>> qryCursor = (QueryCursorImpl<List<?>>)cache.withKeepBinary().query(qry);
if (qryCursor.isQuery()) {
throw createJdbcSqlException(getError("Query produced result set", qry),
IgniteQueryErrorCode.STMT_TYPE_MISMATCH);
}
List<List<?>> rows = qryCursor.getAll();
if (F.isEmpty(rows))
return SUCCESS_NO_INFO;
if (rows.size() != 1)
throw new SQLException(getError("Expected single row for update operation result", qry));
List<?> row = rows.get(0);
if (F.isEmpty(row) || row.size() != 1)
throw new SQLException(getError("Expected row size of 1 for update operation", qry));
Object objRes = row.get(0);
if (!(objRes instanceof Long))
throw new SQLException(getError("Unexpected update result type", qry));
Long longRes = (Long)objRes;
if (longRes > Integer.MAX_VALUE) {
IgniteLogger log = ignite.log();
if (log != null)
log.warning(getError("Query updated row counter (" + longRes + ") exceeds integer range", qry));
return Integer.MAX_VALUE;
}
return longRes.intValue();
}