use of org.apache.geode.cache.query.internal.QCompiler in project geode by apache.
the class QueryDataFunction method compileQuery.
/**
* Compile the query and return a set of regions involved in the query It throws an
* QueryInvalidException if the query is not proper
*
* @param cache current cache
* @param query input query
*
* @return a set of regions involved in the query
*/
private static Set<String> compileQuery(final InternalCache cache, final String query) throws QueryInvalidException {
QCompiler compiler = new QCompiler();
Set<String> regionsInQuery;
try {
CompiledValue compiledQuery = compiler.compileQuery(query);
Set<String> regions = new HashSet<>();
compiledQuery.getRegionsInQuery(regions, null);
regionsInQuery = Collections.unmodifiableSet(regions);
return regionsInQuery;
} catch (QueryInvalidException qe) {
logger.error("{} Failed, Error {}", query, qe.getMessage(), qe);
throw qe;
}
}
use of org.apache.geode.cache.query.internal.QCompiler in project geode by apache.
the class RangeIndexAPIJUnitTest method bindIterators.
private void bindIterators(ExecutionContext context, String string) throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
QCompiler compiler = new QCompiler();
List compilerItrDefs = compiler.compileFromClause(string);
context.newScope(0);
for (Object itrDef : compilerItrDefs) {
CompiledIteratorDef iterDef = (CompiledIteratorDef) itrDef;
RuntimeIterator rIter = iterDef.getRuntimeIterator(context);
context.bindIterator(rIter);
}
}
use of org.apache.geode.cache.query.internal.QCompiler 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.internal.QCompiler 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.QCompiler in project geode by apache.
the class PartitionedRegionDataStore method getIndexes.
private List getIndexes(String rootRegion, String bucketRegion) {
List indexes = null;
if (!this.partitionedRegion.isIndexed()) {
return indexes;
}
// Get PR indexes.
Map indexMap = this.partitionedRegion.getIndex();
if (indexMap == null || indexMap.isEmpty()) {
return indexes;
}
// Build index info thats used to create indexes on bucket regions.
indexes = new ArrayList();
Set indexSet = indexMap.entrySet();
for (Iterator it = indexSet.iterator(); it.hasNext(); ) {
try {
Map.Entry indexEntry = (Map.Entry) it.next();
PartitionedIndex index = (PartitionedIndex) indexEntry.getValue();
IndexCreationData icd = new IndexCreationData(index.getName());
new QCompiler();
String imports = index.getImports();
icd.setIndexData(index.getType(), index.getCanonicalizedFromClause(), index.getCanonicalizedIndexedExpression(), index.getImports());
icd.setPartitionedIndex(index);
indexes.add(icd);
} catch (Exception ignor) {
// since bucket creation should not fail.
logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegionDataStore_EXCPETION__IN_BUCKET_INDEX_CREATION_, ignor.getLocalizedMessage()), ignor);
}
}
return indexes;
}
Aggregations