use of org.apache.geode.cache.query.TypeMismatchException in project geode by apache.
the class RangeIndex method evaluate.
private void evaluate(Object key, int operator, Collection results, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, List projAttrib, SelectResults intermediateResults, boolean isIntersection, int limit, boolean applyOrderBy, List orderByAttribs) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
key = TypeUtils.indexKeyFor(key);
boolean multiColOrderBy = false;
boolean asc = true;
if (applyOrderBy) {
CompiledSortCriterion csc = (CompiledSortCriterion) orderByAttribs.get(0);
asc = !csc.getCriterion();
multiColOrderBy = orderByAttribs.size() > 1;
}
limit = multiColOrderBy ? -1 : limit;
try {
switch(operator) {
case OQLLexerTokenTypes.TOK_EQ:
{
addValuesToResult(this.valueToEntriesMap.get(key), results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_LT:
{
NavigableMap sm = this.valueToEntriesMap.headMap(key, false);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_LE:
{
NavigableMap sm = this.valueToEntriesMap.headMap(key, true);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_GT:
{
// Asif:As tail Map returns the SortedMap vie which is greater
// than or equal
// to the key passed, the equal to key needs to be removed.
// However if the boundary key is already part of the
// keysToRemove set
// then we do not have to remove it as it is already taken care
// of
NavigableMap sm = this.valueToEntriesMap.tailMap(key, false);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_GE:
{
NavigableMap sm = this.valueToEntriesMap.tailMap(key, true);
sm = asc ? sm : sm.descendingMap();
addValuesToResult(sm, results, null, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
case OQLLexerTokenTypes.TOK_NE_ALT:
case OQLLexerTokenTypes.TOK_NE:
{
NavigableMap sm = this.valueToEntriesMap;
if (!asc) {
sm = sm.descendingMap();
}
addValuesToResult(sm, results, key, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
nullMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
undefinedMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
break;
}
default:
{
throw new IllegalArgumentException("Operator = " + operator);
}
}
// end switch
} catch (ClassCastException ex) {
if (operator == OQLLexerTokenTypes.TOK_EQ) {
// set
return;
} else if (operator == OQLLexerTokenTypes.TOK_NE || operator == OQLLexerTokenTypes.TOK_NE_ALT) {
// put
// all
// in
// result
NavigableMap sm = this.valueToEntriesMap;
if (!asc) {
sm = sm.descendingMap();
}
addValuesToResult(sm, results, key, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
nullMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
undefinedMappedEntries.addValuesToCollection(results, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
} else {
// otherwise throw exception
throw new TypeMismatchException("", ex);
}
}
}
use of org.apache.geode.cache.query.TypeMismatchException in project geode by apache.
the class ExecutionContext method resolve.
public CompiledValue resolve(String name) throws TypeMismatchException, AmbiguousNameException {
CompiledValue value = resolveAsVariable(name);
if (value != null)
return value;
// attribute name or operation name (no args) of a variable in the current scope when there is
// no ambiguity, i.e. this property name belongs to only one variable in the scope
value = resolveImplicitPath(name);
if (value == null)
// cannot be resolved
throw new TypeMismatchException(LocalizedStrings.ExecutionContext_THE_ATTRIBUTE_OR_METHOD_NAME_0_COULD_NOT_BE_RESOLVED.toLocalizedString(name));
return value;
}
use of org.apache.geode.cache.query.TypeMismatchException in project geode by apache.
the class GroupByQueryDUnitTest method runQuery.
private void runQuery(VM queryVM) throws Exception {
// createIndex(vm0, "compactRangeIndex", "entry.value",
// "/region.entrySet entry");
// Do Puts
queryVM.invoke(new SerializableRunnable("putting data") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("portfolio");
for (int i = 1; i < 200; ++i) {
Portfolio pf = new Portfolio(i);
pf.shortID = (short) ((short) i / 5);
region.put("" + i, pf);
}
}
});
queryVM.invoke(new SerializableRunnable("query") {
public void run() {
try {
QueryService qs = getCache().getQueryService();
String queryStr = "select p.shortID as short_id from /portfolio p where p.ID >= 0 group by short_id ";
Query query = qs.newQuery(queryStr);
SelectResults<Struct> results = (SelectResults<Struct>) query.execute();
Iterator<Struct> iter = results.iterator();
int counter = 0;
while (iter.hasNext()) {
Struct str = iter.next();
assertEquals(counter++, ((Short) str.get("short_id")).intValue());
}
assertEquals(39, counter - 1);
} catch (QueryInvocationTargetException e) {
fail(e.toString());
} catch (NameResolutionException e) {
fail(e.toString());
} catch (TypeMismatchException e) {
fail(e.toString());
} catch (FunctionDomainException e) {
fail(e.toString());
}
}
});
}
use of org.apache.geode.cache.query.TypeMismatchException in project geode by apache.
the class IndexOperatorJUnitTest method testWithNULL.
@Test
public void testWithNULL() throws Exception {
runQuery(null, 0);
runQuery(null, null);
Object[] objectArray = { "a", "b" };
try {
runQuery(objectArray, null);
fail();
} catch (TypeMismatchException e) {
}
HashMap map = new HashMap();
map.put("0", new Integer(11));
map.put("1", new Integer(12));
Object result = runQuery(map, null);
if (result != null)
fail();
}
use of org.apache.geode.cache.query.TypeMismatchException in project geode by apache.
the class GetDeliveredOrders method execute.
public void execute(FunctionContext context) {
Cache c = null;
ArrayList<Object> vals = new ArrayList<Object>();
try {
c = CacheFactory.getAnyInstance();
} catch (CacheClosedException ex) {
vals.add("NoCacheFoundResult");
context.getResultSender().lastResult(vals);
}
String oql = "SELECT o.purchaseOrderNo, o.deliveryDate FROM /orders o WHERE o.deliveryDate != NULL";
final Query query = c.getQueryService().newQuery(oql);
SelectResults result = null;
try {
result = (SelectResults) query.execute();
int resultSize = result.size();
if (result instanceof Collection<?>)
for (Object item : result) {
vals.add(item);
}
} catch (FunctionDomainException e) {
if (c != null)
c.getLogger().info("Caught FunctionDomainException while executing function GetDeliveredOrders: " + e.getMessage());
} catch (TypeMismatchException e) {
if (c != null)
c.getLogger().info("Caught TypeMismatchException while executing function GetDeliveredOrders: " + e.getMessage());
} catch (NameResolutionException e) {
if (c != null)
c.getLogger().info("Caught NameResolutionException while executing function GetDeliveredOrders: " + e.getMessage());
} catch (QueryInvocationTargetException e) {
if (c != null)
c.getLogger().info("Caught QueryInvocationTargetException while executing function GetDeliveredOrders: " + e.getMessage());
}
context.getResultSender().lastResult(vals);
}
Aggregations