use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class QCompiler method compileProjectionAttributes.
/** Returns List<CompiledIteratorDef> or null if projectionAttrs is '*' */
public List compileProjectionAttributes(String projectionAttributes) {
try {
OQLLexer lexer = new OQLLexer(new StringReader(projectionAttributes));
OQLParser parser = new OQLParser(lexer);
// by default use Unsupported AST class, overridden for supported
// operators in the grammer proper
parser.setASTNodeClass("org.apache.geode.cache.query.internal.parse.ASTUnsupported");
parser.loneProjectionAttributes();
GemFireAST n = (GemFireAST) parser.getAST();
// don't compile TOK_STAR
if (n.getType() == TOK_STAR) {
return null;
}
n.compile(this);
} catch (Exception ex) {
// GemFire Exception.
throw new QueryInvalidException(LocalizedStrings.QCompiler_SYNTAX_ERROR_IN_QUERY_0.toLocalizedString(ex.getMessage()), ex);
}
Assert.assertTrue(stackSize() == 1, "stack size = " + stackSize() + ";stack=" + this.stack);
return (List) pop();
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class CompiledGroupBySelectJUnitTest method testInvalidQuery.
@Test
public void testInvalidQuery() throws Exception {
String queryStr = "select count(*) , pf.shortID from /portfolio pf where pf.ID > 0 ";
QueryService qs = CacheUtils.getQueryService();
try {
DefaultQuery query = (DefaultQuery) qs.newQuery(queryStr);
fail("query creation should have failed");
} catch (QueryInvalidException qie) {
assertTrue(qie.toString().indexOf(LocalizedStrings.DefaultQuery_PROJ_COL_ABSENT_IN_GROUP_BY.toLocalizedString()) != -1);
}
queryStr = "select * from /portfolio pf where pf.ID > 0 group by pf.ID";
try {
DefaultQuery query = (DefaultQuery) qs.newQuery(queryStr);
fail("query creation should have failed");
} catch (QueryInvalidException qie) {
assertTrue(qie.toString().indexOf(LocalizedStrings.DefaultQuery_PROJ_COL_ABSENT_IN_GROUP_BY.toLocalizedString()) != -1);
}
queryStr = "select * from /portfolio pf, pf.positions pos where pf.ID > 0 group by pf";
try {
DefaultQuery query = (DefaultQuery) qs.newQuery(queryStr);
fail("query creation should have failed");
} catch (QueryInvalidException qie) {
assertTrue(qie.toString().indexOf("Query contains projected column not present in group by clause") != -1);
}
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class ServerToClientFunctionResultSender65 method writeFunctionExceptionResponse.
@Override
protected void writeFunctionExceptionResponse(ChunkedMessage message, String errormessage, Throwable e) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug(" ServerToClientFunctionResultSender sending Function Error Response : {}", errormessage);
}
int numParts = 0;
message.clear();
if (e instanceof FunctionException && e.getCause() instanceof InternalFunctionInvocationTargetException) {
message.setNumberOfParts(3);
message.addObjPart(e);
message.addStringPart(BaseCommand.getExceptionTrace(e));
InternalFunctionInvocationTargetException fe = (InternalFunctionInvocationTargetException) e.getCause();
message.addObjPart(fe.getFailedNodeSet());
numParts = 3;
} else {
if (e instanceof FunctionException && e.getCause() instanceof QueryInvalidException) {
// Handle this exception differently since it can contain
// non-serializable objects.
// java.io.NotSerializableException: antlr.CommonToken
// create a new FunctionException on the original one's message (not cause).
e = new FunctionException(e.getLocalizedMessage());
}
message.setNumberOfParts(2);
message.addObjPart(e);
message.addStringPart(BaseCommand.getExceptionTrace(e));
numParts = 2;
}
message.setServerConnection(this.sc);
message.setLastChunkAndNumParts(true, numParts);
// message.setLastChunk(true);
message.sendChunk(this.sc);
this.sc.setAsTrue(Command.RESPONDED);
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class LocalRegion method constructRegionQueryString.
private String constructRegionQueryString(final String predicate) throws QueryInvalidException {
// send it as is to the server
boolean matches = false;
for (Pattern queryPattern : QUERY_PATTERNS) {
if (queryPattern.matcher(predicate).matches()) {
if (!predicate.contains(getName())) {
throw new QueryInvalidException("Should not execute region.query with a different region in the from clause: " + getName() + " was not present in:" + predicate);
}
matches = true;
break;
}
}
// Compare the query patterns to the 'predicate'. If one matches,
final String queryString;
if (matches) {
queryString = predicate;
} else {
queryString = "select * from " + getFullPath() + " this where " + predicate;
}
return queryString;
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class LocalRegion method query.
@Override
public SelectResults query(String predicate) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
if (predicate == null) {
throw new IllegalArgumentException("The input query predicate is null. A null predicate is not allowed.");
}
predicate = predicate.trim();
SelectResults results;
if (hasServerProxy()) {
// Trim whitespace
String queryString = constructRegionQueryString(predicate.trim());
try {
results = getServerProxy().query(queryString, null);
} catch (Exception e) {
Throwable cause = e.getCause();
if (cause == null) {
cause = e;
}
throw new QueryInvocationTargetException(e.getMessage(), cause);
}
} else {
// TODO: params size is always zero so this whole block is wasted
Object[] params = new Object[0];
QueryService qs = getGemFireCache().getLocalQueryService();
String queryStr = constructRegionQueryString(predicate.trim());
DefaultQuery query = (DefaultQuery) qs.newQuery(queryStr);
if (query.getRegionsInQuery(params).size() != 1) {
throw new QueryInvalidException("Prevent multiple region query from being executed through region.query()");
}
results = (SelectResults) query.execute(params);
}
return results;
}
Aggregations