Package eu.stratosphere.compiler

Examples of eu.stratosphere.compiler.CompilerException


      } else if (PactCompiler.HINT_LOCAL_STRATEGY_NESTEDLOOP_STREAMED_OUTER_FIRST.equals(localStrategy)) {
        fixedDriverStrat = new CrossStreamOuterFirstDescriptor(allowBCfirst, allowBCsecond);
      } else if (PactCompiler.HINT_LOCAL_STRATEGY_NESTEDLOOP_STREAMED_OUTER_SECOND.equals(localStrategy)) {
        fixedDriverStrat = new CrossStreamOuterSecondDescriptor(allowBCfirst, allowBCsecond);
      } else {
        throw new CompilerException("Invalid local strategy hint for cross contract: " + localStrategy);
      }
     
      return Collections.singletonList(fixedDriverStrat);
    }
    else if (operation instanceof CrossOperatorBase.CrossWithSmall) {
View Full Code Here


      if (iteration.getIterationNode() instanceof BulkIterationPlanNode) {
        finalizeBulkIteration(iteration);
      } else if (iteration.getIterationNode() instanceof WorksetIterationPlanNode) {
        finalizeWorksetIteration(iteration);
      } else {
        throw new CompilerException();
      }
    }
   
    // now that the traversal is done, we have the chained tasks write their configs into their
    // parents' configurations
