use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class AbstractExecution method handleException.
private void handleException(Throwable functionException, final Function fn, final FunctionContext cx, final ResultSender sender, DM dm) {
FunctionStats stats = FunctionStats.getFunctionStats(fn.getId(), dm.getSystem());
if (logger.isDebugEnabled()) {
logger.debug("Exception occurred on local node while executing Function: {}", fn.getId(), functionException);
}
stats.endFunctionExecutionWithException(fn.hasResult());
if (fn.hasResult()) {
if (waitOnException || forwardExceptions) {
if (functionException instanceof FunctionException && functionException.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).
functionException = new FunctionException(functionException.getLocalizedMessage());
}
sender.lastResult(functionException);
} else {
((InternalResultSender) sender).setException(functionException);
}
} else {
logger.warn(LocalizedMessage.create(LocalizedStrings.FunctionService_EXCEPTION_ON_LOCAL_NODE), functionException);
}
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class IndexCreationInternalsJUnitTest method testLoneProjectionAttributes.
@Test
public void testLoneProjectionAttributes() throws Exception {
// compileProjectionAttributes returns a List or null.
// null if '*', or a List<Object[2]>.
// The two-element Object arrays are:
// 0: a String, the field name, or null if no identifier provided
// 1: The CompiledValue for the projection expression.
QCompiler compiler = new QCompiler();
List list = compiler.compileProjectionAttributes("*");
assertNull(list);
compiler = new QCompiler();
list = compiler.compileProjectionAttributes("ID, status");
assertEquals(2, list.size());
Object[] firstProj = (Object[]) list.get(0);
assertEquals(2, firstProj.length);
// no field name
assertNull(firstProj[0]);
CompiledID id1 = (CompiledID) firstProj[1];
assertEquals("ID", id1.getId());
Object[] secondProj = (Object[]) list.get(1);
assertEquals(2, secondProj.length);
// no field name
assertNull(secondProj[0]);
CompiledID id2 = (CompiledID) secondProj[1];
assertEquals("status", id2.getId());
// test two ways of specifying the field names
compiler = new QCompiler();
list = compiler.compileProjectionAttributes("x: ID, y: status");
assertEquals(2, list.size());
firstProj = (Object[]) list.get(0);
assertEquals(2, firstProj.length);
assertEquals("x", firstProj[0]);
id1 = (CompiledID) firstProj[1];
assertEquals("ID", id1.getId());
secondProj = (Object[]) list.get(1);
assertEquals(2, secondProj.length);
assertEquals("y", secondProj[0]);
id2 = (CompiledID) secondProj[1];
assertEquals("status", id2.getId());
// the following is invalid
try {
compiler = new QCompiler();
list = compiler.compileProjectionAttributes("ID x, status y");
fail("Should have thrown a QueryInvalidException");
} catch (QueryInvalidException e) {
// pass
}
// test three ways of specifying the field names
compiler = new QCompiler();
list = compiler.compileProjectionAttributes("ID AS x, status as y");
assertEquals(2, list.size());
firstProj = (Object[]) list.get(0);
assertEquals(2, firstProj.length);
assertEquals("x", firstProj[0]);
id1 = (CompiledID) firstProj[1];
assertEquals("ID", id1.getId());
secondProj = (Object[]) list.get(1);
assertEquals(2, secondProj.length);
assertEquals("y", secondProj[0]);
id2 = (CompiledID) secondProj[1];
assertEquals("status", id2.getId());
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class QCompiler method compileFromClause.
/** Returns List<CompiledIteratorDef> */
public List compileFromClause(String fromClause) {
try {
OQLLexer lexer = new OQLLexer(new StringReader(fromClause));
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.loneFromClause();
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 (List) pop();
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class QCompiler method resolveType.
public ObjectType resolveType(String typeName) {
if (typeName == null) {
if (logger.isTraceEnabled()) {
logger.trace("QCompiler.resolveType= {}", Object.class.getName());
}
return TypeUtils.OBJECT_TYPE;
}
// resolve with imports
String as = null;
if (this.imports != null) {
as = (String) this.imports.get(typeName);
}
if (as != null)
typeName = as;
Class resultClass;
try {
resultClass = InternalDataSerializer.getCachedClass(typeName);
} catch (ClassNotFoundException e) {
throw new QueryInvalidException(LocalizedStrings.QCompiler_TYPE_NOT_FOUND_0.toLocalizedString(typeName), e);
}
if (logger.isTraceEnabled()) {
logger.trace("QCompiler.resolveType= {}", resultClass.getName());
}
return new ObjectTypeImpl(resultClass);
}
use of org.apache.geode.cache.query.QueryInvalidException in project geode by apache.
the class RegionProvider method getOrCreateRegion0.
private Region<?, ?> getOrCreateRegion0(ByteArrayWrapper key, RedisDataType type, ExecutionHandlerContext context, boolean addToMeta) {
checkDataType(key, type);
Region<?, ?> r = this.regions.get(key);
if (r != null && r.isDestroyed()) {
removeKey(key, type);
r = null;
}
if (r == null) {
String stringKey = key.toString();
Lock lock = this.locks.get(stringKey);
if (lock == null) {
this.locks.putIfAbsent(stringKey, new ReentrantLock());
lock = this.locks.get(stringKey);
}
try {
lock.lock();
r = regions.get(key);
if (r == null) {
// Can create
boolean hasTransaction = context != null && context.hasTransaction();
// without context
CacheTransactionManager txm = null;
TransactionId transactionId = null;
try {
if (hasTransaction) {
txm = cache.getCacheTransactionManager();
transactionId = txm.suspend();
}
Exception concurrentCreateDestroyException = null;
do {
concurrentCreateDestroyException = null;
r = createRegionGlobally(stringKey);
try {
if (type == RedisDataType.REDIS_LIST) {
doInitializeList(key, r);
} else if (type == RedisDataType.REDIS_SORTEDSET) {
try {
doInitializeSortedSet(key, r);
} catch (RegionNotFoundException | IndexInvalidException e) {
concurrentCreateDestroyException = e;
}
}
} catch (QueryInvalidException e) {
if (e.getCause() instanceof RegionNotFoundException) {
concurrentCreateDestroyException = e;
}
}
} while (concurrentCreateDestroyException != null);
this.regions.put(key, r);
if (addToMeta) {
RedisDataType existingType = metaPutIfAbsent(key, type);
if (existingType != null && existingType != type)
throw new RedisDataTypeMismatchException("The key name \"" + key + "\" is already used by a " + existingType.toString());
}
} finally {
if (hasTransaction)
txm.resume(transactionId);
}
}
} finally {
lock.unlock();
}
}
return r;
}
Aggregations