private Set<String> compileQuery(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; } }
public void arithmetic(int opKind) { switch (opKind) { case TOK_PLUS: addition(opKind); break; case TOK_MINUS: subtraction(opKind); break; case TOK_SLASH: division(opKind); break; case TOK_STAR: multiplication(opKind); break; case LITERAL_mod: mod(opKind); break; case TOK_PERCENTAGE: mod(opKind); break; } }
@Override public void compile(QCompiler compiler) { super.compile(compiler); Object expr = compiler.pop(); if (expr instanceof String) { if (((String) expr).equals("*")) { expr = null; } else { throw new QueryInvalidException("invalid parameter to aggregate function"); } } compiler.aggregateFunction((CompiledValue) expr, this.aggFunctionType, this.distinctOnly); } }
public void typecast() { // pop expr and type, apply type, then push result AbstractCompiledValue cmpVal = (AbstractCompiledValue) TypeUtils.checkCast(pop(), AbstractCompiledValue.class); ObjectType objType = assembleType(); cmpVal.setTypecast(objType); push(cmpVal); }
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);
private Region getRegionFromPath(String imports, String fromClause) throws RegionNotFoundException { QCompiler compiler = new QCompiler(); if (imports != null) { compiler.compileImports(imports); } List list = compiler.compileFromClause(fromClause); CompiledValue cv = QueryUtils .obtainTheBottomMostCompiledValue(((CompiledIteratorDef) list.get(0)).getCollectionExpr()); String regionPath = null; if (cv.getType() == OQLLexerTokenTypes.RegionPath) { regionPath = ((CompiledRegion) cv).getRegionPath(); } else { throw new RegionNotFoundException( String.format( "DefaultQueryService::createIndex:First Iterator of Index >From Clause does not evaluate to a Region Path. The from clause used for Index creation is %s", fromClause)); } Region region = cache.getRegion(regionPath); if (region == null) { throw new RegionNotFoundException( String.format("Region ' %s ' not found: from %s", new Object[] {regionPath, fromClause})); } return region; }
/** * Should be constructed from DefaultQueryService * * @see QueryService#newQuery */ public DefaultQuery(String queryString, InternalCache cache, boolean isForRemote) { this.queryString = queryString; QCompiler compiler = new QCompiler(); this.compiledQuery = compiler.compileQuery(queryString); CompiledSelect cs = getSimpleSelect(); if (cs != null && !isForRemote && (cs.isGroupBy() || cs.isOrderBy())) { QueryExecutionContext ctx = new QueryExecutionContext(null, cache); try { cs.computeDependencies(ctx); } catch (QueryException qe) { throw new QueryInvalidException("", qe); } } this.traceOn = compiler.isTraceRequested() || QUERY_VERBOSE; this.cache = cache; this.stats = new DefaultQueryStatistics(); this.cancelationTask = Optional.empty(); }
break; case OQLLexerTokenTypes.Identifier: compiler.appendPathComponent(child.getText()); break; case OQLLexerTokenTypes.TOK_LBRACK: compiler.pushNull(); } else { ((GemFireAST) child).compile(compiler); compiler.indexOp(); break; default:
public ObjectType assembleType() { ObjectType objType = (ObjectType) TypeUtils.checkCast(pop(), ObjectType.class); if (objType instanceof CollectionType) { // pop the elementType ObjectType elementType = assembleType(); if (objType instanceof MapType) { // pop the key type ObjectType keyType = assembleType(); return new MapTypeImpl(objType.resolveClass(), keyType, elementType); } return new CollectionTypeImpl(objType.resolveClass(), elementType); } return objType; }
QCompiler compiler = new QCompiler(); if (imports != null) { compiler.compileImports(imports);
IndexCreationHelper(String fromClause, String projectionAttributes, InternalCache cache) throws IndexInvalidException { this.cache = cache; // The fromClause,indexedExpression & projectionAttributes // will get modified with the canonicalized value , once the // constructor of derived class is over. this.fromClause = fromClause; this.projectionAttributes = projectionAttributes; this.compiler = new QCompiler(true); }
@Override public void compile(QCompiler compiler) { super.compile(compiler); compiler.and(getNumberOfChildren()); }
@Override public void compile(QCompiler compiler) { super.compile(compiler); compiler.arithmetic(getType()); } }
@Override public void compile(QCompiler compiler) { super.compile(compiler); compiler.combine(getNumberOfChildren()); }
@Override public void compile(QCompiler compiler) { super.compile(compiler); compiler.compare(getType()); } }
public void iteratorDef() { // find type id and colln on the stack ObjectType type = assembleType(); // can be null CompiledID id = (CompiledID) TypeUtils.checkCast(pop(), CompiledID.class); // can be null CompiledValue colln = (CompiledValue) TypeUtils.checkCast(pop(), CompiledValue.class); if (type == null) { type = TypeUtils.OBJECT_TYPE; } push(new CompiledIteratorDef(id == null ? null : id.getId(), type, colln)); }
PartitionedIndex index = (PartitionedIndex) indexEntry.getValue(); IndexCreationData icd = new IndexCreationData(index.getName()); new QCompiler(); String imports = index.getImports(); icd.setIndexData(index.getType(), index.getCanonicalizedFromClause(),
QCompiler compiler = new QCompiler(); Set<String> regionsInQuery; try { CompiledValue compiledQuery = compiler.compileQuery(query); Set<String> regions = new HashSet<>(); compiledQuery.getRegionsInQuery(regions, null);