View Full Code Here

        // implemented
        PlanNode root = iterationNode.getRootOfStepFunction();
        if (root.getDegreeOfParallelism() != node.getDegreeOfParallelism() ||
            root.getSubtasksPerInstance() != node.getSubtasksPerInstance())
        {
          throw new CompilerException("Error: The final operator of the step " +
              "function has a different degree of parallelism than the iteration operator itself.");
        }
       
        IterationDescriptor descr = new IterationDescriptor(iterationNode, this.iterationIdEnumerator++);
        this.iterations.put(iterationNode, descr);
        vertex = null;
      }
      else if (node instanceof WorksetIterationPlanNode) {
        WorksetIterationPlanNode iterationNode = (WorksetIterationPlanNode) node;

        // we have the same constraints as for the bulk iteration
        PlanNode nextWorkSet = iterationNode.getNextWorkSetPlanNode();
        PlanNode solutionSetDelta  = iterationNode.getSolutionSetDeltaPlanNode();
       
        if (nextWorkSet.getDegreeOfParallelism() != node.getDegreeOfParallelism() ||
          nextWorkSet.getSubtasksPerInstance() != node.getSubtasksPerInstance())
        {
          throw new CompilerException("It is currently not supported that the final operator of the step " +
              "function has a different degree of parallelism than the iteration operator itself.");
        }
        if (solutionSetDelta.getDegreeOfParallelism() != node.getDegreeOfParallelism() ||
          solutionSetDelta.getSubtasksPerInstance() != node.getSubtasksPerInstance())
        {
          throw new CompilerException("It is currently not supported that the final operator of the step " +
              "function has a different degree of parallelism than the iteration operator itself.");
        }
       
        IterationDescriptor descr = new IterationDescriptor(iterationNode, this.iterationIdEnumerator++);
        this.iterations.put(iterationNode, descr);
        vertex = null;
      }
      else if (node instanceof SingleInputPlanNode) {
        vertex = createSingleInputVertex((SingleInputPlanNode) node);
      }
      else if (node instanceof DualInputPlanNode) {
        vertex = createDualInputVertex((DualInputPlanNode) node);
      }
      else if (node instanceof NAryUnionPlanNode) {
        // skip the union for now
        vertex = null;
      }
      else if (node instanceof BulkPartialSolutionPlanNode) {
        // create a head node (or not, if it is merged into its successor)
        vertex = createBulkIterationHead((BulkPartialSolutionPlanNode) node);
      }
      else if (node instanceof SolutionSetPlanNode) {
        // this represents an access into the solution set index.
        // we do not create a vertex for the solution set here (we create the head at the workset place holder)
       
        // we adjust the joins / cogroups that go into the solution set here
        for (Channel c : node.getOutgoingChannels()) {
          DualInputPlanNode target = (DualInputPlanNode) c.getTarget();
          AbstractJobVertex accessingVertex = this.vertices.get(target);
          TaskConfig conf = new TaskConfig(accessingVertex.getConfiguration());
          int inputNum = c == target.getInput1() ? 0 : c == target.getInput2() ? 1 : -1;
         
          // sanity checks
          if (inputNum == -1) {
            throw new CompilerException();
          }
         
          // adjust the driver
          if (conf.getDriver().equals(MatchDriver.class)) {
            conf.setDriver(inputNum == 0 ? JoinWithSolutionSetFirstDriver.class : JoinWithSolutionSetSecondDriver.class);
          }
          else if (conf.getDriver().equals(CoGroupDriver.class)) {
            conf.setDriver(inputNum == 0 ? CoGroupWithSolutionSetFirstDriver.class : CoGroupWithSolutionSetSecondDriver.class);
          }
          else {
            throw new CompilerException("Found join with solution set using incompatible operator (only Join/CoGroup are valid).");
          }
        }
       
        // make sure we do not visit this node again. for that, we add a 'already seen' entry into one of the sets
        this.chainedTasks.put(node, ALREADY_VISITED_PLACEHOLDER);
       
        vertex = null;
      }
      else if (node instanceof WorksetPlanNode) {
        // create the iteration head here
        vertex = createWorksetIterationHead((WorksetPlanNode) node);
      }
      else {
        throw new CompilerException("Unrecognized node type: " + node.getClass().getName());
      }
    }
    catch (Exception e) {
      throw new CompilerException("Error translating node '" + node + "': " + e.getMessage(), e);
    }
   
    // check if a vertex was created, or if it was chained or skipped
    if (vertex != null) {
      // set degree of parallelism
      int pd = node.getDegreeOfParallelism();
      vertex.setNumberOfSubtasks(pd);
 
      // check whether this is the vertex with the highest degree of parallelism
      if (this.maxDegreeVertex == null || this.maxDegreeVertex.getNumberOfSubtasks() < pd) {
        this.maxDegreeVertex = vertex;
      }
 
      // set the number of tasks per instance
      if (node.getSubtasksPerInstance() >= 1) {
        vertex.setNumberOfSubtasksPerInstance(node.getSubtasksPerInstance());
      }
     
      // check whether this vertex is part of an iteration step function
      if (this.currentIteration != null) {
        // check that the task has the same DOP as the iteration as such
        PlanNode iterationNode = (PlanNode) this.currentIteration;
        if (iterationNode.getDegreeOfParallelism() < pd) {
          throw new CompilerException("Error: All functions that are part of an iteration must have the same, or a lower, degree-of-parallelism than the iteration operator.");
        }
        if (iterationNode.getSubtasksPerInstance() < node.getSubtasksPerInstance()) {
          throw new CompilerException("Error: All functions that are part of an iteration must have the same, or a lower, number of subtasks-per-node than the iteration operator.");
        }
       
        // store the id of the iterations the step functions participate in
        IterationDescriptor descr = this.iterations.get(this.currentIteration);
        new TaskConfig(vertex.getConfiguration()).setIterationId(descr.getId());
View Full Code Here

     
      // check if we have an iteration. in that case, translate the step function now
      if (node instanceof IterationPlanNode) {
        // for now, prevent nested iterations
        if (this.currentIteration != null) {
          throw new CompilerException("Nested Iterations are not possible at the moment!");
        }
        this.currentIteration = (IterationPlanNode) node;
        this.currentIteration.acceptForStepFunction(this);
        this.currentIteration = null;
       
        // inputs for initial bulk partial solution or initial workset are already connected to the iteration head in the head's post visit.
        // connect the initial solution set now.
        if (node instanceof WorksetIterationPlanNode) {
          // connect the initial solution set
          WorksetIterationPlanNode wsNode = (WorksetIterationPlanNode) node;
          AbstractJobVertex headVertex = this.iterations.get(wsNode).getHeadTask();
          TaskConfig headConfig = new TaskConfig(headVertex.getConfiguration());
          int inputIndex = headConfig.getDriverStrategy().getNumInputs();
          headConfig.setIterationHeadSolutionSetInputIndex(inputIndex);
          translateChannel(wsNode.getInitialSolutionSetInput(), inputIndex, headVertex, headConfig, false);
        }
       
        return;
      }
     
      // --------- Main Path: Translation of channels ----------
      //
      // There are two paths of translation: One for chained tasks (or merged tasks in general),
      // which do not have their own task vertex. The other for tasks that have their own vertex,
      // or are the primary task in a vertex (to which the others are chained).
     
      final AbstractJobVertex targetVertex = this.vertices.get(node);
     
      // check whether this node has its own task, or is merged with another one
      if (targetVertex == null) {
        // node's task is merged with another task. it is either chained, of a merged head vertex
        // from an iteration
        final TaskInChain chainedTask;
        if ((chainedTask = this.chainedTasks.get(node)) != null) {
          // Chained Task. Sanity check first...
          final Iterator<Channel> inConns = node.getInputs();
          if (!inConns.hasNext()) {
            throw new CompilerException("Bug: Found chained task with no input.");
          }
          final Channel inConn = inConns.next();
         
          if (inConns.hasNext()) {
            throw new CompilerException("Bug: Found a chained task with more than one input!");
          }
          if (inConn.getLocalStrategy() != null && inConn.getLocalStrategy() != LocalStrategy.NONE) {
            throw new CompilerException("Bug: Found a chained task with an input local strategy.");
          }
          if (inConn.getShipStrategy() != null && inConn.getShipStrategy() != ShipStrategyType.FORWARD) {
            throw new CompilerException("Bug: Found a chained task with an input ship strategy other than FORWARD.");
          }
 
          AbstractJobVertex container = chainedTask.getContainingVertex();
         
          if (container == null) {
            final PlanNode sourceNode = inConn.getSource();
            container = this.vertices.get(sourceNode);
            if (container == null) {
              // predecessor is itself chained
              container = this.chainedTasks.get(sourceNode).getContainingVertex();
              if (container == null) {
                throw new IllegalStateException("Bug: Chained task predecessor has not been assigned its containing vertex.");
              }
            } else {
              // predecessor is a proper task job vertex and this is the first chained task. add a forward connection entry.
              new TaskConfig(container.getConfiguration()).addOutputShipStrategy(ShipStrategyType.FORWARD);
            }
            chainedTask.setContainingVertex(container);
          }
         
          // add info about the input serializer type
          chainedTask.getTaskConfig().setInputSerializer(inConn.getSerializer(), 0);
         
          // update name of container task
          String containerTaskName = container.getName();
          if(containerTaskName.startsWith("CHAIN ")) {
            container.setName(containerTaskName+" -> "+chainedTask.getTaskName());
          } else {
            container.setName("CHAIN "+containerTaskName+" -> "+chainedTask.getTaskName());
          }
         
          this.chainedTasksInSequence.add(chainedTask);
          return;
        }
        else if (node instanceof BulkPartialSolutionPlanNode ||
            node instanceof WorksetPlanNode)
        {
          // merged iteration head task. the task that the head is merged with will take care of it
          return;
        } else {
          throw new CompilerException("Bug: Unrecognized merged task vertex.");
        }
      }
     
      // -------- Here, we translate non-chained tasks -------------
     
      // create the config that will contain all the description of the inputs
      final TaskConfig targetVertexConfig = new TaskConfig(targetVertex.getConfiguration());
           
      // get the inputs. if this node is the head of an iteration, we obtain the inputs from the
      // enclosing iteration node, because the inputs are the initial inputs to the iteration.
      final Iterator<Channel> inConns;
      if (node instanceof BulkPartialSolutionPlanNode) {
        inConns = ((BulkPartialSolutionPlanNode) node).getContainingIterationNode().getInputs();
        // because the partial solution has its own vertex, is has only one (logical) input.
        // note this in the task configuration
        targetVertexConfig.setIterationHeadPartialSolutionOrWorksetInputIndex(0);
      } else if (node instanceof WorksetPlanNode) {
        WorksetPlanNode wspn = (WorksetPlanNode) node;
        // input that is the initial workset
        inConns = Collections.singleton(wspn.getContainingIterationNode().getInput2()).iterator();
       
        // because we have a stand-alone (non-merged) workset iteration head, the initial workset will
        // be input 0 and the solution set will be input 1
        targetVertexConfig.setIterationHeadPartialSolutionOrWorksetInputIndex(0);
        targetVertexConfig.setIterationHeadSolutionSetInputIndex(1);
      } else {
        inConns = node.getInputs();
      }
      if (!inConns.hasNext()) {
        throw new CompilerException("Bug: Found a non-source task with no input.");
      }
     
      int inputIndex = 0;
      while (inConns.hasNext()) {
        Channel input = inConns.next();
        inputIndex += translateChannel(input, inputIndex, targetVertex, targetVertexConfig, false);
      }
      // broadcast variables
      int broadcastInputIndex = 0;
      for (NamedChannel broadcastInput: node.getBroadcastInputs()) {
        int broadcastInputIndexDelta = translateChannel(broadcastInput, broadcastInputIndex, targetVertex, targetVertexConfig, true);
        targetVertexConfig.setBroadcastInputName(broadcastInput.getName(), broadcastInputIndex);
        targetVertexConfig.setBroadcastInputSerializer(broadcastInput.getSerializer(), broadcastInputIndex);
        broadcastInputIndex += broadcastInputIndexDelta;
      }
    } catch (Exception e) {
      throw new CompilerException(
        "An error occurred while translating the optimized plan to a nephele JobGraph: " + e.getMessage(), e);
    }
  }
