Package com.cloudera.cdk.morphline.api

Examples of com.cloudera.cdk.morphline.api.MorphlineCompilationException


  public Command compile(File morphlineFile, String morphlineId, MorphlineContext morphlineContext, Command finalChild, Config... overrides) {
    Config config;
    try {
      config = parse(morphlineFile, overrides);
    } catch (IOException e) {
      throw new MorphlineCompilationException("Cannot parse morphline file: " + morphlineFile, null, e);
    }
    Config morphlineConfig = find(morphlineId, config, morphlineFile.getPath());
    Command morphlineCommand = compile(morphlineConfig, morphlineContext, finalChild);
    return morphlineCommand;
  }
View Full Code Here


  }
 
  /** Loads the given config file from the local file system */
  public Config parse(File file, Config... overrides) throws IOException {
    if (file == null || file.getPath().trim().length() == 0) {
      throw new MorphlineCompilationException("Missing morphlineFile parameter", null);
    }
    if (!file.exists()) {
      throw new FileNotFoundException("File not found: " + file);
    }
    if (!file.canRead()) {
View Full Code Here

   * for error reporting.
   */
  public Config find(String morphlineId, Config config, String nameForErrorMsg) {
    List<? extends Config> morphlineConfigs = config.getConfigList("morphlines");
    if (morphlineConfigs.size() == 0) {
      throw new MorphlineCompilationException(
          "Morphline file must contain at least one morphline: " + nameForErrorMsg, null);
    }
    if (morphlineId != null) {
      morphlineId = morphlineId.trim();
    }
    if (morphlineId != null && morphlineId.length() == 0) {
      morphlineId = null;
    }
    Config morphlineConfig = null;
    if (morphlineId == null) {
      morphlineConfig = morphlineConfigs.get(0);
      Preconditions.checkNotNull(morphlineConfig);
    } else {
      for (Config candidate : morphlineConfigs) {
        if (morphlineId.equals(new Configs().getString(candidate, "id", null))) {
          morphlineConfig = candidate;
          break;
        }
      }
      if (morphlineConfig == null) {
        throw new MorphlineCompilationException(
            "Morphline id '" + morphlineId + "' not found in morphline file: " + nameForErrorMsg, null);
      }
    }
    return morphlineConfig;
  }
View Full Code Here

      super(builder, config, parent, child, context);     
      this.inputFieldName = getConfigs().getString(config, "inputField");     
      this.outputFieldPrefix = getConfigs().getString(config, "outputFieldPrefix", "");
      String separator = getConfigs().getString(config, "separator", "=");
      if (separator.length() != 1) {
        throw new MorphlineCompilationException("separator must be one character only: " + separator, config);
      }
      this.separatorChar = separator.charAt(0);
      this.addEmptyStrings = getConfigs().getBoolean(config, "addEmptyStrings", false);     
      this.trim = getConfigs().getBoolean(config, "trim", true);
      validateArguments();
View Full Code Here

 
    public ReadCSV(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
      super(builder, config, parent, child, context);
      String separator = getConfigs().getString(config, "separator", ",");
      if (separator.length() != 1) {
        throw new MorphlineCompilationException("CSV separator must be one character only: " + separator, config);
      }
      this.separatorChar = separator.charAt(0);
      this.columnNames = getConfigs().getStringList(config, "columns");
      this.charset = getConfigs().getCharset(config, "charset", null);
      this.ignoreFirstLine = getConfigs().getBoolean(config, "ignoreFirstLine", false);
      this.trim = getConfigs().getBoolean(config, "trim", true);     
      this.quoteChar = getConfigs().getString(config, "quoteChar", "");
      if (quoteChar.length() > 1) {
        throw new MorphlineCompilationException(
            "Quote character must not have a length of more than one character: " + quoteChar, config);
      }
      if (quoteChar.equals(String.valueOf(separatorChar))) {
        throw new MorphlineCompilationException(
            "Quote character must not be the same as separator: " + quoteChar, config);
      }
      this.commentPrefix = getConfigs().getString(config, "commentPrefix", "");
      if (commentPrefix.length() > 1) {
        throw new MorphlineCompilationException(
            "Comment prefix must not have a length of more than one character: " + commentPrefix, config);
      }
      this.tokenizer = quoteChar.length() == 0 ?
          new SimpleCSVTokenizer(separatorChar, trim, columnNames) :
          new QuotedCSVTokenizer(separatorChar, trim, columnNames, quoteChar.charAt(0));         
View Full Code Here

TOP

Related Classes of com.cloudera.cdk.morphline.api.MorphlineCompilationException

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.