@Override public void substituteVar(LogicalVariable v1, LogicalVariable v2) { if (variable.equals(v1)) { variable = v2; } }
@Override public LogicalVariable newVar() { varCounter++; return new LogicalVariable(varCounter); }
@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 WindowOperator createHelperWindowOperator(List<Mutable<ILogicalExpression>> partExprList, List<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> orderExprList, LogicalVariable rowNumVar, LogicalVariable denseRankVar, ListSet<LogicalVariable> usedVars, SourceLocation sourceLoc) throws CompilationException { WindowOperator winOp = new WindowOperator(partExprList, orderExprList); winOp.setSourceLocation(sourceLoc); for (LogicalVariable usedVar : usedVars) { FunctionIdentifier fid; if (usedVar.equals(rowNumVar)) { fid = BuiltinFunctions.ROW_NUMBER_IMPL; } else if (usedVar.equals(denseRankVar)) { fid = BuiltinFunctions.DENSE_RANK_IMPL; } else { throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, sourceLoc, usedVar.toString()); } AbstractFunctionCallExpression valueExpr = BuiltinFunctions.makeWindowFunctionExpression(fid, new ArrayList<>()); if (BuiltinFunctions.windowFunctionHasProperty(valueExpr.getFunctionIdentifier(), BuiltinFunctions.WindowFunctionProperty.INJECT_ORDER_ARGS)) { for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p : orderExprList) { valueExpr.getArguments().add(new MutableObject<>(p.second.getValue().cloneExpression())); } } valueExpr.setSourceLocation(winOp.getSourceLocation()); winOp.getVariables().add(usedVar); winOp.getExpressions().add(new MutableObject<>(valueExpr)); } return winOp; } }
@Override public String toString() { return column.toString() + "(" + order + ")"; } }
@Override public int hashCode() { return tupleRef + variable.hashCode(); }
for (Mutable<ILogicalExpression> expr : primaryKeyExprs) { VariableReferenceExpression varRefExpr = (VariableReferenceExpression) expr.getValue(); primaryKeyLogicalVars.add(new LogicalVariable(varRefExpr.getVariableReference().getId()));
@Override public String toString() { return variable.toString(); }
private boolean varEquivalent(LogicalVariable left, LogicalVariable right) { if (variableMapping.get(right) == null) { return false; } return variableMapping.get(right).equals(left); }
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; }
@Override public LogicalVariable newVar(String displayName) { varCounter++; return new LogicalVariable(varCounter, displayName); }
protected void pprintVeList(List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> vePairList, Integer indent) throws AlgebricksException { buffer.append("["); boolean first = true; for (Pair<LogicalVariable, Mutable<ILogicalExpression>> ve : vePairList) { if (first) { first = false; } else { buffer.append(","); } if (ve.first != null) { buffer.append("{\"variable\": \"" + ve.first.toString().replace('"', ' ') + "\"," + "\"expression\": \"" + ve.second.toString().replace('"', ' ') + "\"}"); } else { buffer.append("{\"expression\": \"" + ve.second.getValue().accept(exprVisitor, indent).replace('"', ' ') + "\"}"); } } buffer.append("]"); }
private boolean isIdentical(List<LogicalVariable> finalSchema, List<LogicalVariable> inputSchema) throws AlgebricksException { int finalSchemaSize = finalSchema.size(); int inputSchemaSize = inputSchema.size(); if (finalSchemaSize != inputSchemaSize) { return false; } for (int i = 0; i < finalSchemaSize; i++) { LogicalVariable var1 = finalSchema.get(i); LogicalVariable var2 = inputSchema.get(i); if (!var1.equals(var2)) { return false; } } return true; }
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; }
public LogicalVariable createNewVar() { varCounter++; LogicalVariable var = new LogicalVariable(-varCounter); return var; }
@Override public Object getVarType(LogicalVariable var, List<LogicalVariable> nonNullVariables, List<List<LogicalVariable>> correlatedNullableVariableLists) throws AlgebricksException { if (var.equals(optFuncExpr.getSourceVar(exprAndVarIdx.second))) { return keyType; } throw new IllegalArgumentException(); }
@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; }
private LogicalVariable newLogicalVariable() { return new LogicalVariable(varCounter++); }
@Override public Object getVarType(LogicalVariable var) throws AlgebricksException { if (var.equals(optFuncExpr.getSourceVar(exprAndVarIdx.second))) { return keyType; } throw new IllegalArgumentException(); }