use of org.apache.geode.cache.query.internal.CompiledIteratorDef in project geode by apache.
the class PrimaryKeyIndexCreationHelper method prepareFromClause.
private void prepareFromClause(IndexManager imgr) throws IndexInvalidException {
List list = this.compiler.compileFromClause(fromClause);
if (list.size() > 1) {
throw new IndexInvalidException(LocalizedStrings.PrimaryKeyIndexCreationHelper_THE_FROMCLAUSE_FOR_A_PRIMARY_KEY_INDEX_SHOULD_ONLY_HAVE_ONE_ITERATOR_AND_THE_COLLECTION_MUST_BE_A_REGION_PATH_ONLY.toLocalizedString());
}
try {
CompiledIteratorDef iterDef = (CompiledIteratorDef) list.get(0);
if (iterDef.getCollectionExpr().getType() != OQLLexerTokenTypes.RegionPath) {
throw new IndexInvalidException(LocalizedStrings.PrimaryKeyIndexCreationHelper_THE_FROMCLAUSE_FOR_A_PRIMARY_KEY_INDEX_SHOULD_BE_A_REGION_PATH_ONLY.toLocalizedString());
}
iterDef.computeDependencies(this.context);
RuntimeIterator rIter = (iterDef.getRuntimeIterator(this.context));
String definition = rIter.getDefinition();
this.canonicalizedIteratorDefinitions = new String[1];
this.canonicalizedIteratorDefinitions[0] = definition;
// Bind the Index_Internal_ID to the RuntimeIterator
PartitionedRegion pr = this.context.getPartitionedRegion();
this.canonicalizedIteratorNames = new String[1];
String name = null;
if (pr != null) {
name = pr.getIndexManager().putCanonicalizedIteratorNameIfAbsent(definition);
} else {
name = imgr.putCanonicalizedIteratorNameIfAbsent(definition);
}
rIter.setIndexInternalID(name);
this.canonicalizedIteratorNames = new String[1];
this.canonicalizedIteratorNames[0] = name;
this.fromClause = new StringBuilder(definition).append(' ').append(name).toString();
context.bindIterator(rIter);
} catch (IndexInvalidException e) {
// propagate
throw e;
} catch (Exception e) {
// wrap any other exceptions
throw new IndexInvalidException(e);
}
}
use of org.apache.geode.cache.query.internal.CompiledIteratorDef in project geode by apache.
the class IndexCreationInternalsJUnitTest method testLoneFromClause.
@Test
public void testLoneFromClause() throws Exception {
// compileFromClause returns a List<CompiledIteratorDef>
QCompiler compiler = new QCompiler();
List list = compiler.compileFromClause("/pos p, p.positions");
assertEquals(2, list.size());
CompiledIteratorDef first = (CompiledIteratorDef) list.get(0);
assertEquals("p", first.getName());
assertEquals("/pos", ((CompiledRegion) first.getCollectionExpr()).getRegionPath());
assertEquals(TypeUtils.OBJECT_TYPE, first.getElementType());
CompiledIteratorDef second = (CompiledIteratorDef) list.get(1);
assertNull(second.getName());
CompiledPath path = (CompiledPath) second.getCollectionExpr();
assertEquals("p", ((CompiledID) path.getReceiver()).getId());
assertEquals("positions", path.getTailID());
assertEquals(TypeUtils.OBJECT_TYPE, second.getElementType());
}
use of org.apache.geode.cache.query.internal.CompiledIteratorDef in project geode by apache.
the class ServerCQImpl method constructServerSideQuery.
/**
* Returns parameterized query used by the server. This method replaces Region name with $1 and if
* type is not specified in the query, looks for type from cqattributes and appends into the
* query.
*
* @return String modified query.
*/
private Query constructServerSideQuery() throws QueryException {
InternalCache cache = cqService.getInternalCache();
DefaultQuery locQuery = (DefaultQuery) cache.getLocalQueryService().newQuery(this.queryString);
CompiledSelect select = locQuery.getSimpleSelect();
CompiledIteratorDef from = (CompiledIteratorDef) select.getIterators().get(0);
// WARNING: ASSUMES QUERY WAS ALREADY VALIDATED FOR PROPER "FORM" ON CLIENT;
// THIS VALIDATION WILL NEED TO BE DONE ON THE SERVER FOR NATIVE CLIENTS,
// BUT IS NOT DONE HERE FOR JAVA CLIENTS.
// The query was already checked on the client that the sole iterator is a
// CompiledRegion
this.regionName = ((CompiledRegion) from.getCollectionExpr()).getRegionPath();
from.setCollectionExpr(new CompiledBindArgument(1));
return locQuery;
}
Aggregations