public void getFields(
     RowMetaInterface row,
     String name,
     RowMetaInterface[] info,
     StepMeta nextStep,
     VariableSpace space)
     throws KettleStepException {
   if (Const.isEmpty(info) || info[0] == null) // null or length 0 : no info from database
   {
     for (int i = 0; i < returnValueNewName.length; i++) {
       ValueMetaInterface v = new ValueMeta(returnValueNewName[i], returnValueDefaultType[i]);
       v.setOrigin(name);
       row.addValueMeta(v);
     }
   } else {
     for (int i = 0; i < returnValueNewName.length; i++) {
       ValueMetaInterface v = info[0].searchValueMeta(returnValueField[i]);
       if (v != null) {
         v.setName(returnValueNewName[i]);
         v.setOrigin(name);
         row.addValueMeta(v);
       }
     }
   }
 }
  @Override
  public void getFields(
      RowMetaInterface row,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space,
      Repository repository,
      IMetaStore metaStore)
      throws KettleStepException {

    for (SasInputField field : outputFields) {
      try {
        ValueMetaInterface valueMeta =
            ValueMetaFactory.createValueMeta(field.getRename(), field.getType());
        valueMeta.setLength(field.getLength(), field.getPrecision());
        valueMeta.setDecimalSymbol(field.getDecimalSymbol());
        valueMeta.setGroupingSymbol(field.getGroupingSymbol());
        valueMeta.setConversionMask(field.getConversionMask());
        valueMeta.setTrimType(field.getTrimType());
        valueMeta.setOrigin(name);

        row.addValueMeta(valueMeta);
      } catch (Exception e) {
        throw new KettleStepException(e);
      }
    }
  }
