@Override public boolean equals(Object obj) { if (obj instanceof LogicalVariable) { return id == ((LogicalVariable) obj).getId(); } return false; }
@Override public PhysicalRequirements getRequiredPropertiesForChildren(ILogicalOperator op, IPhysicalPropertiesVector reqdByParent, IOptimizationContext context) { //skVarMap is used to remove duplicated variable references for order operator Map<Integer, Object> skVarMap = new HashMap<Integer, Object>(); List<LogicalVariable> scanVariables = new ArrayList<>(); scanVariables.addAll(primaryKeys); scanVariables.add(new LogicalVariable(-1)); IPhysicalPropertiesVector physicalProps = dataSourceIndex.getDataSource().getPropertiesProvider().computePropertiesVector(scanVariables); List<ILocalStructuralProperty> localProperties = new ArrayList<>(); List<OrderColumn> orderColumns = new ArrayList<OrderColumn>(); // Data needs to be sorted based on the [token, number of token, PK] // OR [token, PK] if the index is not partitioned for (LogicalVariable skVar : secondaryKeys) { if (!skVarMap.containsKey(skVar.getId())) { orderColumns.add(new OrderColumn(skVar, OrderKind.ASC)); skVarMap.put(skVar.getId(), null); } } for (LogicalVariable pkVar : primaryKeys) { orderColumns.add(new OrderColumn(pkVar, OrderKind.ASC)); } localProperties.add(new LocalOrderProperty(orderColumns)); StructuralPropertiesVector spv = new StructuralPropertiesVector(physicalProps.getPartitioningProperty(), localProperties); return new PhysicalRequirements(new IPhysicalPropertiesVector[] { spv }, IPartitioningRequirementsCoordinator.NO_COORDINATION); }
private UniqueNodes propagateUniqueNodes(ILogicalExpression expr, HashMap<Integer, UniqueNodes> variableMap) { UniqueNodes uniqueNodes = null; switch (expr.getExpressionTag()) { case FUNCTION_CALL: AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) expr; // Look up all arguments. List<UniqueNodes> argProperties = new ArrayList<UniqueNodes>(); for (Mutable<ILogicalExpression> argExpr : functionCall.getArguments()) { argProperties.add(propagateUniqueNodes(argExpr.getValue(), variableMap)); } // Propagate the property. Function func = (Function) functionCall.getFunctionInfo(); uniqueNodes = func.getUniqueNodesPropagationPolicy().propagate(argProperties); break; case VARIABLE: VariableReferenceExpression variableReference = (VariableReferenceExpression) expr; int argVariableId = variableReference.getVariableReference().getId(); uniqueNodes = variableMap.get(argVariableId); break; case CONSTANT: default: uniqueNodes = UniqueNodes.YES; break; } return uniqueNodes; }
private DocumentOrder propagateDocumentOrder(ILogicalExpression expr, HashMap<Integer, DocumentOrder> variableMap) { DocumentOrder documentOrder = null; switch (expr.getExpressionTag()) { case FUNCTION_CALL: AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) expr; // Look up all arguments. List<DocumentOrder> argProperties = new ArrayList<DocumentOrder>(); for (Mutable<ILogicalExpression> argExpr : functionCall.getArguments()) { argProperties.add(propagateDocumentOrder(argExpr.getValue(), variableMap)); } // Propagate the property. Function func = (Function) functionCall.getFunctionInfo(); documentOrder = func.getDocumentOrderPropagationPolicy().propagate(argProperties); break; case VARIABLE: VariableReferenceExpression variableReference = (VariableReferenceExpression) expr; int argVariableId = variableReference.getVariableReference().getId(); documentOrder = variableMap.get(argVariableId); break; case CONSTANT: default: documentOrder = DocumentOrder.YES; break; } return documentOrder; }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (context.checkIfInDontApplySet(this, opRef.getValue())) { return false; } int variableId = 0; // TODO Move the setVarCounter to the compiler after the translator has run. AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); switch (op.getOperatorTag()) { case ASSIGN: case AGGREGATE: AbstractAssignOperator assign = (AbstractAssignOperator) op; variableId = assign.getVariables().get(0).getId(); break; case UNNEST: UnnestOperator unnest = (UnnestOperator) op; variableId = unnest.getVariable().getId(); break; default: return false; } if (context.getVarCounter() <= variableId) { context.setVarCounter(variableId + 1); } context.addToDontApplySet(this, opRef.getValue()); return false; }
ILogicalExpression aggregateLogicalExpression = (ILogicalExpression) aggregate.getExpressions() .get(index).getValue(); variableId = aggregate.getVariables().get(index).getId(); documentOrder = propagateDocumentOrder(aggregateLogicalExpression, documentOrderVariablesForOperator); ILogicalExpression assignLogicalExpression = (ILogicalExpression) assign.getExpressions() .get(index).getValue(); variableId = assign.getVariables().get(index).getId(); documentOrder = propagateDocumentOrder(assignLogicalExpression, documentOrderVariablesForOperator); uniqueNodes = propagateUniqueNodes(assignLogicalExpression, uniqueNodesVariablesForOperator); variableId = variableExpression.getVariableReference().getId(); variableId = unnest.getVariables().get(0).getId(); Cardinality inputCardinality = vxqueryContext.getCardinalityOperatorMap(op.getInputs().get(0) .getValue()); variableId = unnest.getPositionalVariable().getId(); if (inputCardinality == Cardinality.ONE) { documentOrderVariables.put(variableId, DocumentOrder.YES);
private ILogicalOperator createFieldAccessAssignOperator(LogicalVariable recordVar, Set<LogicalVariable> inputLiveVars, SourceLocation sourceLoc) { List<LogicalVariable> fieldAccessVars = new ArrayList<>(); List<Mutable<ILogicalExpression>> fieldAccessExprs = new ArrayList<>(); // Adds field access by name. for (LogicalVariable inputLiveVar : inputLiveVars) { if (!correlatedKeyVars.contains(inputLiveVar)) { // field Var LogicalVariable newVar = context.newVar(); fieldAccessVars.add(newVar); // fieldAcess expr List<Mutable<ILogicalExpression>> argRefs = new ArrayList<>(); VariableReferenceExpression recordVarRef = new VariableReferenceExpression(recordVar); recordVarRef.setSourceLocation(sourceLoc); argRefs.add(new MutableObject<>(recordVarRef)); argRefs.add(new MutableObject<>(new ConstantExpression( new AsterixConstantValue(new AString(Integer.toString(inputLiveVar.getId())))))); ScalarFunctionCallExpression faExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME), argRefs); faExpr.setSourceLocation(sourceLoc); fieldAccessExprs.add(new MutableObject<>(faExpr)); // Updates variable mapping for ancestor operators. updateInputToOutputVarMapping(inputLiveVar, newVar, false); } } AssignOperator assignOp = new AssignOperator(fieldAccessVars, fieldAccessExprs); assignOp.setSourceLocation(sourceLoc); return assignOp; }
private Pair<ILogicalOperator, LogicalVariable> createRecordConstructorAssignOp(Set<LogicalVariable> inputLiveVars, SourceLocation sourceLoc) { // Creates a nested record. List<Mutable<ILogicalExpression>> recordConstructorArgs = new ArrayList<>(); for (LogicalVariable inputLiveVar : inputLiveVars) { if (!correlatedKeyVars.contains(inputLiveVar)) { recordConstructorArgs.add(new MutableObject<>(new ConstantExpression( new AsterixConstantValue(new AString(Integer.toString(inputLiveVar.getId())))))); VariableReferenceExpression inputLiveVarRef = new VariableReferenceExpression(inputLiveVar); inputLiveVarRef.setSourceLocation(sourceLoc); recordConstructorArgs.add(new MutableObject<>(inputLiveVarRef)); } } LogicalVariable recordVar = context.newVar(); ScalarFunctionCallExpression openRecConstr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR), recordConstructorArgs); openRecConstr.setSourceLocation(sourceLoc); Mutable<ILogicalExpression> recordExprRef = new MutableObject<ILogicalExpression>(openRecConstr); AssignOperator assignOp = new AssignOperator(recordVar, recordExprRef); assignOp.setSourceLocation(sourceLoc); return new Pair<>(assignOp, recordVar); }
private int getOperatorSortDistinctNodesAscOrAtomicsArgumentVariableId(Mutable<ILogicalOperator> opRef) { // Check if assign is for sort-distinct-nodes-asc-or-atomics. AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return 0; } AssignOperator assign = (AssignOperator) op; // Check to see if the expression is a function and // sort-distinct-nodes-asc-or-atomics. ILogicalExpression logicalExpression = (ILogicalExpression) assign.getExpressions().get(0).getValue(); if (logicalExpression.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return 0; } AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) logicalExpression; if (!functionCall.getFunctionIdentifier().equals( BuiltinOperators.SORT_DISTINCT_NODES_ASC_OR_ATOMICS.getFunctionIdentifier())) { return 0; } // Find the variable id used as the parameter. ILogicalExpression logicalExpression2 = (ILogicalExpression) functionCall.getArguments().get(0).getValue(); if (logicalExpression2.getExpressionTag() != LogicalExpressionTag.VARIABLE) { return 0; } VariableReferenceExpression variableExpression = (VariableReferenceExpression) logicalExpression2; return variableExpression.getVariableReference().getId(); }
if (variableId != aggregate.getVariables().get(0).getId()) { opSearch = (AbstractLogicalOperator) opSearch.getInputs().get(0).getValue(); continue;
for (Mutable<ILogicalExpression> expr : primaryKeyExprs) { VariableReferenceExpression varRefExpr = (VariableReferenceExpression) expr.getValue(); primaryKeyLogicalVars.add(new LogicalVariable(varRefExpr.getVariableReference().getId()));
int variableId = variableReference.getVariableReference().getId();