use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class OrderByComparatorJUnitTest method testUnsupportedOrderByForPR.
@Test
public void testUnsupportedOrderByForPR() throws Exception {
String[] unsupportedQueries = { "select distinct p.status from /portfolio1 p order by p.status, p.ID" };
Object[][] r = new Object[unsupportedQueries.length][2];
QueryService qs;
qs = CacheUtils.getQueryService();
Position.resetCounter();
// Create Regions
PartitionAttributesFactory paf = new PartitionAttributesFactory();
AttributesFactory af = new AttributesFactory();
af.setPartitionAttributes(paf.create());
Region r1 = CacheUtils.createRegion("portfolio1", af.create(), false);
for (int i = 0; i < 50; i++) {
r1.put(new Portfolio(i), new Portfolio(i));
}
for (int i = 0; i < unsupportedQueries.length; i++) {
Query q = null;
CacheUtils.getLogger().info("Executing query: " + unsupportedQueries[i]);
q = CacheUtils.getQueryService().newQuery(unsupportedQueries[i]);
try {
r[i][0] = q.execute();
fail("The query should have thrown exception");
} catch (QueryInvalidException qe) {
// ok
}
}
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class QueryTraceJUnitTest method testQueryFailLocalRegionWithSmallTracePrefixNoSpace.
@Test
public void testQueryFailLocalRegionWithSmallTracePrefixNoSpace() throws Exception {
String prefix = "<trace>";
// Create Partition Region
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.LOCAL);
region = CacheUtils.createRegion("portfolio", af.create(), false);
if (region.size() == 0) {
for (int i = 1; i <= 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
}
assertEquals(100, region.size());
qs = CacheUtils.getQueryService();
keyIndex1 = (IndexProtocol) qs.createIndex(INDEX_NAME, IndexType.FUNCTIONAL, "ID", "/portfolio ");
assertTrue(keyIndex1 instanceof CompactRangeIndex);
try {
Query query = qs.newQuery(prefix + queryStr);
} catch (Exception e) {
if (!(e instanceof QueryInvalidException)) {
fail("Test Failed: Query is invalid but exception was not thrown!");
}
}
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class PartitionedRegionDataStore method executeOnDataStore.
public void executeOnDataStore(final Set localKeys, final Function function, final Object object, final int prid, final Set<Integer> bucketSet, final boolean isReExecute, final PartitionedRegionFunctionStreamingMessage msg, long time, ServerConnection servConn, int transactionID) {
if (!areAllBucketsHosted(bucketSet)) {
throw new BucketMovedException(LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE.toLocalizedString());
}
final DM dm = this.partitionedRegion.getDistributionManager();
ResultSender resultSender = new PartitionedRegionFunctionResultSender(dm, this.partitionedRegion, time, msg, function, bucketSet);
final RegionFunctionContextImpl prContext = new RegionFunctionContextImpl(function.getId(), this.partitionedRegion, object, localKeys, ColocationHelper.constructAndGetAllColocatedLocalDataSet(this.partitionedRegion, bucketSet), bucketSet, resultSender, isReExecute);
FunctionStats stats = FunctionStats.getFunctionStats(function.getId(), dm.getSystem());
try {
long start = stats.startTime();
stats.startFunctionExecution(function.hasResult());
if (logger.isDebugEnabled()) {
logger.debug("Executing Function: {} on Remote Node with context: ", function.getId(), prContext);
}
function.execute(prContext);
stats.endFunctionExecution(start, function.hasResult());
} catch (FunctionException functionException) {
if (logger.isDebugEnabled()) {
logger.debug("FunctionException occurred on remote node while executing Function: {}", function.getId(), functionException);
}
stats.endFunctionExecutionWithException(function.hasResult());
if (functionException.getCause() instanceof QueryInvalidException) {
// create a new FunctionException on the original one's message (not cause).
throw new FunctionException(functionException.getLocalizedMessage());
}
throw functionException;
}
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class Query method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
// Based on MessageType.DESTROY
// Added by gregp 10/18/05
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
// Retrieve the data from the message parts
String queryString = clientMessage.getPart(0).getString();
if (clientMessage.getNumberOfParts() == 3) {
int timeout = clientMessage.getPart(2).getInt();
serverConnection.setRequestSpecificTimeout(timeout);
}
if (logger.isDebugEnabled()) {
logger.debug("{}: Received query request from {} queryString: {}", serverConnection.getName(), serverConnection.getSocketString(), queryString);
}
try {
// Create query
QueryService queryService = serverConnection.getCachedRegionHelper().getCache().getLocalQueryService();
org.apache.geode.cache.query.Query query = queryService.newQuery(queryString);
Set regionNames = ((DefaultQuery) query).getRegionsInQuery(null);
// Authorization check
QueryOperationContext queryContext = null;
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
queryContext = authzRequest.queryAuthorize(queryString, regionNames);
String newQueryString = queryContext.getQuery();
if (queryString != null && !queryString.equals(newQueryString)) {
query = queryService.newQuery(newQueryString);
queryString = newQueryString;
regionNames = queryContext.getRegionNames();
if (regionNames == null) {
regionNames = ((DefaultQuery) query).getRegionsInQuery(null);
}
}
}
processQuery(clientMessage, query, queryString, regionNames, start, null, queryContext, serverConnection, true);
} catch (QueryInvalidException e) {
throw new QueryInvalidException(e.getMessage() + queryString);
} catch (QueryExecutionLowMemoryException e) {
writeQueryResponseException(clientMessage, e, serverConnection);
}
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class CompiledSelect method transformGroupByIfPossible.
/**
* Transforms the group by clause into distinct order by clause, if possible
*/
private void transformGroupByIfPossible(ExecutionContext context) throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
// for time being assume that the group by cols are explicitly mentioned in proj
if (this.groupBy != null) {
List projAttribs = this.projAttrs;
if (projAttribs == null) {
projAttribs = new ArrayList();
List currentIters = context.getCurrentIterators();
for (Object o : currentIters) {
RuntimeIterator rIter = (RuntimeIterator) o;
String name = rIter.getName();
projAttribs.add(new Object[] { name, rIter });
}
}
if (projAttribs != null && projAttribs.size() != this.groupBy.size()) {
throw new QueryInvalidException(LocalizedStrings.DefaultQuery_PROJ_COL_ABSENT_IN_GROUP_BY.toLocalizedString() + " or " + LocalizedStrings.DefaultQuery_GROUP_BY_COL_ABSENT_IN_PROJ.toLocalizedString());
}
boolean shouldTransform = true;
StringBuilder lhsBuffer = new StringBuilder();
StringBuilder rhsBuffer = new StringBuilder();
outer: for (int i = 0; i < projAttribs.size(); ++i) {
Object[] prj = (Object[]) TypeUtils.checkCast(projAttribs.get(i), Object[].class);
CompiledValue groupByAttr = this.groupBy.get(i);
if (prj[0] != null) {
if (groupByAttr instanceof CompiledID) {
if (prj[0].equals(((CompiledID) groupByAttr).getId())) {
lhsBuffer.delete(0, lhsBuffer.length());
rhsBuffer.delete(0, rhsBuffer.length());
continue;
}
}
}
CompiledValue cvProj = (CompiledValue) TypeUtils.checkCast(prj[1], CompiledValue.class);
cvProj.generateCanonicalizedExpression(lhsBuffer, context);
groupByAttr.generateCanonicalizedExpression(rhsBuffer, context);
if (lhsBuffer.length() == rhsBuffer.length()) {
for (int indx = 0; indx < lhsBuffer.length(); ++indx) {
if (lhsBuffer.charAt(indx) != rhsBuffer.charAt(indx)) {
shouldTransform = false;
break outer;
}
}
} else {
shouldTransform = false;
break;
}
lhsBuffer.delete(0, lhsBuffer.length());
rhsBuffer.delete(0, rhsBuffer.length());
}
// for now check if order by is null
if (shouldTransform && this.orderByAttrs == null) {
this.modifyGroupByToOrderBy(true, context);
} else {
throw new QueryInvalidException(LocalizedStrings.DefaultQuery_PROJ_COL_ABSENT_IN_GROUP_BY.toLocalizedString() + " or " + LocalizedStrings.DefaultQuery_GROUP_BY_COL_ABSENT_IN_PROJ.toLocalizedString());
}
}
}
Aggregations