Esempio n. 1
0
  public String getCreateVarInstructions(String outputFileName, String outputLabel)
      throws LopsException {
    if (getDataType() == DataType.MATRIX || getDataType() == DataType.FRAME) {

      if (isTransient())
        throw new LopsException("getInstructions() should not be called for transient nodes.");

      OutputParameters oparams = getOutputParameters();
      String fmt = "";
      // TODO: following logic should change once we LOPs encode key-value-class information.
      if (oparams.getFormat() == Format.TEXT) fmt = "textcell";
      else if (oparams.getFormat() == Format.MM) fmt = "matrixmarket";
      else if (oparams.getFormat() == Format.CSV) fmt = "csv";
      else {
        if (oparams.getRowsInBlock() > 0 || oparams.getColsInBlock() > 0) fmt = "binaryblock";
        else fmt = "binarycell";
      }

      StringBuilder sb = new StringBuilder();
      sb.append("CP");
      sb.append(OPERAND_DELIMITOR);
      sb.append("createvar");
      sb.append(OPERAND_DELIMITOR);
      sb.append(outputLabel);
      sb.append(OPERAND_DELIMITOR);
      sb.append(outputFileName);
      sb.append(OPERAND_DELIMITOR);
      sb.append(false);
      sb.append(OPERAND_DELIMITOR); // only persistent reads come here!
      sb.append(fmt);
      sb.append(OPERAND_DELIMITOR);
      sb.append(oparams.getNumRows());
      sb.append(OPERAND_DELIMITOR);
      sb.append(oparams.getNumCols());
      sb.append(OPERAND_DELIMITOR);
      sb.append(oparams.getRowsInBlock());
      sb.append(OPERAND_DELIMITOR);
      sb.append(oparams.getColsInBlock());
      sb.append(OPERAND_DELIMITOR);
      sb.append(oparams.getNnz());

      /* Format-specific properties */
      if (oparams.getFormat() == Format.CSV) {
        sb.append(OPERAND_DELIMITOR);
        sb.append(createVarCSVHelper());
      }

      return sb.toString();
    } else {
      throw new LopsException(
          this.printErrorLocation() + "In Data Lop, Unexpected data type " + getDataType());
    }
  }