use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class QCompiler method compileQuery.
/*
* compile the string into a Query (returns the root CompiledValue)
*/
public CompiledValue compileQuery(String oqlSource) {
try {
OQLLexer lexer = new OQLLexer(new StringReader(oqlSource));
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.queryProgram();
GemFireAST n = (GemFireAST) parser.getAST();
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());
return (CompiledValue) pop();
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class QCompiler method indexOp.
public void indexOp() {
// find the List of index expressions and the receiver on the stack
Object indexParams = pop();
final CompiledValue rcvr = (CompiledValue) TypeUtils.checkCast(pop(), CompiledValue.class);
CompiledValue indexExpr = CompiledValue.MAP_INDEX_ALL_KEYS;
if (indexParams != null) {
final List indexList = (List) TypeUtils.checkCast(indexParams, List.class);
if (!isForIndexCompilation && indexList.size() != 1) {
throw new UnsupportedOperationException(LocalizedStrings.QCompiler_ONLY_ONE_INDEX_EXPRESSION_SUPPORTED.toLocalizedString());
}
if (indexList.size() == 1) {
indexExpr = (CompiledValue) TypeUtils.checkCast(indexList.get(0), CompiledValue.class);
if (indexExpr.getType() == TOK_COLON) {
throw new UnsupportedOperationException(LocalizedStrings.QCompiler_RANGES_NOT_SUPPORTED_IN_INDEX_OPERATORS.toLocalizedString());
}
indexExpr = (CompiledValue) TypeUtils.checkCast(indexList.get(0), CompiledValue.class);
push(new CompiledIndexOperation(rcvr, indexExpr));
} else {
assert this.isForIndexCompilation;
MapIndexable mi = new MapIndexOperation(rcvr, indexList);
push(mi);
}
} else {
if (!this.isForIndexCompilation) {
throw new QueryInvalidException(LocalizedStrings.QCompiler_SYNTAX_ERROR_IN_QUERY_0.toLocalizedString("* use incorrect"));
}
push(new CompiledIndexOperation(rcvr, indexExpr));
}
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class QCompiler method select.
public void select(Map<Integer, Object> queryComponents) {
CompiledValue limit = null;
Object limitObject = queryComponents.remove(OQLLexerTokenTypes.LIMIT);
if (limitObject instanceof Integer) {
limit = new CompiledLiteral(limitObject);
} else {
limit = (CompiledBindArgument) limitObject;
}
List<CompiledSortCriterion> orderByAttrs = (List<CompiledSortCriterion>) queryComponents.remove(OQLLexerTokenTypes.LITERAL_order);
List iterators = (List) queryComponents.remove(OQLLexerTokenTypes.LITERAL_from);
List projAttrs = (List) queryComponents.remove(OQLLexerTokenTypes.PROJECTION_ATTRS);
if (projAttrs == null) {
// remove any * or all attribute
queryComponents.remove(OQLLexerTokenTypes.TOK_STAR);
queryComponents.remove(OQLLexerTokenTypes.LITERAL_all);
}
// "COUNT" or null
/*
* String aggrExpr = (String) queryComponents .remove(OQLLexerTokenTypes.LITERAL_count);
*/
// "DISTINCT" or null
String distinct = (String) queryComponents.remove(OQLLexerTokenTypes.LITERAL_distinct);
List<String> hints = null;
Object hintObject = queryComponents.remove(OQLLexerTokenTypes.LITERAL_hint);
if (hintObject != null) {
hints = (List<String>) hintObject;
}
List<CompiledValue> groupByClause = (List<CompiledValue>) queryComponents.remove(OQLLexerTokenTypes.LITERAL_group);
// whatever remains , treat it as where
// whereClause
CompiledValue where = null;
if (queryComponents.size() == 1) {
where = (CompiledValue) queryComponents.values().iterator().next();
} else if (queryComponents.size() > 1) {
throw new QueryInvalidException("Unexpected/unsupported query clauses found");
}
LinkedHashMap<Integer, CompiledAggregateFunction> aggMap = identifyAggregateExpressions(projAttrs);
boolean isCountOnly = checkForCountOnly(aggMap, projAttrs, groupByClause);
if (isCountOnly) {
projAttrs = null;
}
CompiledSelect select = createSelect(distinct != null, isCountOnly, where, iterators, projAttrs, orderByAttrs, limit, hints, groupByClause, aggMap);
push(select);
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class Query651 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();
long compiledQueryId = 0;
Object[] queryParams = null;
try {
if (clientMessage.getMessageType() == MessageType.QUERY_WITH_PARAMETERS) {
// Query with parameters supported from 6.6 onwards.
// Number of parameters.
int params = clientMessage.getPart(1).getInt();
// In case of native client there will be extra two parameters at 2 and 3 index.
int paramStartIndex = 2;
if (clientMessage.getNumberOfParts() > (1 + /* type */
1 + /* query string */
1 + /* params length */
params)) {
int timeout = clientMessage.getPart(3).getInt();
serverConnection.setRequestSpecificTimeout(timeout);
paramStartIndex = 4;
}
// Get the query execution parameters.
queryParams = new Object[params];
for (int i = 0; i < queryParams.length; i++) {
queryParams[i] = clientMessage.getPart(i + paramStartIndex).getObject();
}
} else {
// need to take care while adding new message
if (clientMessage.getNumberOfParts() == 3) {
int timeout = clientMessage.getPart(2).getInt();
serverConnection.setRequestSpecificTimeout(timeout);
}
}
} catch (ClassNotFoundException cne) {
throw new QueryInvalidException(cne.getMessage() + queryString);
}
if (logger.isDebugEnabled()) {
logger.debug("{}: Received query request from {} queryString: {}{}", serverConnection.getName(), serverConnection.getSocketString(), queryString, (queryParams != null ? (" with num query parameters :" + queryParams.length) : ""));
}
try {
// Create query
QueryService queryService = serverConnection.getCachedRegionHelper().getCache().getLocalQueryService();
org.apache.geode.cache.query.Query query = null;
if (queryParams != null) {
// Its a compiled query.
CacheClientNotifier ccn = serverConnection.getAcceptor().getCacheClientNotifier();
query = ccn.getCompiledQuery(queryString);
if (query == null) {
// This is first time the query is seen by this server.
query = queryService.newQuery(queryString);
ccn.addCompiledQuery((DefaultQuery) query);
}
ccn.getStats().incCompiledQueryUsedCount(1);
((DefaultQuery) query).setLastUsed(true);
} else {
query = queryService.newQuery(queryString);
}
Set regionNames = ((DefaultQuery) query).getRegionsInQuery(queryParams);
// Authorization check
QueryOperationContext queryContext = null;
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
queryContext = authzRequest.queryAuthorize(queryString, regionNames, queryParams);
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);
}
}
}
processQueryUsingParams(clientMessage, query, queryString, regionNames, start, null, queryContext, serverConnection, true, queryParams);
} catch (QueryInvalidException e) {
throw new QueryInvalidException(e.getMessage() + queryString);
}
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class QCompiler method compileImports.
/**
* Processes import statements only. This compiler instance remembers the imports and can be used
* to compile other strings with this context info
*/
public void compileImports(String imports) {
try {
OQLLexer lexer = new OQLLexer(new StringReader(imports));
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.loneImports();
GemFireAST n = (GemFireAST) parser.getAST();
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() == 0, "stack size = " + stackSize() + ";stack=" + this.stack);
}
Aggregations