Package org.apache.flink.configuration

Examples of org.apache.flink.configuration.IllegalConfigurationException


   
    // read number of field configured via configuration
    int numConfigFields = config.getInteger(NUM_FIELDS_PARAMETER, -1);
    if (numConfigFields != -1) {
      if (numConfigFields <= 0) {
        throw new IllegalConfigurationException("The number of fields for the CsvInputFormat is invalid.");
      }
     
      if (getNumberOfNonNullFields() > 0) {
        throw new IllegalConfigurationException("Mixing configuration via instance parameters and config parameters is not possible.");
      }
   
      int[] textPosIdx = new int[numConfigFields];
      boolean anyTextPosSet = false;
      boolean allTextPosSet = true;
      int maxTextPos = -1;
     
      // parse text positions
      for (int i = 0; i < numConfigFields; i++) {
        int pos = config.getInteger(TEXT_POSITION_PARAMETER_PREFIX + i, -1);
        if (pos == -1) {
          allTextPosSet = false;
          textPosIdx[i] = i;
          maxTextPos = i;
        } else {
          anyTextPosSet = true;
          textPosIdx[i] = pos;
          maxTextPos = pos > maxTextPos ? pos : maxTextPos;
        }
      }
      // check if either none or all text positions have been set
      if (anyTextPosSet && !allTextPosSet) {
        throw new IllegalArgumentException("Invalid configuration for CsvInputFormat: " +
            "Not all text positions set");
      }
     
      // init the array of types to be set. unify the types from the config
      // with the types array set on the instance
     
      // make sure we have a sufficiently large types array
      @SuppressWarnings("unchecked")
      Class<? extends Value>[] types = (Class<? extends Value>[]) new Class[maxTextPos+1];
      int[] targetPos = new int[maxTextPos+1];
     
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
     
      // set the fields
      try {
        for (int i = 0; i < numConfigFields; i++) {
          int pos = textPosIdx[i];
         
          Class<? extends Value> clazz = config.getClass(FIELD_TYPE_PARAMETER_PREFIX + i, null, cl).asSubclass(Value.class);
          if (clazz == null) {
            throw new IllegalConfigurationException("Invalid configuration for CsvInputFormat: " +
              "No field parser class for parameter " + i);
          }
         
          types[pos] = clazz;
          targetPos[pos] = i;
        }
      }
      catch (ClassNotFoundException e) {
        throw new RuntimeException("Could not resolve type classes", e);
      }
     
      // update the field types
      setFieldTypes(types);
     
      // make a dense target pos array
      this.targetPositions = new int[numConfigFields];
      for (int i = 0, k = 0; i < targetPos.length; i++) {
        if (types[i] != null) {
          this.targetPositions[k++] = targetPos[i];
        }
      }
    }
    else {
      // not configured via config parameters
      if (this.targetPositions.length == 0) {
        this.targetPositions = new int[getNumberOfNonNullFields()];
        for (int i = 0; i < this.targetPositions.length; i++) {
          this.targetPositions[i] = i;
        }
      }
    }
   
    if (getNumberOfNonNullFields() == 0) {
      throw new IllegalConfigurationException("No fields configured in the CsvInputFormat.");
    }

    this.configured = true;
  }
View Full Code Here


  @Override
  public void readParametersFromConfig(Configuration config, ClassLoader cl) throws ClassNotFoundException {
    // figure out how many key fields there are
    final int numKeyFields = config.getInteger(NUM_KEYS, -1);
    if (numKeyFields < 0) {
      throw new IllegalConfigurationException("The number of keys for the comparator is invalid: " + numKeyFields);
    }
   
    final int[] positions = new int[numKeyFields];
    final Class<? extends Key<?>>[] types = new Class[numKeyFields];
    final boolean[] direction = new boolean[numKeyFields];
   
    // read the individual key positions and types
    for (int i = 0; i < numKeyFields; i++) {
      // next key position
      final int p = config.getInteger(KEY_POS_PREFIX + i, -1);
      if (p >= 0) {
        positions[i] = p;
      } else {
        throw new IllegalConfigurationException("Contained invalid position for key no positions for keys.");
      }
     
      // next key type
      final String name = config.getString(KEY_CLASS_PREFIX + i, null);
      if (name != null) {
        types[i] = (Class<? extends Key<?>>) Class.forName(name, true, cl).asSubclass(Key.class);
      } else {
        throw new IllegalConfigurationException("The key type (" + i +
          ") for the comparator is null");
      }
     
      // next key sort direction
      direction[i] = config.getBoolean(KEY_SORT_DIRECTION_PREFIX + i, true);
View Full Code Here

TOP

Related Classes of org.apache.flink.configuration.IllegalConfigurationException

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.