Example #3
0
  public void getFields(
      RowMetaInterface r,
      String name,
      RowMetaInterface info[],
      StepMeta nextStep,
      VariableSpace space,
      Repository repository,
      IMetaStore metaStore)
      throws KettleStepException {
    int i;
    for (i = 0; i < inputFields.length; i++) {
      RssInputField field = inputFields[i];

      int type = field.getType();
      if (type == ValueMeta.TYPE_NONE) type = ValueMeta.TYPE_STRING;
      try {
        ValueMetaInterface v =
            ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
        v.setLength(field.getLength(), field.getPrecision());
        v.setOrigin(name);
        r.addValueMeta(v);
      } catch (Exception e) {
        throw new KettleStepException(e);
      }
    }

    if (includeUrl) {
      ValueMetaInterface v =
          new ValueMeta(space.environmentSubstitute(urlField), ValueMeta.TYPE_STRING);
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }

    if (includeRowNumber) {
      ValueMetaInterface v =
          new ValueMeta(space.environmentSubstitute(rowNumberField), ValueMeta.TYPE_INTEGER);
      v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
  }
  public void getFields(
      RowMetaInterface row,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {

    ValueMetaInterface v = new ValueMeta(this.getValueName(), ValueMetaInterface.TYPE_STRING);
    v.setOrigin(name);
    row.addValueMeta(v);
  }
Example #5
0
  @Override
  public void getFields(
      RowMetaInterface row,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {

    // Remove the key value (there will be different entries for each output row)
    //
    if (keyField != null && keyField.length() > 0) {
      int idx = row.indexOfValue(keyField);
      if (idx < 0) {
        throw new KettleStepException(
            BaseMessages.getString(
                PKG, "DenormaliserMeta.Exception.UnableToLocateKeyField", keyField));
      } //$NON-NLS-1$ //$NON-NLS-2$
      row.removeValueMeta(idx);
    } else {
      throw new KettleStepException(
          BaseMessages.getString(
              PKG, "DenormaliserMeta.Exception.RequiredKeyField")); // $NON-NLS-1$
    }

    // Remove all field value(s) (there will be different entries for each output row)
    //
    for (int i = 0; i < denormaliserTargetField.length; i++) {
      String fieldname = denormaliserTargetField[i].getFieldName();
      if (fieldname != null && fieldname.length() > 0) {
        int idx = row.indexOfValue(fieldname);
        if (idx >= 0) {
          row.removeValueMeta(idx);
        }
      } else {
        throw new KettleStepException(
            BaseMessages.getString(
                PKG,
                "DenormaliserMeta.Exception.RequiredTargetFieldName",
                (i + 1) + "")); // $NON-NLS-1$ //$NON-NLS-2$
      }
    }

    // Re-add the target fields
    for (int i = 0; i < denormaliserTargetField.length; i++) {
      DenormaliserTargetField field = denormaliserTargetField[i];
      ValueMetaInterface target = new ValueMeta(field.getTargetName(), field.getTargetType());
      target.setLength(field.getTargetLength(), field.getTargetPrecision());
      target.setOrigin(name);
      row.addValueMeta(target);
    }
  }
  public void getFields(
      RowMetaInterface row,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space,
      Repository repository,
      IMetaStore metaStore)
      throws KettleStepException {

    ValueMetaInterface v = new ValueMetaString(newFieldname);
    v.setOrigin(name);
    row.addValueMeta(v);

    // include row number
    if (includeRowNumber) {
      v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
      v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
      v.setOrigin(name);
      row.addValueMeta(v);
    }
  }
 public void getFields(
     RowMetaInterface row,
     String name,
     RowMetaInterface[] info,
     StepMeta nextStep,
     VariableSpace space,
     Repository repository,
     IMetaStore metaStore)
     throws KettleStepException {
   ValueMetaInterface v = new ValueMeta(valuename, ValueMetaInterface.TYPE_INTEGER);
   v.setOrigin(name);
   row.addValueMeta(v);
 }
  public void getFields(
      RowMetaInterface inputRowMeta,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space,
      Repository repository,
      IMetaStore metaStore)
      throws KettleStepException {

    if (!Const.isEmpty(resultfieldname)) {
      ValueMetaInterface v = new ValueMeta(resultfieldname, ValueMeta.TYPE_BOOLEAN);
      v.setOrigin(name);
      inputRowMeta.addValueMeta(v);
    }
  }
Example #9
0
  public void getFields(
      RowMetaInterface row,
      String origin,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {
    row.clear(); // TODO: add an option to also include the input data...

    for (SapOutputField field : outputFields) {

      ValueMetaInterface valueMeta = new ValueMeta(field.getNewName(), field.getTargetType());
      valueMeta.setOrigin(origin);
      row.addValueMeta(valueMeta);
    }
  }
Example #10
0
 public void getFields(
     RowMetaInterface inputRowMeta,
     String name,
     RowMetaInterface info[],
     StepMeta nextStep,
     VariableSpace space)
     throws KettleStepException {
   for (int i = 0; i < fieldOutStream.length; i++) {
     if (!Const.isEmpty(fieldOutStream[i])) {
       ValueMetaInterface v =
           new ValueMeta(space.environmentSubstitute(fieldOutStream[i]), ValueMeta.TYPE_STRING);
       v.setLength(100, -1);
       v.setOrigin(name);
       inputRowMeta.addValueMeta(v);
     }
   }
 }
 /* This function adds meta data to the rows being pushed out */
 public void getFields(
     RowMetaInterface r,
     String name,
     RowMetaInterface[] info,
     StepMeta nextStep,
     VariableSpace space,
     Repository repository,
     IMetaStore metaStore)
     throws KettleStepException {
   String realfieldname = space.environmentSubstitute(getSalesforceIDFieldName());
   if (!Const.isEmpty(realfieldname)) {
     ValueMetaInterface v = new ValueMetaString(realfieldname);
     v.setLength(18);
     v.setOrigin(name);
     r.addValueMeta(v);
   }
 }
  public static ValueMetaInterface cloneValueMeta(ValueMetaInterface source, int targetType)
      throws KettlePluginException {
    ValueMetaInterface target = null;

    // If we're Cloneable and not changing types, call clone()
    if (source instanceof Cloneable && source.getType() == targetType) {
      target = source.clone();
    } else {
      target =
          createValueMeta(source.getName(), targetType, source.getLength(), source.getPrecision());
    }
    target.setConversionMask(source.getConversionMask());
    target.setDecimalSymbol(source.getDecimalSymbol());
    target.setGroupingSymbol(source.getGroupingSymbol());
    target.setStorageType(source.getStorageType());
    if (source.getStorageMetadata() != null) {
      target.setStorageMetadata(
          cloneValueMeta(source.getStorageMetadata(), source.getStorageMetadata().getType()));
    }
    target.setStringEncoding(source.getStringEncoding());
    target.setTrimType(source.getTrimType());
    target.setDateFormatLenient(source.isDateFormatLenient());
    target.setDateFormatLocale(source.getDateFormatLocale());
    target.setDateFormatTimeZone(source.getDateFormatTimeZone());
    target.setLenientStringToNumber(source.isLenientStringToNumber());
    target.setLargeTextField(source.isLargeTextField());
    target.setComments(source.getComments());
    target.setCaseInsensitive(source.isCaseInsensitive());
    target.setIndex(source.getIndex());

    target.setOrigin(source.getOrigin());

    target.setOriginalAutoIncrement(source.isOriginalAutoIncrement());
    target.setOriginalColumnType(source.getOriginalColumnType());
    target.setOriginalColumnTypeName(source.getOriginalColumnTypeName());
    target.setOriginalNullable(source.isOriginalNullable());
    target.setOriginalPrecision(source.getOriginalPrecision());
    target.setOriginalScale(source.getOriginalScale());
    target.setOriginalSigned(source.isOriginalSigned());

    return target;
  }
 /* This function adds meta data to the rows being pushed out */
 public void getFields(
     RowMetaInterface r,
     String name,
     RowMetaInterface[] info,
     StepMeta nextStep,
     VariableSpace space,
     Repository repository,
     IMetaStore metaStore)
     throws KettleStepException {
   if (StringUtils.isNotBlank(this.getIdOutField())) {
     ValueMetaInterface valueMeta =
         new ValueMeta(
             space.environmentSubstitute(this.getIdOutField()), ValueMetaInterface.TYPE_STRING);
     valueMeta.setOrigin(name);
     // add if doesn't exist
     if (!r.exists(valueMeta)) {
       r.addValueMeta(valueMeta);
     }
   }
 }
Example #14
0
  public void getFields(
      RowMetaInterface r,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space) {
    // Remove the field to split
    int idx = r.indexOfValue(splitField);
    if (idx < 0) // not found
    {
      throw new RuntimeException(
          BaseMessages.getString(
              PKG,
              "FieldSplitter.Log.CouldNotFindFieldToSplit",
              splitField)); //$NON-NLS-1$ //$NON-NLS-2$
    }

    // Add the new fields at the place of the index --> replace!
    for (int i = 0; i < fieldName.length; i++) {
      final ValueMetaInterface v = new ValueMeta(fieldName[i], fieldType[i]);
      v.setLength(fieldLength[i], fieldPrecision[i]);
      v.setOrigin(name);
      v.setConversionMask(fieldFormat[i]);
      v.setDecimalSymbol(fieldDecimal[i]);
      v.setGroupingSymbol(fieldGroup[i]);
      v.setCurrencySymbol(fieldCurrency[i]);
      v.setTrimType(fieldTrimType[i]);
      // TODO when implemented in UI
      // v.setDateFormatLenient(dateFormatLenient);
      // TODO when implemented in UI
      // v.setDateFormatLocale(dateFormatLocale);
      if (i == 0 && idx >= 0) {
        // the first valueMeta (splitField) will be replaced
        r.setValueMeta(idx, v);
      } else {
        // other valueMeta will be added
        if (idx >= r.size()) r.addValueMeta(v);
        r.addValueMeta(idx + i, v);
      }
    }
  }
Example #15
0
  /**
   * Generates row meta structure from a fields array.
   *
   * @param fields the fields array
   * @param origin the data origin
   * @param rowMeta the row meta to generate
   */
  public static void fieldsToRowMeta(
      final CobFileInputField[] fields, final String origin, final RowMetaInterface rowMeta) {

    rowMeta.clear(); // Start with a clean slate, eats the input

    for (int i = 0; i < fields.length; i++) {
      CobFileInputField field = fields[i];

      ValueMetaInterface valueMeta = new ValueMeta(field.getName(), field.getType());
      valueMeta.setConversionMask(field.getFormat());
      valueMeta.setLength(field.getLength());
      valueMeta.setPrecision(field.getPrecision());
      valueMeta.setConversionMask(field.getFormat());
      valueMeta.setDecimalSymbol(field.getDecimalSymbol());
      valueMeta.setGroupingSymbol(field.getGroupSymbol());
      valueMeta.setCurrencySymbol(field.getCurrencySymbol());
      valueMeta.setTrimType(field.getTrimType());
      valueMeta.setOrigin(origin);

      rowMeta.addValueMeta(valueMeta);
    }
  }
Example #16
0
  public void getFields(
      RowMetaInterface row,
      String origin,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {
    List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
    RowMetaAndData rowMetaAndData = RowGenerator.buildRow(this, remarks, origin);
    if (!remarks.isEmpty()) {
      StringBuffer stringRemarks = new StringBuffer();
      for (CheckResultInterface remark : remarks) {
        stringRemarks.append(remark.toString()).append(Const.CR);
      }
      throw new KettleStepException(stringRemarks.toString());
    }

    for (ValueMetaInterface valueMeta : rowMetaAndData.getRowMeta().getValueMetaList()) {
      valueMeta.setOrigin(origin);
    }

    row.mergeRowMeta(rowMetaAndData.getRowMeta());
  }
Example #17
0
  public void getFields(
      RowMetaInterface row,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {

    // Remember the types of the row.
    int fieldnrs[] = new int[fieldName.length];
    ValueMetaInterface[] values = new ValueMetaInterface[fieldName.length];

    for (int i = 0; i < fieldName.length; i++) {
      fieldnrs[i] = row.indexOfValue(fieldName[i]);
      ValueMetaInterface v = row.getValueMeta(fieldnrs[i]);
      values[i] = v.clone(); // copy value : default settings!
      switch (aggregateType[i]) {
        case TYPE_AGGREGATE_AVERAGE:
        case TYPE_AGGREGATE_COUNT:
        case TYPE_AGGREGATE_SUM:
          values[i].setType(Value.VALUE_TYPE_NUMBER);
          values[i].setLength(-1, -1);
          break;
      }
    }

    // Only the aggregate is returned!
    row.clear();

    for (int i = 0; i < fieldName.length; i++) {
      ValueMetaInterface v = values[i];
      v.setName(fieldNewName[i]);
      v.setOrigin(name);
      row.addValueMeta(v);
    }
  }
  public void getFields(
      RowMetaInterface row,
      String origin,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {
    if (!Const.isEmpty(technicalKeyField)) {
      ValueMetaInterface v = new ValueMeta(technicalKeyField, ValueMetaInterface.TYPE_INTEGER);
      v.setLength(10);
      v.setPrecision(0);
      v.setOrigin(origin);
      row.addValueMeta(v);
    }

    if (replaceFields) {
      for (int i = 0; i < keyField.length; i++) {
        int idx = row.indexOfValue(keyField[i]);
        if (idx >= 0) {
          row.removeValueMeta(idx);
        }
      }
    }
  }
  public void getFields(
      RowMetaInterface r,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space,
      Repository repository,
      IMetaStore metaStore)
      throws KettleStepException {

    int i;
    for (i = 0; i < inputFields.length; i++) {
      PropertyInputField field = inputFields[i];

      int type = field.getType();
      if (type == ValueMetaInterface.TYPE_NONE) {
        type = ValueMetaInterface.TYPE_STRING;
      }
      try {
        ValueMetaInterface v =
            ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
        v.setLength(field.getLength());
        v.setPrecision(field.getPrecision());
        v.setOrigin(name);
        v.setConversionMask(field.getFormat());
        v.setDecimalSymbol(field.getDecimalSymbol());
        v.setGroupingSymbol(field.getGroupSymbol());
        v.setCurrencySymbol(field.getCurrencySymbol());
        r.addValueMeta(v);
      } catch (Exception e) {
        throw new KettleStepException(e);
      }
    }
    String realFilenameField = space.environmentSubstitute(filenameField);
    if (includeFilename && !Utils.isEmpty(realFilenameField)) {
      ValueMetaInterface v = new ValueMetaString(realFilenameField);
      v.setLength(500);
      v.setPrecision(-1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }

    String realRowNumberField = space.environmentSubstitute(rowNumberField);
    if (includeRowNumber && !Utils.isEmpty(realRowNumberField)) {
      ValueMetaInterface v = new ValueMetaInteger(realRowNumberField);
      v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    String realSectionField = space.environmentSubstitute(iniSectionField);
    if (includeIniSection && !Utils.isEmpty(realSectionField)) {
      ValueMetaInterface v = new ValueMetaString(realSectionField);
      v.setLength(500);
      v.setPrecision(-1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    // Add additional fields

    if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
      ValueMetaInterface v =
          new ValueMetaString(space.environmentSubstitute(getShortFileNameField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    if (getExtensionField() != null && getExtensionField().length() > 0) {
      ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getExtensionField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    if (getPathField() != null && getPathField().length() > 0) {
      ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getPathField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    if (getSizeField() != null && getSizeField().length() > 0) {
      ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(getSizeField()));
      v.setOrigin(name);
      v.setLength(9);
      r.addValueMeta(v);
    }
    if (isHiddenField() != null && isHiddenField().length() > 0) {
      ValueMetaInterface v = new ValueMetaBoolean(space.environmentSubstitute(isHiddenField()));
      v.setOrigin(name);
      r.addValueMeta(v);
    }

    if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
      ValueMetaInterface v =
          new ValueMetaDate(space.environmentSubstitute(getLastModificationDateField()));
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    if (getUriField() != null && getUriField().length() > 0) {
      ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getUriField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }

    if (getRootUriField() != null && getRootUriField().length() > 0) {
      ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getRootUriField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
  }
Example #20
0
  private ValueMetaInterface getValueMeta(CalculatorMetaFunction fn, String origin) {
    ValueMetaInterface v = new ValueMeta(fn.getFieldName(), fn.getValueType());

    // What if the user didn't specify a data type?
    // In that case we look for the default data type
    //
    if (fn.getValueType() == ValueMetaInterface.TYPE_NONE) {
      int defaultResultType = ValueMetaInterface.TYPE_NONE;

      switch (fn.getCalcType()) {
        case CalculatorMetaFunction.CALC_NONE:
          break;
        case CalculatorMetaFunction.CALC_ADD: // A + B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_SUBTRACT: // A - B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_MULTIPLY: // A * B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_DIVIDE: // A / B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_SQUARE: // A * A
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_SQUARE_ROOT: // SQRT( A )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_PERCENT_1: // 100 * A / B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_PERCENT_2: // A - ( A * B / 100 )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_PERCENT_3: // A + ( A * B / 100 )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_COMBINATION_1: // A + B * C
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_COMBINATION_2: // SQRT( A*A + B*B )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_ROUND_1: // ROUND( A )
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_ROUND_2: //  ROUND( A , B )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_ROUND_STD_1: // STDROUND( A )
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_ROUND_STD_2: //  STDROUND( A , B )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_CONSTANT: // Set field to constant value...
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_NVL: // Replace null values with another value
          break;
        case CalculatorMetaFunction.CALC_ADD_DAYS: // Add B days to date field A
          defaultResultType = ValueMetaInterface.TYPE_DATE;
          break;
        case CalculatorMetaFunction.CALC_YEAR_OF_DATE: // What is the year (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_MONTH_OF_DATE: // What is the month (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_DAY_OF_YEAR: // What is the day of year (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_DAY_OF_MONTH: // What is the day of month (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_DAY_OF_WEEK: // What is the day of week (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_WEEK_OF_YEAR: // What is the week of year (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_WEEK_OF_YEAR_ISO8601: // What is the week of year (Integer) of a date ISO8601
          // style?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_YEAR_OF_DATE_ISO8601: // What is the year (Integer) of a date ISO8601 style?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_BYTE_TO_HEX_ENCODE: // Byte to Hex encode string field A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_HEX_TO_BYTE_DECODE: // Hex to Byte decode string field A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_CHAR_TO_HEX_ENCODE: // Char to Hex encode string field A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_HEX_TO_CHAR_DECODE: // Hex to Char decode string field A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_CRC32: // CRC32 of a file A
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_ADLER32: // ADLER32 of a file A
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_MD5: // MD5 of a file A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_SHA1: // SHA1 of a file Al
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction
            .CALC_LEVENSHTEIN_DISTANCE: // LEVENSHTEIN_DISTANCE of string A and string B
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_METAPHONE: // METAPHONE of string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_DOUBLE_METAPHONE: // Double METAPHONE of string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_ABS: // ABS( A )
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_TIME_FROM_DATE: // Remove time from field A
          defaultResultType = ValueMetaInterface.TYPE_DATE;
          break;
        case CalculatorMetaFunction.CALC_DATE_DIFF: // DateA - DateB
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_ADD3: // A + B +C
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_INITCAP: // InitCap(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_UPPER_CASE: // UpperCase(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_LOWER_CASE: // LowerCase(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_MASK_XML: // MaskXML(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_USE_CDATA: // CDATA(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_CR: // REMOVE CR FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_LF: // REMOVE LF FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_CRLF: // REMOVE CRLF FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_TAB: // REMOVE TAB FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_GET_ONLY_DIGITS: // GET ONLY DIGITS FROM string A
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_DIGITS: // REMOVE DIGITS FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_STRING_LEN: // LENGTH OF string A
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_LOAD_FILE_CONTENT_BINARY: // LOAD FILE CONTENT IN BLOB
          defaultResultType = ValueMetaInterface.TYPE_BINARY;
          break;
        case CalculatorMetaFunction.CALC_ADD_TIME_TO_DATE: // ADD TIME TO A DATE
          defaultResultType = ValueMetaInterface.TYPE_DATE;
          break;
        case CalculatorMetaFunction
            .CALC_QUARTER_OF_DATE: // What is the quarter (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_SUBSTITUTE_VARIABLE: // variable substitution in string
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_ESCAPE_HTML: // escape HTML
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_ESCAPE_SQL: // escape SQL
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_UNESCAPE_HTML: // unEscape HTML
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_UNESCAPE_XML: // unEscape XML
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_DATE_WORKING_DIFF: // Date A - Date B
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_ADD_MONTHS: // Date A - B Months
          defaultResultType = ValueMetaInterface.TYPE_DATE;
          break;
        case CalculatorMetaFunction.CALC_CHECK_XML_FILE_WELL_FORMED: // XML file A well formed
          defaultResultType = ValueMetaInterface.TYPE_BOOLEAN;
          break;
        case CalculatorMetaFunction.CALC_CHECK_XML_WELL_FORMED: // XML string A well formed
          defaultResultType = ValueMetaInterface.TYPE_BOOLEAN;
          break;
        case CalculatorMetaFunction.CALC_GET_FILE_ENCODING: // get file encoding
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_DAMERAU_LEVENSHTEIN:
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_NEEDLEMAN_WUNSH:
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_JARO:
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_JARO_WINKLER:
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_SOUNDEX:
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_REFINED_SOUNDEX:
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_CEIL: // CEIL( A )
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_FLOOR: // FLOOR( A )
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_HOUR_OF_DAY:
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_MINUTE_OF_HOUR:
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_SECOND_OF_MINUTE:
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        default:
          break;
      }

      v = new ValueMeta(fn.getFieldName(), defaultResultType);
    }

    v.setLength(fn.getValueLength());
    v.setPrecision(fn.getValuePrecision());
    v.setOrigin(origin);
    v.setComments(fn.getCalcTypeDesc());
    v.setConversionMask(fn.getConversionMask());
    v.setDecimalSymbol(fn.getDecimalSymbol());
    v.setGroupingSymbol(fn.getGroupingSymbol());
    v.setCurrencySymbol(fn.getCurrencySymbol());

    return v;
  }
  public void getFields(
      RowMetaInterface rowMeta,
      String origin,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {
    // depending on who calls this method (preview, show output/input fields, etc)
    // we need to give back the appropriate information
    if (nextStep == null || nextStep.getName().equals(stepMain)) {
      ValueMetaInterface totalGroups = new ValueMeta("ruleengine_groups", ValueMeta.TYPE_INTEGER);
      totalGroups.setOrigin(origin);
      rowMeta.addValueMeta(totalGroups);

      ValueMetaInterface totalGroupsFailed =
          new ValueMeta("ruleengine_groups_failed", ValueMeta.TYPE_INTEGER);
      totalGroupsFailed.setOrigin(origin);
      rowMeta.addValueMeta(totalGroupsFailed);

      ValueMetaInterface totalRules = new ValueMeta("ruleengine_rules", ValueMeta.TYPE_INTEGER);
      totalRules.setOrigin(origin);
      rowMeta.addValueMeta(totalRules);

      ValueMetaInterface totalRulesFailed =
          new ValueMeta("ruleengine_rules_failed", ValueMeta.TYPE_INTEGER);
      totalRulesFailed.setOrigin(origin);
      rowMeta.addValueMeta(totalRulesFailed);

      ValueMetaInterface totalActions = new ValueMeta("ruleengine_actions", ValueMeta.TYPE_INTEGER);
      totalActions.setOrigin(origin);
      rowMeta.addValueMeta(totalActions);
    } else if (nextStep.getName().equals(stepRuleResults)) {
      ValueMetaInterface group = new ValueMeta("ruleengine_group", ValueMeta.TYPE_STRING);
      group.setOrigin(origin);
      rowMeta.addValueMeta(group);

      ValueMetaInterface groupFailed =
          new ValueMeta("ruleengine_group_failed", ValueMeta.TYPE_INTEGER);
      groupFailed.setOrigin(origin);
      rowMeta.addValueMeta(groupFailed);

      ValueMetaInterface subgroup = new ValueMeta("ruleengine_subgroup", ValueMeta.TYPE_STRING);
      subgroup.setOrigin(origin);
      rowMeta.addValueMeta(subgroup);

      ValueMetaInterface subgroupFailed =
          new ValueMeta("ruleengine_subgroup_failed", ValueMeta.TYPE_INTEGER);
      subgroupFailed.setOrigin(origin);
      rowMeta.addValueMeta(subgroupFailed);

      ValueMetaInterface subgroupIntergroupOperator =
          new ValueMeta("ruleengine_subgroup_intergroup_operator", ValueMeta.TYPE_STRING);
      subgroupIntergroupOperator.setOrigin(origin);
      rowMeta.addValueMeta(subgroupIntergroupOperator);

      ValueMetaInterface subgroupRuleOperator =
          new ValueMeta("ruleengine_subgroup_rule_operator", ValueMeta.TYPE_STRING);
      subgroupRuleOperator.setOrigin(origin);
      rowMeta.addValueMeta(subgroupRuleOperator);

      ValueMetaInterface rule = new ValueMeta("ruleengine_rule", ValueMeta.TYPE_STRING);
      rule.setOrigin(origin);
      rowMeta.addValueMeta(rule);

      ValueMetaInterface ruleFailed =
          new ValueMeta("ruleengine_rule_failed", ValueMeta.TYPE_INTEGER);
      ruleFailed.setOrigin(origin);
      rowMeta.addValueMeta(ruleFailed);

      ValueMetaInterface ruleMessage = new ValueMeta("ruleengine_message", ValueMeta.TYPE_STRING);
      ruleMessage.setOrigin(origin);
      rowMeta.addValueMeta(ruleMessage);
    }
  }
  public void getFields(
      RowMetaInterface row,
      String origin,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {
    // Row should normally be empty when we get here.
    // That is because there is no previous step to this mapping input step from the viewpoint of
    // this single sub-transformation.
    // From the viewpoint of the transformation that executes the mapping, it's important to know
    // what comes out at the exit points.
    // For that reason we need to re-order etc, based on the input specification...
    //
    if (inputRowMeta != null && !inputRowMeta.isEmpty()) {
      // this gets set only in the parent transformation...
      // It includes all the renames that needed to be done
      //
      if (selectingAndSortingUnspecifiedFields) {

        // First rename any fields...
        if (valueRenames != null) {
          for (MappingValueRename valueRename : valueRenames) {
            ValueMetaInterface valueMeta =
                inputRowMeta.searchValueMeta(valueRename.getSourceValueName());
            if (valueMeta == null) {
              throw new KettleStepException(
                  BaseMessages.getString(
                      PKG,
                      "MappingInput.Exception.UnableToFindMappedValue",
                      valueRename.getSourceValueName()));
            }
            valueMeta.setName(valueRename.getTargetValueName());
          }
        }

        // Select the specified fields from the input, re-order everything and put the other fields
        // at the back, sorted...
        //
        RowMetaInterface newRow = new RowMeta();

        for (int i = 0; i < fieldName.length; i++) {
          int index = inputRowMeta.indexOfValue(fieldName[i]);
          if (index < 0) {
            throw new KettleStepException(
                BaseMessages.getString(
                    PKG, "MappingInputMeta.Exception.UnknownField", fieldName[i]));
          }

          newRow.addValueMeta(inputRowMeta.getValueMeta(index));
        }

        // Now get the unspecified fields.
        // Sort the fields
        // Add them after the specified fields...
        //
        List<String> extra = new ArrayList<String>();
        for (int i = 0; i < inputRowMeta.size(); i++) {
          String fieldName = inputRowMeta.getValueMeta(i).getName();
          if (newRow.indexOfValue(fieldName) < 0) {
            extra.add(fieldName);
          }
        }
        Collections.sort(extra);
        for (String fieldName : extra) {
          ValueMetaInterface extraValue = inputRowMeta.searchValueMeta(fieldName);
          newRow.addValueMeta(extraValue);
        }

        // now merge the new row...
        // This is basically the input row meta data with the fields re-ordered.
        //
        row.mergeRowMeta(newRow);
      } else {
        row.mergeRowMeta(inputRowMeta);

        // Validate the existence of all the specified fields...
        //
        if (!row.isEmpty()) {
          for (int i = 0; i < fieldName.length; i++) {
            if (row.indexOfValue(fieldName[i]) < 0) {
              throw new KettleStepException(
                  BaseMessages.getString(
                      PKG, "MappingInputMeta.Exception.UnknownField", fieldName[i]));
            }
          }
        }
      }
    } else {
      // We'll have to work with the statically provided information
      for (int i = 0; i < fieldName.length; i++) {
        if (!Const.isEmpty(fieldName[i])) {
          ValueMetaInterface v = new ValueMeta(fieldName[i], fieldType[i]);
          if (v.getType() == ValueMetaInterface.TYPE_NONE)
            v.setType(ValueMetaInterface.TYPE_STRING);
          v.setLength(fieldLength[i]);
          v.setPrecision(fieldPrecision[i]);
          v.setOrigin(origin);
          row.addValueMeta(v);
        }
      }
    }
  }
  public void getFields(
      RowMetaInterface rowMeta,
      String origin,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {
    rowMeta.clear(); // Start with a clean slate, eats the input

    for (int i = 0; i < inputFields.length; i++) {
      TextFileInputField field = inputFields[i];

      ValueMetaInterface valueMeta = new ValueMeta(field.getName(), field.getType());
      valueMeta.setConversionMask(field.getFormat());
      valueMeta.setLength(field.getLength());
      valueMeta.setPrecision(field.getPrecision());
      valueMeta.setConversionMask(field.getFormat());
      valueMeta.setDecimalSymbol(field.getDecimalSymbol());
      valueMeta.setGroupingSymbol(field.getGroupSymbol());
      valueMeta.setCurrencySymbol(field.getCurrencySymbol());
      valueMeta.setTrimType(field.getTrimType());
      if (lazyConversionActive)
        valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
      valueMeta.setStringEncoding(space.environmentSubstitute(encoding));

      // In case we want to convert Strings...
      // Using a copy of the valueMeta object means that the inner and outer representation format
      // is the same.
      // Preview will show the data the same way as we read it.
      // This layout is then taken further down the road by the metadata through the transformation.
      //
      ValueMetaInterface storageMetadata = valueMeta.clone();
      storageMetadata.setType(ValueMetaInterface.TYPE_STRING);
      storageMetadata.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
      storageMetadata.setLength(
          -1, -1); // we don't really know the lengths of the strings read in advance.
      valueMeta.setStorageMetadata(storageMetadata);

      valueMeta.setOrigin(origin);

      rowMeta.addValueMeta(valueMeta);
    }

    if (!Const.isEmpty(filenameField) && includingFilename) {
      ValueMetaInterface filenameMeta =
          new ValueMeta(filenameField, ValueMetaInterface.TYPE_STRING);
      filenameMeta.setOrigin(origin);
      if (lazyConversionActive) {
        filenameMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
        filenameMeta.setStorageMetadata(
            new ValueMeta(filenameField, ValueMetaInterface.TYPE_STRING));
      }
      rowMeta.addValueMeta(filenameMeta);
    }

    if (!Const.isEmpty(rowNumField)) {
      ValueMetaInterface rowNumMeta = new ValueMeta(rowNumField, ValueMetaInterface.TYPE_INTEGER);
      rowNumMeta.setLength(10);
      rowNumMeta.setOrigin(origin);
      rowMeta.addValueMeta(rowNumMeta);
    }
  }
Example #24
0
  @Override
  public void getFields(
      RowMetaInterface rowMeta,
      String origin,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space,
      Repository repository,
      IMetaStore metaStore) {
    // re-assemble a new row of metadata
    //
    RowMetaInterface fields = new RowMeta();

    if (!passAllRows) {
      // Add the grouping fields in the correct order...
      //
      for (int i = 0; i < groupField.length; i++) {
        ValueMetaInterface valueMeta = rowMeta.searchValueMeta(groupField[i]);
        if (valueMeta != null) {
          fields.addValueMeta(valueMeta);
        }
      }
    } else {
      // Add all the original fields from the incoming row meta
      //
      fields.addRowMeta(rowMeta);
    }

    // Re-add aggregates
    //
    for (int i = 0; i < subjectField.length; i++) {
      ValueMetaInterface subj = rowMeta.searchValueMeta(subjectField[i]);
      if (subj != null || aggregateType[i] == TYPE_GROUP_COUNT_ANY) {
        String valueName = aggregateField[i];
        int valueType = ValueMetaInterface.TYPE_NONE;
        int length = -1;
        int precision = -1;

        switch (aggregateType[i]) {
          case TYPE_GROUP_SUM:
          case TYPE_GROUP_AVERAGE:
          case TYPE_GROUP_CUMULATIVE_SUM:
          case TYPE_GROUP_CUMULATIVE_AVERAGE:
          case TYPE_GROUP_FIRST:
          case TYPE_GROUP_LAST:
          case TYPE_GROUP_FIRST_INCL_NULL:
          case TYPE_GROUP_LAST_INCL_NULL:
          case TYPE_GROUP_MIN:
          case TYPE_GROUP_MAX:
            valueType = subj.getType();
            break;
          case TYPE_GROUP_COUNT_DISTINCT:
          case TYPE_GROUP_COUNT_ANY:
          case TYPE_GROUP_COUNT_ALL:
            valueType = ValueMetaInterface.TYPE_INTEGER;
            break;
          case TYPE_GROUP_CONCAT_COMMA:
            valueType = ValueMetaInterface.TYPE_STRING;
            break;
          case TYPE_GROUP_STANDARD_DEVIATION:
          case TYPE_GROUP_MEDIAN:
          case TYPE_GROUP_PERCENTILE:
            valueType = ValueMetaInterface.TYPE_NUMBER;
            break;
          case TYPE_GROUP_CONCAT_STRING:
            valueType = ValueMetaInterface.TYPE_STRING;
            break;
          default:
            break;
        }

        // Change type from integer to number in case off averages for cumulative average
        //
        if (aggregateType[i] == TYPE_GROUP_CUMULATIVE_AVERAGE
            && valueType == ValueMetaInterface.TYPE_INTEGER) {
          valueType = ValueMetaInterface.TYPE_NUMBER;
          precision = -1;
          length = -1;
        } else if (aggregateType[i] == TYPE_GROUP_COUNT_ALL
            || aggregateType[i] == TYPE_GROUP_COUNT_DISTINCT
            || aggregateType[i] == TYPE_GROUP_COUNT_ANY) {
          length = ValueMetaInterface.DEFAULT_INTEGER_LENGTH;
          precision = 0;
        } else if (aggregateType[i] == TYPE_GROUP_SUM
            && valueType != ValueMetaInterface.TYPE_INTEGER
            && valueType != ValueMetaInterface.TYPE_NUMBER
            && valueType != ValueMetaInterface.TYPE_BIGNUMBER) {
          // If it ain't numeric, we change it to Number
          //
          valueType = ValueMetaInterface.TYPE_NUMBER;
          precision = -1;
          length = -1;
        }

        if (valueType != ValueMetaInterface.TYPE_NONE) {
          ValueMetaInterface v = new ValueMeta(valueName, valueType);
          v.setOrigin(origin);
          v.setLength(length, precision);
          fields.addValueMeta(v);
        }
      }
    }

    if (passAllRows) {
      // If we pass all rows, we can add a line nr in the group...
      if (addingLineNrInGroup && !Utils.isEmpty(lineNrInGroupField)) {
        ValueMetaInterface lineNr = new ValueMetaInteger(lineNrInGroupField);
        lineNr.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
        lineNr.setOrigin(origin);
        fields.addValueMeta(lineNr);
      }
    }

    // Now that we have all the fields we want, we should clear the original row and replace the
    // values...
    //
    rowMeta.clear();
    rowMeta.addRowMeta(fields);
  }
 // Rogers (07/2014)
 private void addValueMeta(
     RowMetaInterface outputRowMeta, String fieldName, int type, String origin) {
   ValueMetaInterface field = new ValueMeta(fieldName, type);
   field.setOrigin(origin);
   outputRowMeta.addValueMeta(field);
 }
  public static final RowMetaAndData buildRow(
      RowGeneratorMeta meta, List<CheckResultInterface> remarks, String origin) {
    RowMetaInterface rowMeta = new RowMeta();
    Object[] rowData = RowDataUtil.allocateRowData(meta.getFieldName().length);

    for (int i = 0; i < meta.getFieldName().length; i++) {
      int valtype = ValueMeta.getType(meta.getFieldType()[i]);
      if (meta.getFieldName()[i] != null) {
        ValueMetaInterface valueMeta =
            new ValueMeta(meta.getFieldName()[i], valtype); // build a value!
        valueMeta.setLength(meta.getFieldLength()[i]);
        valueMeta.setPrecision(meta.getFieldPrecision()[i]);
        valueMeta.setConversionMask(meta.getFieldFormat()[i]);
        valueMeta.setGroupingSymbol(meta.getGroup()[i]);
        valueMeta.setDecimalSymbol(meta.getDecimal()[i]);
        valueMeta.setOrigin(origin);

        ValueMetaInterface stringMeta = valueMeta.clone();
        stringMeta.setType(ValueMetaInterface.TYPE_STRING);

        String stringValue = meta.getValue()[i];

        // If the value is empty: consider it to be NULL.
        if (Const.isEmpty(stringValue)) {
          rowData[i] = null;

          if (valueMeta.getType() == ValueMetaInterface.TYPE_NONE) {
            String message =
                BaseMessages.getString(
                    PKG,
                    "RowGenerator.CheckResult.SpecifyTypeError",
                    valueMeta.getName(),
                    stringValue);
            remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
          }
        } else {
          // Convert the data from String to the specified type ...
          //
          try {
            rowData[i] = valueMeta.convertData(stringMeta, stringValue);
          } catch (KettleValueException e) {
            switch (valueMeta.getType()) {
              case ValueMetaInterface.TYPE_NUMBER:
                {
                  String message =
                      BaseMessages.getString(
                          PKG,
                          "RowGenerator.BuildRow.Error.Parsing.Number",
                          valueMeta.getName(),
                          stringValue,
                          e.toString());
                  remarks.add(
                      new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                }
                break;
              case ValueMetaInterface.TYPE_DATE:
                {
                  String message =
                      BaseMessages.getString(
                          PKG,
                          "RowGenerator.BuildRow.Error.Parsing.Date",
                          valueMeta.getName(),
                          stringValue,
                          e.toString());
                  remarks.add(
                      new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                }
                break;
              case ValueMetaInterface.TYPE_INTEGER:
                {
                  String message =
                      BaseMessages.getString(
                          PKG,
                          "RowGenerator.BuildRow.Error.Parsing.Integer",
                          valueMeta.getName(),
                          stringValue,
                          e.toString());
                  remarks.add(
                      new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                }
                break;
              case ValueMetaInterface.TYPE_BIGNUMBER:
                {
                  String message =
                      BaseMessages.getString(
                          PKG,
                          "RowGenerator.BuildRow.Error.Parsing.BigNumber",
                          valueMeta.getName(),
                          stringValue,
                          e.toString());
                  remarks.add(
                      new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                }
                break;
              default:
                // Boolean and binary don't throw errors normally, so it's probably an unspecified
                // error problem...
                {
                  String message =
                      BaseMessages.getString(
                          PKG,
                          "RowGenerator.CheckResult.SpecifyTypeError",
                          valueMeta.getName(),
                          stringValue);
                  remarks.add(
                      new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                }
                break;
            }
          }
        }
        // Now add value to the row!
        // This is in fact a copy from the fields row, but now with data.
        rowMeta.addValueMeta(valueMeta);
      }
    }

    return new RowMetaAndData(rowMeta, rowData);
  }
  private ValueMetaInterface getValueMeta(CalculatorMetaFunction fn, String origin) {
    ValueMetaInterface v = new ValueMeta(fn.getFieldName(), fn.getValueType());
    v.setLength(fn.getValueLength());
    v.setPrecision(fn.getValuePrecision());
    v.setOrigin(origin);
    v.setComments(fn.getCalcTypeDesc());
    v.setConversionMask(fn.getConversionMask());
    v.setDecimalSymbol(fn.getDecimalSymbol());
    v.setGroupingSymbol(fn.getGroupingSymbol());
    v.setCurrencySymbol(fn.getCurrencySymbol());

    // What if the user didn't specify a data type?
    // In that case we look for the default data type
    //
    if (fn.getValueType() == ValueMetaInterface.TYPE_NONE) {
      int defaultResultType = ValueMetaInterface.TYPE_NONE;

      switch (fn.getCalcType()) {
        case CalculatorMetaFunction.CALC_NONE:
          break;
        case CalculatorMetaFunction.CALC_ADD: // A + B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_SUBTRACT: // A - B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_MULTIPLY: // A * B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_DIVIDE: // A / B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_SQUARE: // A * A
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_SQUARE_ROOT: // SQRT( A )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_PERCENT_1: // 100 * A / B
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_PERCENT_2: // A - ( A * B / 100 )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_PERCENT_3: // A + ( A * B / 100 )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_COMBINATION_1: // A + B * C
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_COMBINATION_2: // SQRT( A*A + B*B )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_ROUND_1: // ROUND( A )
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_ROUND_2: //  ROUND( A , B )
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_CONSTANT: // Set field to constant value...
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_NVL: // Replace null values with another value
          break;
        case CalculatorMetaFunction.CALC_ADD_DAYS: // Add B days to date field A
          defaultResultType = ValueMetaInterface.TYPE_DATE;
          break;
        case CalculatorMetaFunction.CALC_YEAR_OF_DATE: // What is the year (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_MONTH_OF_DATE: // What is the month (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_DAY_OF_YEAR: // What is the day of year (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_DAY_OF_MONTH: // What is the day of month (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_DAY_OF_WEEK: // What is the day of week (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_WEEK_OF_YEAR: // What is the week of year (Integer) of a date?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_WEEK_OF_YEAR_ISO8601: // What is the week of year (Integer) of a date ISO8601
          // style?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction
            .CALC_YEAR_OF_DATE_ISO8601: // What is the year (Integer) of a date ISO8601 style?
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_BYTE_TO_HEX_ENCODE: // Byte to Hex encode string field A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_HEX_TO_BYTE_DECODE: // Hex to Byte decode string field A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_CHAR_TO_HEX_ENCODE: // Char to Hex encode string field A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_HEX_TO_CHAR_DECODE: // Hex to Char decode string field A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_CRC32: // CRC32 of a file A
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_ADLER32: // ADLER32 of a file A
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_MD5: // MD5 of a file A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_SHA1: // SHA1 of a file Al
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction
            .CALC_LEVENSHTEIN_DISTANCE: // LEVENSHTEIN_DISTANCE of string A and string B
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_METAPHONE: // METAPHONE of string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_DOUBLE_METAPHONE: // Double METAPHONE of string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_ABS: // ABS( A )
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_TIME_FROM_DATE: // Remove time from field A
          defaultResultType = ValueMetaInterface.TYPE_DATE;
          break;
        case CalculatorMetaFunction.CALC_DATE_DIFF: // DateA - DateB
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_ADD3: // A + B +C
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_INITCAP: // InitCap(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_UPPER_CASE: // UpperCase(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_LOWER_CASE: // LowerCase(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_MASK_XML: // MaskXML(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_USE_CDATA: // CDATA(A)
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_CR: // REMOVE CR FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_LF: // REMOVE LF FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_CRLF: // REMOVE CRLF FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_TAB: // REMOVE TAB FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_GET_ONLY_DIGITS: // GET ONLY DIGITS FROM string A
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_REMOVE_DIGITS: // REMOVE DIGITS FROM string A
          defaultResultType = ValueMetaInterface.TYPE_STRING;
          break;
        case CalculatorMetaFunction.CALC_STRING_LEN: // LENGTH OF string A
          defaultResultType = ValueMetaInterface.TYPE_INTEGER;
          break;
        case CalculatorMetaFunction.CALC_LOAD_FILE_CONTENT_BINARY: // LOAD FILE CONTENT IN BLOB
          defaultResultType = ValueMetaInterface.TYPE_BINARY;
          break;
        case CalculatorMetaFunction.CALC_ADD_TIME_TO_DATE: // ADD TIME TO A DATE
          defaultResultType = ValueMetaInterface.TYPE_DATE;
          break;
        case CalculatorMetaFunction.CALC_GEOM_UNION: // Calculate geometry union
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_INTERSECTION: // Calculate geometry intersection
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_DIFFERENCE: // Calculate geometry difference
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction
            .CALC_GEOM_SYMETRIC_DIFFERENCE: // Calculate geometry symetric difference
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_AREA: // Calculate area
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_GEOM_LENGTH: // Calculate length
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        case CalculatorMetaFunction.CALC_GEOM_CENTROID: // Calculate centroid
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_POINT_ON_SURFACE: // Calculate random point on surface
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_REVERSE: // Reverse geometry
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_BOUNDARY: // Calculate geometry boundary
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_ENVELOPE: // Calculate geometry envelope
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_CONVEX_HULL: // Calculate geometry convex hull
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_BUFFER: // Calculate geometry buffer
          defaultResultType = ValueMetaInterface.TYPE_GEOMETRY;
          break;
        case CalculatorMetaFunction.CALC_GEOM_DISTANCE: // Calculate distance between geometries
          defaultResultType = ValueMetaInterface.TYPE_NUMBER;
          break;
        default:
          break;
      }

      v.setType(defaultResultType);
    }

    return v;
  }