@Override public ILogicalOperator visitWindowOperator(WindowOperator op, Void arg) throws AlgebricksException { List<Mutable<ILogicalExpression>> newPartitionExprs = new ArrayList<>(); deepCopyExpressionRefs(op.getPartitionExpressions(), newPartitionExprs); List<Pair<IOrder, Mutable<ILogicalExpression>>> newOrderExprs = deepCopyOrderAndExpression(op.getOrderExpressions()); List<Pair<IOrder, Mutable<ILogicalExpression>>> newFrameValueExprs = deepCopyOrderAndExpression(op.getFrameValueExpressions()); List<Mutable<ILogicalExpression>> newFrameStartExprs = new ArrayList<>(); deepCopyExpressionRefs(newFrameStartExprs, op.getFrameStartExpressions()); List<Mutable<ILogicalExpression>> newFrameEndExprs = new ArrayList<>(); deepCopyExpressionRefs(newFrameEndExprs, op.getFrameEndExpressions()); List<Mutable<ILogicalExpression>> newFrameExclusionExprs = new ArrayList<>(); deepCopyExpressionRefs(newFrameExclusionExprs, op.getFrameExcludeExpressions()); ILogicalExpression newFrameOffset = deepCopyExpressionRef(op.getFrameOffset()).getValue(); List<LogicalVariable> newVariables = new ArrayList<>(); deepCopyVars(newVariables, op.getVariables()); List<Mutable<ILogicalExpression>> newExpressions = new ArrayList<>(); deepCopyExpressionRefs(newExpressions, op.getExpressions()); List<ILogicalPlan> newNestedPlans = new ArrayList<>(); WindowOperator newWinOp = new WindowOperator(newPartitionExprs, newOrderExprs, newFrameValueExprs, newFrameStartExprs, newFrameEndExprs, newFrameExclusionExprs, op.getFrameExcludeNegationStartIdx(), newFrameOffset, op.getFrameMaxObjects(), newVariables, newExpressions, newNestedPlans); for (ILogicalPlan nestedPlan : op.getNestedPlans()) { newNestedPlans.add(OperatorManipulationUtil.deepCopy(nestedPlan, newWinOp)); } return newWinOp; } }
@Override public ILogicalOperator visitWriteResultOperator(WriteResultOperator op, Void arg) throws AlgebricksException { ArrayList<Mutable<ILogicalExpression>> newKeyExpressions = new ArrayList<>(); deepCopyExpressionRefs(newKeyExpressions, op.getKeyExpressions()); List<Mutable<ILogicalExpression>> newLSMComponentFilterExpressions = new ArrayList<>(); deepCopyExpressionRefs(newKeyExpressions, op.getAdditionalFilteringExpressions()); WriteResultOperator writeResultOp = new WriteResultOperator(op.getDataSource(), deepCopyExpressionRef(op.getPayloadExpression()), newKeyExpressions); writeResultOp.setAdditionalFilteringExpressions(newLSMComponentFilterExpressions); return writeResultOp; }
@Override public ILogicalOperator visitTokenizeOperator(TokenizeOperator op, Void arg) throws AlgebricksException { List<Mutable<ILogicalExpression>> newPrimaryKeyExpressions = new ArrayList<>(); deepCopyExpressionRefs(newPrimaryKeyExpressions, op.getPrimaryKeyExpressions()); List<Mutable<ILogicalExpression>> newSecondaryKeyExpressions = new ArrayList<>(); deepCopyExpressionRefs(newSecondaryKeyExpressions, op.getSecondaryKeyExpressions()); List<LogicalVariable> newTokenizeVars = new ArrayList<>(); deepCopyVars(newTokenizeVars, op.getTokenizeVars()); Mutable<ILogicalExpression> newFilterExpression = new MutableObject<>(((AbstractLogicalExpression) op.getFilterExpression()).cloneExpression()); List<Object> newTokenizeVarTypes = new ArrayList<>(); deepCopyObjects(newTokenizeVarTypes, op.getTokenizeVarTypes()); TokenizeOperator tokenizeOp = new TokenizeOperator(op.getDataSourceIndex(), newPrimaryKeyExpressions, newSecondaryKeyExpressions, newTokenizeVars, newFilterExpression, op.getOperation(), op.isBulkload(), op.isPartitioned(), newTokenizeVarTypes); return tokenizeOp; }
private List<Pair<IOrder, Mutable<ILogicalExpression>>> deepCopyOrderAndExpression( List<Pair<IOrder, Mutable<ILogicalExpression>>> ordersAndExprs) { List<Pair<IOrder, Mutable<ILogicalExpression>>> newOrdersAndExprs = new ArrayList<>(); for (Pair<IOrder, Mutable<ILogicalExpression>> pair : ordersAndExprs) { newOrdersAndExprs.add(new Pair<>(pair.first, deepCopyExpressionRef(pair.second))); } return newOrdersAndExprs; }
@Override public ILogicalOperator visitDistinctOperator(DistinctOperator op, Void arg) throws AlgebricksException { ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<>(); deepCopyExpressionRefs(newExpressions, op.getExpressions()); return new DistinctOperator(newExpressions); }
@Override public ILogicalOperator visitOrderOperator(OrderOperator op, Void arg) throws AlgebricksException { return new OrderOperator(this.deepCopyOrderAndExpression(op.getOrderExpressions())); }
public static ILogicalOperator deepCopy(ILogicalOperator op) throws AlgebricksException { OperatorDeepCopyVisitor visitor = new OperatorDeepCopyVisitor(); AbstractLogicalOperator copiedOperator = (AbstractLogicalOperator) op.accept(visitor, null); copiedOperator.setSourceLocation(op.getSourceLocation()); copiedOperator.setExecutionMode(op.getExecutionMode()); copiedOperator.getAnnotations().putAll(op.getAnnotations()); copiedOperator.setSchema(op.getSchema()); AbstractLogicalOperator sourceOp = (AbstractLogicalOperator) op; copiedOperator.setPhysicalOperator(sourceOp.getPhysicalOperator()); return copiedOperator; }
@Override public ILogicalOperator visitUnnestMapOperator(UnnestMapOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newInputList = new ArrayList<>(); newInputList.addAll(op.getVariables()); Mutable<ILogicalExpression> newSelectCondition = op.getSelectCondition() != null ? deepCopyExpressionRef(op.getSelectCondition()) : null; return new UnnestMapOperator(newInputList, deepCopyExpressionRef(op.getExpressionRef()), new ArrayList<>(op.getVariableTypes()), op.propagatesInput(), newSelectCondition, op.getOutputLimit()); }
@Override public ILogicalOperator visitInsertDeleteUpsertOperator(InsertDeleteUpsertOperator op, Void arg) throws AlgebricksException { List<Mutable<ILogicalExpression>> newKeyExpressions = new ArrayList<>(); deepCopyExpressionRefs(newKeyExpressions, op.getPrimaryKeyExpressions()); List<Mutable<ILogicalExpression>> newLSMComponentFilterExpressions = new ArrayList<>(); deepCopyExpressionRefs(newKeyExpressions, op.getAdditionalFilteringExpressions()); InsertDeleteUpsertOperator insertDeleteOp = new InsertDeleteUpsertOperator(op.getDataSource(), deepCopyExpressionRef(op.getPayloadExpression()), newKeyExpressions, op.getOperation(), op.isBulkload()); insertDeleteOp.setAdditionalFilteringExpressions(newLSMComponentFilterExpressions); return insertDeleteOp; }
@Override public ILogicalOperator visitAggregateOperator(AggregateOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newList = new ArrayList<>(); ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<>(); newList.addAll(op.getVariables()); deepCopyExpressionRefs(newExpressions, op.getExpressions()); return new AggregateOperator(newList, newExpressions); }
@Override public ILogicalOperator visitInnerJoinOperator(InnerJoinOperator op, Void arg) throws AlgebricksException { return new InnerJoinOperator(deepCopyExpressionRef(op.getCondition()), op.getInputs().get(0), op.getInputs().get(1)); }
@Override public ILogicalOperator visitRunningAggregateOperator(RunningAggregateOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newList = new ArrayList<>(); ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<>(); newList.addAll(op.getVariables()); deepCopyExpressionRefs(newExpressions, op.getExpressions()); return new RunningAggregateOperator(newList, newExpressions); }
@Override public ILogicalOperator visitLeftOuterUnnestMapOperator(LeftOuterUnnestMapOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newInputList = new ArrayList<>(); newInputList.addAll(op.getVariables()); return new LeftOuterUnnestMapOperator(newInputList, deepCopyExpressionRef(op.getExpressionRef()), new ArrayList<>(op.getVariableTypes()), op.propagatesInput()); }
@Override public ILogicalOperator visitAssignOperator(AssignOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newList = new ArrayList<>(); ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<>(); newList.addAll(op.getVariables()); deepCopyExpressionRefs(newExpressions, op.getExpressions()); return new AssignOperator(newList, newExpressions); }
@Override public ILogicalOperator visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Void arg) throws AlgebricksException { return new LeftOuterJoinOperator(deepCopyExpressionRef(op.getCondition()), op.getInputs().get(0), op.getInputs().get(1)); }
@Override public ILogicalOperator visitWriteOperator(WriteOperator op, Void arg) throws AlgebricksException { ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<>(); deepCopyExpressionRefs(newExpressions, op.getExpressions()); return new WriteOperator(newExpressions, op.getDataSink()); }
@Override public ILogicalOperator visitGroupByOperator(GroupByOperator op, Void arg) throws AlgebricksException { List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> groupByList = new ArrayList<>(); List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decoList = new ArrayList<>(); ArrayList<ILogicalPlan> newSubplans = new ArrayList<>(); for (Pair<LogicalVariable, Mutable<ILogicalExpression>> pair : op.getGroupByList()) { groupByList.add(new Pair<>(pair.first, deepCopyExpressionRef(pair.second))); } for (Pair<LogicalVariable, Mutable<ILogicalExpression>> pair : op.getDecorList()) { decoList.add(new Pair<>(pair.first, deepCopyExpressionRef(pair.second))); } GroupByOperator gbyOp = new GroupByOperator(groupByList, decoList, newSubplans, op.isGroupAll()); for (ILogicalPlan plan : op.getNestedPlans()) { newSubplans.add(OperatorManipulationUtil.deepCopy(plan, gbyOp)); } return gbyOp; }
@Override public ILogicalOperator visitDistributeResultOperator(DistributeResultOperator op, Void arg) throws AlgebricksException { ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<>(); deepCopyExpressionRefs(newExpressions, op.getExpressions()); return new DistributeResultOperator(newExpressions, op.getDataSink()); }
@Override public ILogicalOperator visitLimitOperator(LimitOperator op, Void arg) throws AlgebricksException { return new LimitOperator(deepCopyExpressionRef(op.getMaxObjects()).getValue(), deepCopyExpressionRef(op.getOffset()).getValue(), op.isTopmostLimitOp()); }
@Override public ILogicalOperator visitIndexInsertDeleteUpsertOperator(IndexInsertDeleteUpsertOperator op, Void arg) throws AlgebricksException { List<Mutable<ILogicalExpression>> newPrimaryKeyExpressions = new ArrayList<>(); deepCopyExpressionRefs(newPrimaryKeyExpressions, op.getPrimaryKeyExpressions()); List<Mutable<ILogicalExpression>> newSecondaryKeyExpressions = new ArrayList<>(); deepCopyExpressionRefs(newSecondaryKeyExpressions, op.getSecondaryKeyExpressions()); Mutable<ILogicalExpression> newFilterExpression = new MutableObject<>(((AbstractLogicalExpression) op.getFilterExpression()).cloneExpression()); List<Mutable<ILogicalExpression>> newLSMComponentFilterExpressions = new ArrayList<>(); deepCopyExpressionRefs(newLSMComponentFilterExpressions, op.getAdditionalFilteringExpressions()); IndexInsertDeleteUpsertOperator indexInsertDeleteOp = new IndexInsertDeleteUpsertOperator( op.getDataSourceIndex(), newPrimaryKeyExpressions, newSecondaryKeyExpressions, newFilterExpression, op.getOperation(), op.isBulkload(), op.getNumberOfAdditionalNonFilteringFields()); indexInsertDeleteOp.setAdditionalFilteringExpressions(newLSMComponentFilterExpressions); return indexInsertDeleteOp; }