use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheProxyImpl method convertToBinary.
/**
* Convert query arguments to BinaryObjects if binary marshaller used.
*
* @param qry Query.
*/
private void convertToBinary(final Query qry) {
if (ctx.binaryMarshaller()) {
if (qry instanceof SqlQuery) {
final SqlQuery sqlQry = (SqlQuery) qry;
convertToBinary(sqlQry.getArgs());
} else if (qry instanceof SpiQuery) {
final SpiQuery spiQry = (SpiQuery) qry;
convertToBinary(spiQry.getArgs());
} else if (qry instanceof SqlFieldsQuery) {
final SqlFieldsQuery fieldsQry = (SqlFieldsQuery) qry;
convertToBinary(fieldsQry.getArgs());
}
}
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheProxyImpl method query.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <R> QueryCursor<R> query(Query<R> qry) {
A.notNull(qry, "qry");
try {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
validate(qry);
convertToBinary(qry);
CacheOperationContext opCtxCall = ctx.operationContextPerCall();
boolean keepBinary = opCtxCall != null && opCtxCall.isKeepBinary();
if (qry instanceof ContinuousQuery || qry instanceof ContinuousQueryWithTransformer)
return (QueryCursor<R>) queryContinuous((AbstractContinuousQuery) qry, qry.isLocal(), keepBinary);
if (qry instanceof SqlQuery)
return (QueryCursor<R>) ctx.kernalContext().query().querySql(ctx, (SqlQuery) qry, keepBinary);
if (qry instanceof SqlFieldsQuery)
return (FieldsQueryCursor<R>) ctx.kernalContext().query().querySqlFields(ctx, (SqlFieldsQuery) qry, null, keepBinary, true).get(0);
if (qry instanceof ScanQuery)
return query((ScanQuery) qry, null, projection(qry.isLocal()));
return (QueryCursor<R>) query(qry, projection(qry.isLocal()));
} catch (Exception e) {
if (e instanceof CacheException)
throw (CacheException) e;
throw new CacheException(e.getMessage(), e);
}
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class BinarySerializationQuerySelfTest method check.
/**
* Internal check routine.
*
* @param cls Entity class.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void check(Class cls) throws Exception {
cache.put(1, createInstance(cls, 10));
cache.put(2, createInstance(cls, 20));
cache.put(3, createInstance(cls, 30));
Iterator iter = cache.query(new SqlQuery(cls, "val=20")).iterator();
assert iter.hasNext();
Cache.Entry res = (Cache.Entry) iter.next();
assertEquals(2, res.getKey());
assertEquals(Integer.valueOf(20), U.field(res.getValue(), "val"));
assert !iter.hasNext();
iter = cache.query(new SqlFieldsQuery("SELECT p.val FROM " + cls.getSimpleName() + " p WHERE p.val=20")).iterator();
assert iter.hasNext();
List<Object> fieldsRes = (List<Object>) iter.next();
assertEquals(20, fieldsRes.get(0));
assert !iter.hasNext();
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class CacheAbstractQueryMetricsSelfTest method testSqlQueryNotFullyFetchedMetrics.
/**
* Test metrics for Sql queries.
*
* @throws Exception In case of error.
*/
public void testSqlQueryNotFullyFetchedMetrics() throws Exception {
IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
SqlQuery qry = new SqlQuery<>("String", "from String");
qry.setPageSize(10);
checkQueryNotFullyFetchedMetrics(cache, qry, true);
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class CacheQueryExample method sqlQueryWithDistributedJoin.
/**
* Example for SQL queries based on all employees working
* for a specific organization (query uses distributed join).
*/
private static void sqlQueryWithDistributedJoin() {
IgniteCache<Long, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
// SQL clause query which joins on 2 types to select people for a specific organization.
String joinSql = "from Person, \"" + ORG_CACHE + "\".Organization as org " + "where Person.orgId = org.id " + "and lower(org.name) = lower(?)";
SqlQuery qry = new SqlQuery<Long, Person>(Person.class, joinSql).setArgs("ApacheIgnite");
// Enable distributed joins for query.
qry.setDistributedJoins(true);
// Execute queries for find employees for different organizations.
print("Following people are 'ApacheIgnite' employees (distributed join): ", cache.query(qry).getAll());
qry.setArgs("Other");
print("Following people are 'Other' employees (distributed join): ", cache.query(qry).getAll());
}
Aggregations