scanCollExpr.setSourceLocation(exprSourceLoc); UnnestOperator unnestOp = new UnnestOperator(unnestVar, new MutableObject<>(scanCollExpr)); unnestOp.getInputs().add(new MutableObject<>(opAndVar.first)); unnestOp.setSourceLocation(exprSourceLoc); inputOpRefsToUnion.add(new MutableObject<>(unnestOp));
/** * This method is to inline one variable * * @param usedVar * A variable that is used by the scan-collection function in the unnest operator * @param unnestOp * The unnest operator. * @throws AlgebricksException */ private void inlineVariable(LogicalVariable usedVar, UnnestOperator unnestOp) throws AlgebricksException { AbstractFunctionCallExpression expr = (AbstractFunctionCallExpression) unnestOp.getExpressionRef().getValue(); List<Pair<AbstractFunctionCallExpression, Integer>> parentAndIndexList = new ArrayList<Pair<AbstractFunctionCallExpression, Integer>>(); getParentFunctionExpression(usedVar, expr, parentAndIndexList); ILogicalExpression usedVarOrginExpr = findUsedVarOrigin(usedVar, unnestOp, (AbstractLogicalOperator) unnestOp.getInputs().get(0).getValue()); if (usedVarOrginExpr != null) { for (Pair<AbstractFunctionCallExpression, Integer> parentAndIndex : parentAndIndexList) { //we only rewrite the top scan-collection function if (parentAndIndex.first.getFunctionIdentifier() == BuiltinFunctions.SCAN_COLLECTION && parentAndIndex.first == expr) { unnestOp.getExpressionRef().setValue(usedVarOrginExpr); } } } }
AbstractLogicalOperator op2 = (AbstractLogicalOperator) unnest.getInputs().get(0).getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) { return false; datascan.getVariables().get(0)); AssignOperator noOp = new AssignOperator(unnest.getVariable(), varExp); noOp.getInputs().addAll(unnest.getInputs()); opRef.setValue(noOp); return true;
private ILogicalPlan translateMainModule(MainModuleNode moduleNode) throws SystemException { QueryBodyNode qbn = moduleNode.getQueryBody(); ASTNode queryBody = qbn.getExpression(); TranslationContext tCtx = new TranslationContext(null, new EmptyTupleSourceOperator()); LogicalVariable lVar = translateExpression(queryBody, tCtx); LogicalVariable iLVar = newLogicalVariable(); UnnestOperator unnest = new UnnestOperator(iLVar, mutable(ufce(BuiltinOperators.ITERATE, vre(lVar)))); unnest.getInputs().add(mutable(tCtx.op)); List<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>(); exprs.add(mutable(vre(iLVar))); QueryResultSetDataSink sink = new QueryResultSetDataSink(ccb.getResultSetId(), null); DistributeResultOperator op = new DistributeResultOperator(exprs, sink); op.getInputs().add(mutable(unnest)); ALogicalPlanImpl lp = new ALogicalPlanImpl(mutable(op)); return lp; }
AbstractLogicalOperator op2 = (AbstractLogicalOperator) unnest.getInputs().get(0).getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return null;
UnnestOperator unnest = new UnnestOperator(var, new MutableObject<ILogicalExpression>(scanCollExpr)); unnest.setSourceLocation(assign.getSourceLocation()); unnest.getInputs().addAll(assign.getInputs()); opRef.setValue(unnest); context.computeAndSetTypeEnvironmentForOperator(unnest);
unnestOperator.getInputs().add(nextOperatorRef); nextOperatorRef = new MutableObject<ILogicalOperator>(unnestOperator);
scan.setSourceLocation(unnest.getSourceLocation()); List<Mutable<ILogicalOperator>> scanInpList = scan.getInputs(); scanInpList.addAll(unnest.getInputs()); opRef.setValue(scan); context.computeAndSetTypeEnvironmentForOperator(scan);
scan.setSourceLocation(unnest.getSourceLocation()); List<Mutable<ILogicalOperator>> scanInpList = scan.getInputs(); scanInpList.addAll(unnest.getInputs()); opRef.setValue(scan); context.computeAndSetTypeEnvironmentForOperator(scan);
Mutable<ILogicalOperator> opRef2 = unnest.getInputs().get(0); AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); AssignOperator assign = (AssignOperator) op2;
scan.setSourceLocation(unnest.getSourceLocation()); List<Mutable<ILogicalOperator>> scanInpList = scan.getInputs(); scanInpList.addAll(unnest.getInputs()); opRef.setValue(scan); addPrimaryKey(variables, dataSource, context);
unnest.getInputs().add(mutable(tCtx.op)); tCtx.op = unnest; ++pushCount;
private void iterateOver(ILogicalExpression ctxExpr, TranslationContext tCtx) { LogicalVariable seqLVar = createAssignment(ctxExpr, tCtx); LogicalVariable lastLVar = createAssignment(sfce(BuiltinFunctions.FN_COUNT_1, vre(seqLVar)), tCtx); tCtx.varScope.registerVariable(new XQueryVariable(XMLQueryCompilerConstants.LAST_VAR_NAME, SequenceType.create(BuiltinTypeRegistry.XS_INTEGER, Quantifier.QUANT_ONE), lastLVar)); LogicalVariable forLVar = newLogicalVariable(); LogicalVariable posLVar = newLogicalVariable(); UnnestOperator unnest = new UnnestOperator(forLVar, mutable(ufce(BuiltinOperators.ITERATE, vre(seqLVar))), posLVar, BuiltinTypeRegistry.XS_INTEGER, new VXQueryPositionWriter()); SequenceType forVarType = SequenceType.create(AnyItemType.INSTANCE, Quantifier.QUANT_ONE); XQueryVariable forVar = new XQueryVariable(XMLQueryCompilerConstants.DOT_VAR_NAME, forVarType, forLVar); tCtx.varScope.registerVariable(forVar); SequenceType posVarType = SequenceType.create(BuiltinTypeRegistry.XS_INTEGER, Quantifier.QUANT_ONE); XQueryVariable posVar = new XQueryVariable(XMLQueryCompilerConstants.POS_VAR_NAME, posVarType, posLVar); tCtx.varScope.registerVariable(posVar); unnest.getInputs().add(mutable(tCtx.op)); tCtx.op = unnest; }
unnestOp = new UnnestOperator(fromVar, new MutableObject<>(makeUnnestExpression(eo.first))); unnestOp.getInputs().add(eo.second); unnestOp.setSourceLocation(sourceLoc);