View Full Code Here

     
      // sanity check the common serializer
      if (typeSerFact == null) {
        typeSerFact = inConn.getSerializer();
      } else if (!typeSerFact.equals(inConn.getSerializer())) {
        throw new CompilerException("Conflicting types in union operator.");
      }
     
      final PlanNode sourceNode = inConn.getSource();
      AbstractJobVertex sourceVertex = this.vertices.get(sourceNode);
      TaskConfig sourceVertexConfig;

      if (sourceVertex == null) {
        // this predecessor is chained to another task or an iteration
        final TaskInChain chainedTask;
        final IterationDescriptor iteration;
        if ((chainedTask = this.chainedTasks.get(sourceNode)) != null) {
          // push chained task
          if (chainedTask.getContainingVertex() == null) {
            throw new IllegalStateException("Bug: Chained task has not been assigned its containing vertex when connecting.");
          }
          sourceVertex = chainedTask.getContainingVertex();
          sourceVertexConfig = chainedTask.getTaskConfig();
        } else if ((iteration = this.iterations.get(sourceNode)) != null) {
          // predecessor is an iteration
          sourceVertex = iteration.getHeadTask();
          sourceVertexConfig = iteration.getHeadFinalResultConfig();
        } else {
          throw new CompilerException("Bug: Could not resolve source node for a channel.");
        }
      } else {
        // predecessor is its own vertex
        sourceVertexConfig = new TaskConfig(sourceVertex.getConfiguration());
      }
      DistributionPattern pattern = connectJobVertices(
        inConn, inputIndex, sourceVertex, sourceVertexConfig, targetVertex, targetVertexConfig, isBroadcast);
     
      // accounting on channels and senders
      numChannelsTotal++;
      if (inConn.isOnDynamicPath()) {
        numChannelsDynamicPath++;
        numDynamicSenderTasksTotal += getNumberOfSendersPerReceiver(pattern,
          sourceVertex.getNumberOfSubtasks(), targetVertex.getNumberOfSubtasks());
      }
    }
   
    // for the iterations, check that the number of dynamic channels is the same as the number
    // of channels for this logical input. this condition is violated at the moment, if there
    // is a union between nodes on the static and nodes on the dynamic path
    if (numChannelsDynamicPath > 0 && numChannelsTotal != numChannelsDynamicPath) {
      throw new CompilerException("Error: It is currently not supported to union between dynamic and static path in an iteration.");
    }
    if (numDynamicSenderTasksTotal > 0) {
      if (isBroadcast) {
        targetVertexConfig.setBroadcastGateIterativeWithNumberOfEventsUntilInterrupt(inputIndex, numDynamicSenderTasksTotal);
      } else {
View Full Code Here

    this.keys2 = k2 == null || k2.length == 0 ? null : new FieldList(k2);
   
    if (this.keys1 != null) {
      if (this.keys2 != null) {
        if (this.keys1.size() != this.keys2.size()) {
          throw new CompilerException("Unequal number of key fields on the two inputs.");
        }
      } else {
        throw new CompilerException("Keys are set on first input, but not on second.");
      }
    } else if (this.keys2 != null) {
      throw new CompilerException("Keys are set on second input, but not on first.");
    }
   
    this.possibleProperties = getPossibleProperties();
  }
View Full Code Here

      } else if (PactCompiler.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
        preSet1 = preSet2 = ShipStrategyType.PARTITION_RANGE;
      } else if (shipStrategy.equalsIgnoreCase(PactCompiler.HINT_SHIP_STRATEGY_REPARTITION)) {
        preSet1 = preSet2 = ShipStrategyType.PARTITION_RANDOM;
      } else {
        throw new CompilerException("Unknown hint for shipping strategy: " + shipStrategy);
      }
    }

    // see if there is a hint that dictates which shipping strategy to use for the FIRST input
    shipStrategy = conf.getString(PactCompiler.HINT_SHIP_STRATEGY_FIRST_INPUT, null);
    if (shipStrategy != null) {
      if (PactCompiler.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
        preSet1 = ShipStrategyType.FORWARD;
      } else if (PactCompiler.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
        preSet1 = ShipStrategyType.BROADCAST;
      } else if (PactCompiler.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
        preSet1 = ShipStrategyType.PARTITION_HASH;
      } else if (PactCompiler.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
        preSet1 = ShipStrategyType.PARTITION_RANGE;
      } else if (shipStrategy.equalsIgnoreCase(PactCompiler.HINT_SHIP_STRATEGY_REPARTITION)) {
        preSet1 = ShipStrategyType.PARTITION_RANDOM;
      } else {
        throw new CompilerException("Unknown hint for shipping strategy of input one: " + shipStrategy);
      }
    }

    // see if there is a hint that dictates which shipping strategy to use for the SECOND input
    shipStrategy = conf.getString(PactCompiler.HINT_SHIP_STRATEGY_SECOND_INPUT, null);
    if (shipStrategy != null) {
      if (PactCompiler.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
        preSet2 = ShipStrategyType.FORWARD;
      } else if (PactCompiler.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
        preSet2 = ShipStrategyType.BROADCAST;
      } else if (PactCompiler.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
        preSet2 = ShipStrategyType.PARTITION_HASH;
      } else if (PactCompiler.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
        preSet2 = ShipStrategyType.PARTITION_RANGE;
      } else if (shipStrategy.equalsIgnoreCase(PactCompiler.HINT_SHIP_STRATEGY_REPARTITION)) {
        preSet2 = ShipStrategyType.PARTITION_RANDOM;
      } else {
        throw new CompilerException("Unknown hint for shipping strategy of input two: " + shipStrategy);
      }
    }
   
    // get the predecessors
    DualInputOperator<?, ?, ?, ?> contr = (DualInputOperator<?, ?, ?, ?>) getPactContract();
   
    Operator<?> leftPred = contr.getFirstInput();
    Operator<?> rightPred = contr.getSecondInput();
   
    OptimizerNode pred1;
    PactConnection conn1;
    if (leftPred == null) {
      throw new CompilerException("Error: Node for '" + getPactContract().getName() + "' has no input set for first input.");
    } else {
      pred1 = contractToNode.get(leftPred);
      conn1 = new PactConnection(pred1, this);
      if (preSet1 != null) {
        conn1.setShipStrategy(preSet1);
      }
    }
   
    // create the connection and add it
    this.input1 = conn1;
    pred1.addOutgoingConnection(conn1);
   
    OptimizerNode pred2;
    PactConnection conn2;
    if (rightPred == null) {
      throw new CompilerException("Error: Node for '" + getPactContract().getName() + "' has no input set for second input.");
    } else {
      pred2 = contractToNode.get(rightPred);
      conn2 = new PactConnection(pred2, this);
      if (preSet2 != null) {
        conn2.setShipStrategy(preSet2);
View Full Code Here

        }
        else if (numSenders == 1) {
          return 1;
        }
        else {
          throw new CompilerException("Error: A changing degree of parallelism is currently " +
              "not supported between tasks within an iteration.");
        }
      } else {
        return 1;
      }
    } else {
      throw new CompilerException("Unknown distribution pattern for channels: " + pattern);
    }
  }
View Full Code Here

      if (schema.getNumConnectionsThatContributed() < iterationNode.getOutgoingChannels().size()) {
        return;
      }
     
      if (iterationNode.getRootOfStepFunction() instanceof NAryUnionPlanNode) {
        throw new CompilerException("Optimizer cannot compile an iteration step function where next partial solution is created by a Union node.");
      }
     
      // traverse the termination criterion for the first time. create schema only, no utilities. Needed in case of intermediate termination criterion
      if (iterationNode.getRootOfTerminationCriterion() != null) {
        SingleInputPlanNode addMapper = (SingleInputPlanNode) iterationNode.getRootOfTerminationCriterion();
        traverse(addMapper.getInput().getSource(), createEmptySchema(), false);
        try {
          addMapper.getInput().setSerializer(createSerializer(createEmptySchema()));
        } catch (MissingFieldTypeInfoException e) {
          throw new RuntimeException(e);
        }
      }
     
      // traverse the step function for the first time. create schema only, no utilities
      traverse(iterationNode.getRootOfStepFunction(), schema, false);
     
      T pss = (T) iterationNode.getPartialSolutionPlanNode().postPassHelper;
      if (pss == null) {
        throw new CompilerException("Error in Optimizer Post Pass: Partial solution schema is null after first traversal of the step function.");
      }
     
      // traverse the step function for the second time, taking the schema of the partial solution
      traverse(iterationNode.getRootOfStepFunction(), pss, createUtilities);
     
      if (iterationNode.getRootOfTerminationCriterion() != null) {
        SingleInputPlanNode addMapper = (SingleInputPlanNode) iterationNode.getRootOfTerminationCriterion();
        traverse(addMapper.getInput().getSource(), createEmptySchema(), createUtilities);
        try {
          addMapper.getInput().setSerializer(createSerializer(createEmptySchema()));
        } catch (MissingFieldTypeInfoException e) {
          throw new RuntimeException(e);
        }
      }
     
      // take the schema from the partial solution node and add its fields to the iteration result schema.
      // input and output schema need to be identical, so this is essentially a sanity check
      addSchemaToSchema(pss, schema, iterationNode.getPactContract().getName());
     
      // set the serializer
      if (createUtilities) {
        iterationNode.setSerializerForIterationChannel(createSerializer(pss, iterationNode.getPartialSolutionPlanNode()));
      }
     
      // done, we can now propagate our info down
      try {
        propagateToChannel(schema, iterationNode.getInput(), createUtilities);
      } catch (MissingFieldTypeInfoException e) {
        throw new CompilerPostPassException("Could not set up runtime strategy for input channel to node '"
          + iterationNode.getPactContract().getName() + "'. Missing type information for key field " +
          e.getFieldNumber());
      }
    }
    else if (node instanceof WorksetIterationPlanNode) {
      WorksetIterationPlanNode iterationNode = (WorksetIterationPlanNode) node;
     
      // get the nodes current schema
      T schema;
      if (iterationNode.postPassHelper == null) {
        schema = createEmptySchema();
        iterationNode.postPassHelper = schema;
      } else {
        schema = (T) iterationNode.postPassHelper;
      }
      schema.increaseNumConnectionsThatContributed();
     
      // add the parent schema to the schema (which refers to the solution set schema)
      if (propagateParentSchemaDown) {
        addSchemaToSchema(parentSchema, schema, iterationNode.getPactContract().getName());
      }
     
      // check whether all outgoing channels have not yet contributed. come back later if not.
      if (schema.getNumConnectionsThatContributed() < iterationNode.getOutgoingChannels().size()) {
        return;
      }
      if (iterationNode.getNextWorkSetPlanNode() instanceof NAryUnionPlanNode) {
        throw new CompilerException("Optimizer cannot compile a workset iteration step function where the next workset is produced by a Union node.");
      }
      if (iterationNode.getSolutionSetDeltaPlanNode() instanceof NAryUnionPlanNode) {
        throw new CompilerException("Optimizer cannot compile a workset iteration step function where the solution set delta is produced by a Union node.");
      }
     
      // traverse the step function
      // pass an empty schema to the next workset and the parent schema to the solution set delta
      // these first traversals are schema only
      traverse(iterationNode.getNextWorkSetPlanNode(), createEmptySchema(), false);
      traverse(iterationNode.getSolutionSetDeltaPlanNode(), schema, false);
     
      T wss = (T) iterationNode.getWorksetPlanNode().postPassHelper;
      T sss = (T) iterationNode.getSolutionSetPlanNode().postPassHelper;
     
      if (wss == null) {
        throw new CompilerException("Error in Optimizer Post Pass: Workset schema is null after first traversal of the step function.");
      }
      if (sss == null) {
        throw new CompilerException("Error in Optimizer Post Pass: Solution set schema is null after first traversal of the step function.");
      }
     
      // make the second pass and instantiate the utilities
      traverse(iterationNode.getNextWorkSetPlanNode(), wss, createUtilities);
      traverse(iterationNode.getSolutionSetDeltaPlanNode(), sss, createUtilities);
     
      // add the types from the solution set schema to the iteration's own schema. since
      // the solution set input and the result must have the same schema, this acts as a sanity check.
      try {
        for (Map.Entry<Integer, X> entry : sss) {
          Integer pos = entry.getKey();
          schema.addType(pos, entry.getValue());
        }
      } catch (ConflictingFieldTypeInfoException e) {
        throw new CompilerPostPassException("Conflicting type information for field " + e.getFieldNumber()
          + " in node '" + iterationNode.getPactContract().getName() + "'. Contradicting types between the " +
          "result of the iteration and the solution set schema: " + e.getPreviousType() +
          " and " + e.getNewType() + ". Most probable cause: Invalid constant field annotations.");
      }
     
      // set the serializers and comparators
      if (createUtilities) {
        WorksetIterationNode optNode = iterationNode.getIterationNode();
        iterationNode.setWorksetSerializer(createSerializer(wss, iterationNode.getWorksetPlanNode()));
        iterationNode.setSolutionSetSerializer(createSerializer(sss, iterationNode.getSolutionSetPlanNode()));
        try {
          iterationNode.setSolutionSetComparator(createComparator(optNode.getSolutionSetKeyFields(), null, sss));
        } catch (MissingFieldTypeInfoException ex) {
          throw new CompilerPostPassException("Could not set up the solution set for workset iteration '" +
              optNode.getPactContract().getName() + "'. Missing type information for key field " + ex.getFieldNumber() + '.');
        }
      }
     
      // done, we can now propagate our info down
      try {
        propagateToChannel(schema, iterationNode.getInitialSolutionSetInput(), createUtilities);
        propagateToChannel(wss, iterationNode.getInitialWorksetInput(), createUtilities);
      } catch (MissingFieldTypeInfoException ex) {
        throw new CompilerPostPassException("Could not set up runtime strategy for input channel to node '"
          + iterationNode.getPactContract().getName() + "'. Missing type information for key field " +
          ex.getFieldNumber());
      }
    }
    else if (node instanceof SingleInputPlanNode) {
      SingleInputPlanNode sn = (SingleInputPlanNode) node;
     
      // get the nodes current schema
      T schema;
      if (sn.postPassHelper == null) {
        schema = createEmptySchema();
        sn.postPassHelper = schema;
      } else {
        schema = (T) sn.postPassHelper;
      }
      schema.increaseNumConnectionsThatContributed();
      SingleInputNode optNode = sn.getSingleInputNode();
     
      // add the parent schema to the schema
      if (propagateParentSchemaDown) {
        addSchemaToSchema(parentSchema, schema, optNode, 0);
      }
     
      // check whether all outgoing channels have not yet contributed. come back later if not.
      if (schema.getNumConnectionsThatContributed() < sn.getOutgoingChannels().size()) {
        return;
      }
     
      // add the nodes local information
      try {
        getSingleInputNodeSchema(sn, schema);
      } catch (ConflictingFieldTypeInfoException e) {
        throw new CompilerPostPassException(getConflictingTypeErrorMessage(e, optNode.getPactContract().getName()));
      }
     
      if (createUtilities) {
        // parameterize the node's driver strategy
        if (sn.getDriverStrategy().requiresComparator()) {
          try {
            sn.setComparator(createComparator(sn.getKeys(), sn.getSortOrders(), schema));
          } catch (MissingFieldTypeInfoException e) {
            throw new CompilerPostPassException("Could not set up runtime strategy for node '" +
                optNode.getPactContract().getName() + "'. Missing type information for key field " +
                e.getFieldNumber());
          }
        }
      }
     
      // done, we can now propagate our info down
      try {
        propagateToChannel(schema, sn.getInput(), createUtilities);
      } catch (MissingFieldTypeInfoException e) {
        throw new CompilerPostPassException("Could not set up runtime strategy for input channel to node '" +
          optNode.getPactContract().getName() + "'. Missing type information for field " + e.getFieldNumber());
      }
     
      // don't forget the broadcast inputs
      for (Channel c: sn.getBroadcastInputs()) {
        try {
          propagateToChannel(createEmptySchema(), c, createUtilities);
        } catch (MissingFieldTypeInfoException e) {
          throw new CompilerPostPassException("Could not set up runtime strategy for broadcast channel in node '" +
            optNode.getPactContract().getName() + "'. Missing type information for field " + e.getFieldNumber());
        }
      }
    }
    else if (node instanceof DualInputPlanNode) {
      DualInputPlanNode dn = (DualInputPlanNode) node;
     
      // get the nodes current schema
      T schema1;
      T schema2;
      if (dn.postPassHelper1 == null) {
        schema1 = createEmptySchema();
        schema2 = createEmptySchema();
        dn.postPassHelper1 = schema1;
        dn.postPassHelper2 = schema2;
      } else {
        schema1 = (T) dn.postPassHelper1;
        schema2 = (T) dn.postPassHelper2;
      }

      schema1.increaseNumConnectionsThatContributed();
      schema2.increaseNumConnectionsThatContributed();
      TwoInputNode optNode = dn.getTwoInputNode();
     
      // add the parent schema to the schema
      if (propagateParentSchemaDown) {
        addSchemaToSchema(parentSchema, schema1, optNode, 0);
        addSchemaToSchema(parentSchema, schema2, optNode, 1);
      }
     
      // check whether all outgoing channels have not yet contributed. come back later if not.
      if (schema1.getNumConnectionsThatContributed() < dn.getOutgoingChannels().size()) {
        return;
      }
     
      // add the nodes local information
      try {
        getDualInputNodeSchema(dn, schema1, schema2);
      } catch (ConflictingFieldTypeInfoException e) {
        throw new CompilerPostPassException(getConflictingTypeErrorMessage(e, optNode.getPactContract().getName()));
      }
     
      // parameterize the node's driver strategy
      if (createUtilities) {
        if (dn.getDriverStrategy().requiresComparator()) {
          // set the individual comparators
          try {
            dn.setComparator1(createComparator(dn.getKeysForInput1(), dn.getSortOrders(), schema1));
            dn.setComparator2(createComparator(dn.getKeysForInput2(), dn.getSortOrders(), schema2));
          } catch (MissingFieldTypeInfoException e) {
            throw new CompilerPostPassException("Could not set up runtime strategy for node '" +
                optNode.getPactContract().getName() + "'. Missing type information for field " + e.getFieldNumber());
          }
         
          // set the pair comparator
          try {
            dn.setPairComparator(createPairComparator(dn.getKeysForInput1(), dn.getKeysForInput2(),
              dn.getSortOrders(), schema1, schema2));
          } catch (MissingFieldTypeInfoException e) {
            throw new CompilerPostPassException("Could not set up runtime strategy for node '" +
                optNode.getPactContract().getName() + "'. Missing type information for field " + e.getFieldNumber());
          }
         
        }
      }
     
      // done, we can now propagate our info down
      try {
        propagateToChannel(schema1, dn.getInput1(), createUtilities);
      } catch (MissingFieldTypeInfoException e) {
        throw new CompilerPostPassException("Could not set up runtime strategy for the first input channel to node '"
          + optNode.getPactContract().getName() + "'. Missing type information for field " + e.getFieldNumber());
      }
      try {
        propagateToChannel(schema2, dn.getInput2(), createUtilities);
      } catch (MissingFieldTypeInfoException e) {
        throw new CompilerPostPassException("Could not set up runtime strategy for the second input channel to node '"
          + optNode.getPactContract().getName() + "'. Missing type information for field " + e.getFieldNumber());
      }
     
      // don't forget the broadcast inputs
      for (Channel c: dn.getBroadcastInputs()) {
        try {
          propagateToChannel(createEmptySchema(), c, createUtilities);
        } catch (MissingFieldTypeInfoException e) {
          throw new CompilerPostPassException("Could not set up runtime strategy for broadcast channel in node '" +
            optNode.getPactContract().getName() + "'. Missing type information for field " + e.getFieldNumber());
        }
      }
    }
    else if (node instanceof NAryUnionPlanNode) {
      // only propagate the info down
      try {
        for (Iterator<Channel> channels = node.getInputs(); channels.hasNext(); ) {
          propagateToChannel(parentSchema, channels.next(), createUtilities);
        }
      } catch (MissingFieldTypeInfoException ex) {
        throw new CompilerPostPassException("Could not set up runtime strategy for the input channel to " +
            " a union node. Missing type information for field " + ex.getFieldNumber());
      }
    }
    // catch the sources of the iterative step functions
    else if (node instanceof BulkPartialSolutionPlanNode ||
        node instanceof SolutionSetPlanNode ||
        node instanceof WorksetPlanNode)
    {
      // get the nodes current schema
      T schema;
      String name;
      if (node instanceof BulkPartialSolutionPlanNode) {
        BulkPartialSolutionPlanNode psn = (BulkPartialSolutionPlanNode) node;
        if (psn.postPassHelper == null) {
          schema = createEmptySchema();
          psn.postPassHelper = schema;
        } else {
          schema = (T) psn.postPassHelper;
        }
        name = "partial solution of bulk iteration '" +
          psn.getPartialSolutionNode().getIterationNode().getPactContract().getName() + "'";
      }
      else if (node instanceof SolutionSetPlanNode) {
        SolutionSetPlanNode ssn = (SolutionSetPlanNode) node;
        if (ssn.postPassHelper == null) {
          schema = createEmptySchema();
          ssn.postPassHelper = schema;
        } else {
          schema = (T) ssn.postPassHelper;
        }
        name = "solution set of workset iteration '" +
            ssn.getSolutionSetNode().getIterationNode().getPactContract().getName() + "'";
      }
      else if (node instanceof WorksetPlanNode) {
        WorksetPlanNode wsn = (WorksetPlanNode) node;
        if (wsn.postPassHelper == null) {
          schema = createEmptySchema();
          wsn.postPassHelper = schema;
        } else {
          schema = (T) wsn.postPassHelper;
        }
        name = "workset of workset iteration '" +
            wsn.getWorksetNode().getIterationNode().getPactContract().getName() + "'";
      } else {
        throw new CompilerException();
      }
     
      schema.increaseNumConnectionsThatContributed();
     
      // add the parent schema to the schema
View Full Code Here

                // all right, co compatible
                instantiate(dps, in1, in2, broadcastPlanChannels, target, estimator, rgps1, rgps2, ilp1, ilp2);
                break allPossibleLoop;
              } else {
                // meet, but not co-compatible
                throw new CompilerException("Implements to adjust one side to the other!");
              }
            }
          }
        }
      }
View Full Code Here

TOP

Related Classes of eu.stratosphere.compiler.CompilerException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.