private void sql() {
    try {
      IngresVectorwiseLoaderMeta info = new IngresVectorwiseLoaderMeta();
      getInfo(info);
      RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
      StepMeta stepMeta = transMeta.findStep(stepname);

      // Only use the fields that were specified.
      //
      RowMetaInterface prevNew = new RowMeta();

      for (int i = 0; i < info.getFieldDatabase().length; i++) {
        ValueMetaInterface insValue = prev.searchValueMeta(info.getFieldStream()[i]);
        if (insValue != null) {
          ValueMetaInterface insertValue = insValue.clone();
          insertValue.setName(info.getFieldDatabase()[i]);
          prevNew.addValueMeta(insertValue);
        } else {
          throw new KettleStepException(
              BaseMessages.getString(
                  PKG,
                  "IngresVectorWiseLoaderDialog.FailedToFindField.Message",
                  info.getFieldStream()[i]));
        }
      }
      prev = prevNew;

      SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
      if (!sql.hasError()) {
        if (sql.hasSQL()) {
          SQLEditor sqledit =
              new SQLEditor(
                  transMeta,
                  shell,
                  SWT.NONE,
                  info.getDatabaseMeta(),
                  transMeta.getDbCache(),
                  sql.getSQL());
          sqledit.open();
        } else {
          MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
          mb.setMessage(
              BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.NoSQL.DialogMessage"));
          mb.setText(BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.NoSQL.DialogTitle"));
          mb.open();
        }
      } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(sql.getError());
        mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
        mb.open();
      }
    } catch (KettleException ke) {
      new ErrorDialog(
          shell,
          BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.BuildSQLError.DialogTitle"),
          BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.BuildSQLError.DialogMessage"),
          ke);
    }
  }
  public SQLStatement getSQLStatements(
      TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev) throws KettleStepException {
    SQLStatement retval =
        new SQLStatement(stepMeta.getName(), databaseMeta, null); // default: nothing to do!

    if (databaseMeta != null) {
      if (prev != null && prev.size() > 0) {
        // Copy the row
        RowMetaInterface tableFields = new RowMeta();

        // Now change the field names
        for (int i = 0; i < fieldTable.length; i++) {
          ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
          if (v != null) {
            ValueMetaInterface tableField = v.clone();
            tableField.setName(fieldTable[i]);
            tableFields.addValueMeta(tableField);
          } else {
            throw new KettleStepException(
                "Unable to find field [" + fieldStream[i] + "] in the input rows");
          }
        }

        if (!Const.isEmpty(tableName)) {
          Database db = new Database(loggingObject, databaseMeta);
          db.shareVariablesWith(transMeta);
          try {
            db.connect();

            String schemaTable =
                databaseMeta.getQuotedSchemaTableCombination(
                    transMeta.environmentSubstitute(schemaName),
                    transMeta.environmentSubstitute(tableName));
            String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);

            if (sql.length() == 0) retval.setSQL(null);
            else retval.setSQL(sql);
          } catch (KettleException e) {
            retval.setError(
                BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.ErrorOccurred")
                    + e.getMessage()); // $NON-NLS-1$
          }
        } else {
          retval.setError(
              BaseMessages.getString(
                  PKG, "GPBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection")); // $NON-NLS-1$
        }
      } else {
        retval.setError(
            BaseMessages.getString(
                PKG, "GPBulkLoaderMeta.GetSQL.NotReceivingAnyFields")); // $NON-NLS-1$
      }
    } else {
      retval.setError(
          BaseMessages.getString(
              PKG, "GPBulkLoaderMeta.GetSQL.NoConnectionDefined")); // $NON-NLS-1$
    }

    return retval;
  }
  public void analyseImpact(
      List<DatabaseImpact> impact,
      TransMeta transMeta,
      StepMeta stepMeta,
      RowMetaInterface prev,
      String[] input,
      String[] output,
      RowMetaInterface info)
      throws KettleStepException {
    if (prev != null) {
      // Lookup: we do a lookup on the natural keys
      for (int i = 0; i < keyLookup.length; i++) {
        ValueMetaInterface v = prev.searchValueMeta(keyStream[i]);

        DatabaseImpact ii =
            new DatabaseImpact(
                DatabaseImpact.TYPE_IMPACT_DELETE,
                transMeta.getName(),
                stepMeta.getName(),
                databaseMeta.getDatabaseName(),
                tableName,
                keyLookup[i],
                keyStream[i],
                v != null ? v.getOrigin() : "?",
                "",
                "Type = " + v.toStringMeta()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        impact.add(ii);
      }
    }
  }
 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 rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
   if (rowNbr >= data.length) {
     throw new ComparisonFailure("too many output rows", "" + data.length, "" + rowNbr + 1);
   } else {
     for (int i = 0; i < data[rowNbr].length; i++) {
       try {
         boolean eq = true;
         if (comparators.containsKey(i)) {
           Comparison<Object> comp = comparators.get(i);
           if (comp != null) {
             eq = comp.equals(data[rowNbr][i], row[i]);
           }
         } else {
           ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
           eq = valueMeta.compare(data[rowNbr][i], row[i]) == 0;
         }
         if (!eq) {
           throw new ComparisonFailure(
               String.format("Mismatch row %d, column %d", rowNbr, i),
               rowMeta.getString(data[rowNbr]),
               rowMeta.getString(row));
         }
       } catch (Exception e) {
         throw new AssertionError(
             String.format("Value type at row %d, column %d", rowNbr, i), e);
       }
     }
     rowNbr++;
   }
 }
  public void analyseImpact(
      List<DatabaseImpact> impact,
      TransMeta transMeta,
      StepMeta stepMeta,
      RowMetaInterface prev,
      String input[],
      String output[],
      RowMetaInterface info)
      throws KettleStepException {
    if (prev != null) {
      /* DEBUG CHECK THIS */
      // Insert dateMask fields : read/write
      for (int i = 0; i < fieldTable.length; i++) {
        ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);

        DatabaseImpact ii =
            new DatabaseImpact(
                DatabaseImpact.TYPE_IMPACT_READ_WRITE,
                transMeta.getName(),
                stepMeta.getName(),
                databaseMeta.getDatabaseName(),
                transMeta.environmentSubstitute(tableName),
                fieldTable[i],
                fieldStream[i],
                v != null ? v.getOrigin() : "?",
                "",
                "Type = " + v.toStringMeta()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        impact.add(ii);
      }
    }
  }
  public void getFields(
      RowMetaInterface r,
      String name,
      RowMetaInterface info[],
      StepMeta nextStep,
      VariableSpace space)
      throws KettleStepException {
    // It's best that this method doesn't change anything by itself.
    // Eventually it's the Mapping step that's going to tell this step how to behave meta-data wise.
    // It is the mapping step that tells the mapping output step what fields to rename.
    //
    if (inputValueRenames != null) {
      for (MappingValueRename valueRename : inputValueRenames) {
        ValueMetaInterface valueMeta = r.searchValueMeta(valueRename.getTargetValueName());
        if (valueMeta != null) {
          valueMeta.setName(valueRename.getSourceValueName());
        }
      }
    }

    // This is the optionally entered stuff in the output tab of the mapping dialog.
    //
    if (outputValueRenames != null) {
      for (MappingValueRename valueRename : outputValueRenames) {
        ValueMetaInterface valueMeta = r.searchValueMeta(valueRename.getSourceValueName());
        if (valueMeta != null) {
          valueMeta.setName(valueRename.getTargetValueName());
        }
      }
    }
  }
 private byte[] formatField(ValueMetaInterface v, Object valueData) throws KettleValueException {
   if (v.isString()) {
     String svalue = (valueData instanceof String) ? (String) valueData : v.getString(valueData);
     return convertStringToBinaryString(v, Const.trimToType(svalue, v.getTrimType()));
   } else {
     return v.getBinaryString(valueData);
   }
 }
  @Override
  public String getFieldDefinition(
      ValueMetaInterface v,
      String tk,
      String pk,
      boolean use_autoinc,
      boolean add_fieldname,
      boolean add_cr) {
    String retval = "";

    String fieldname = v.getName();
    int length = v.getLength();
    int precision = v.getPrecision();

    if (add_fieldname) retval += fieldname + " ";

    int type = v.getType();
    switch (type) {
      case ValueMetaInterface.TYPE_DATE:
        retval += "DATETIME";
        break;
      case ValueMetaInterface.TYPE_BOOLEAN:
        retval += "CHAR(1)";
        break;
      case ValueMetaInterface.TYPE_NUMBER:
      case ValueMetaInterface.TYPE_INTEGER:
      case ValueMetaInterface.TYPE_BIGNUMBER:
        retval += "DECIMAL";
        if (length > 0) {
          retval += "(" + length;
          if (precision > 0) {
            retval += ", " + precision;
          }
          retval += ")";
        }
        break;
      case ValueMetaInterface.TYPE_STRING:
        if (length >= DatabaseMeta.CLOB_LENGTH) {
          retval += "CLOB";
        } else {
          retval += "VARCHAR";
          if (length > 0) {
            retval += "(" + length;
          } else {
            retval += "("; // Maybe use some default DB String length?
          }
          retval += ")";
        }
        break;
      default:
        retval += " UNKNOWN";
        break;
    }

    if (add_cr) retval += Const.CR;

    return retval;
  }
  private void writeField(ValueMetaInterface v, Object valueData, byte[] nullString)
      throws KettleStepException {
    try {
      byte[] str;

      // First check whether or not we have a null string set
      // These values should be set when a null value passes
      //
      if (nullString != null && v.isNull(valueData)) {
        str = nullString;
      } else {
        if (meta.isFastDump()) {
          if (valueData instanceof byte[]) {
            str = (byte[]) valueData;
          } else {
            str = getBinaryString((valueData == null) ? "" : valueData.toString());
          }
        } else {
          str = formatField(v, valueData);
        }
      }

      if (str != null && str.length > 0) {
        List<Integer> enclosures = null;

        if (v.isString() && meta.isEnclosureForced() && !meta.isPadded()) {
          data.writer.write(data.binaryEnclosure);

          // Also check for the existence of the enclosure character.
          // If needed we double (escape) the enclosure character.
          //
          enclosures = getEnclosurePositions(str);
        }

        if (enclosures == null) {
          data.writer.write(str);
        } else {
          // Skip the enclosures, double them instead...
          int from = 0;
          for (int i = 0; i < enclosures.size(); i++) {
            int position = enclosures.get(i);
            data.writer.write(str, from, position + data.binaryEnclosure.length - from);
            data.writer.write(data.binaryEnclosure); // write enclosure a second time
            from = position + data.binaryEnclosure.length;
          }
          if (from < str.length) {
            data.writer.write(str, from, str.length - from);
          }
        }

        if (v.isString() && meta.isEnclosureForced() && !meta.isPadded()) {
          data.writer.write(data.binaryEnclosure);
        }
      }
    } catch (Exception e) {
      throw new KettleStepException("Error writing field content to file", e);
    }
  }
Beispiel #11
0
 private Object convertDataToTargetValueMeta(int i, Object formulaResult) throws KettleException {
   if (formulaResult == null) {
     return formulaResult;
   }
   ValueMetaInterface target = data.outputRowMeta.getValueMeta(i);
   ValueMetaInterface actual = ValueMetaFactory.guessValueMetaInterface(formulaResult);
   Object value = target.convertData(actual, formulaResult);
   return value;
 }
  public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    if (data.linesWritten >= meta.getDataLines().size()) // no more rows to be written
    {
      setOutputDone();
      return false;
    }

    if (first) {
      // The output meta is the original input meta + the
      // additional constant fields.

      first = false;
      data.linesWritten = 0;

      data.outputRowMeta = new RowMeta();
      meta.getFields(data.outputRowMeta, getStepname(), null, null, this);

      // Use these metadata values to convert data...
      //
      data.convertMeta = data.outputRowMeta.clone();
      for (ValueMetaInterface valueMeta : data.convertMeta.getValueMetaList()) {
        valueMeta.setType(ValueMetaInterface.TYPE_STRING);
      }
    }

    Object[] outputRowData = RowDataUtil.allocateRowData(data.outputRowMeta.size());
    List<String> outputLine = meta.getDataLines().get(data.linesWritten);

    for (int i = 0; i < data.outputRowMeta.size(); i++) {
      ValueMetaInterface valueMeta = data.outputRowMeta.getValueMeta(i);
      ValueMetaInterface convertMeta = data.convertMeta.getValueMeta(i);
      String valueData = outputLine.get(i);

      outputRowData[i] = valueMeta.convertDataFromString(valueData, convertMeta, null, null, 0);
    }

    putRow(data.outputRowMeta, outputRowData);
    data.linesWritten++;

    if (log.isRowLevel()) {
      log.logRowlevel(
          toString(),
          BaseMessages.getString(
              PKG,
              "DataGrid.Log.Wrote.Row",
              Long.toString(getLinesWritten()),
              data.outputRowMeta.getString(outputRowData)));
    }

    if (checkFeedback(getLinesWritten())) {
      if (log.isBasic())
        logBasic(
            BaseMessages.getString(PKG, "DataGrid.Log.LineNr", Long.toString(getLinesWritten())));
    }

    return true;
  }
  protected JsonInput createBasicTestJsonInput(
      String jsonPath, ValueMetaInterface outputMeta, final String inCol, Object[]... inputRows) {
    JsonInputField jpath = new JsonInputField(outputMeta.getName());
    jpath.setPath(jsonPath);
    jpath.setType(outputMeta.getType());

    JsonInputMeta meta = createSimpleMeta(inCol, jpath);
    return createJsonInput(inCol, meta, inputRows);
  }
 public static ValueMetaInterface createValueMeta(String name, int type, int length, int precision)
     throws KettlePluginException {
   PluginInterface stringPlugin =
       pluginRegistry.getPlugin(ValueMetaPluginType.class, String.valueOf(type));
   if (stringPlugin == null) {
     throw new KettlePluginException("Unable to locate value meta plugin of type (id) " + type);
   }
   ValueMetaInterface valueMeta = pluginRegistry.loadClass(stringPlugin, ValueMetaInterface.class);
   valueMeta.setName(name);
   valueMeta.setLength(length, precision);
   return valueMeta;
 }
  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);
  }
Beispiel #16
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 ValueMeta(valuename, ValueMetaInterface.TYPE_INTEGER);
   v.setOrigin(name);
   row.addValueMeta(v);
 }
  private Date getIncrementalFieldValue() throws KettleException {
    Date result = null;
    boolean firstRow = true;
    Object[] row;
    RowMetaInterface inputRowMeta;

    while ((row = getRow()) != null) {
      if (firstRow) {
        firstRow = false;
        inputRowMeta = getInputRowMeta();

        if (inputRowMeta == null || inputRowMeta.size() <= 0) {
          if (log.isBasic()) {
            logBasic(BaseMessages.getString(PKG, "ZendeskInput.Error.NoIncomingRows"));
          }
          return null;
        }

        String filenameField = environmentSubstitute(meta.getTimestampFieldName());
        int fieldIndex = inputRowMeta.indexOfValue(filenameField);
        if (fieldIndex < 0) {
          throw new KettleStepException(
              BaseMessages.getString(
                  PKG, "ZendeskInputIncremental.Exception.StartDateFieldNotFound", filenameField));
        }
        ValueMetaInterface fieldValueMeta = inputRowMeta.getValueMeta(fieldIndex);
        if (!(fieldValueMeta instanceof ValueMetaDate)) {
          throw new KettleStepException(
              BaseMessages.getString(
                  PKG,
                  "ZendeskInput.Error.WrongFieldType",
                  ValueMetaFactory.getValueMetaName(fieldValueMeta.getType())));
        } else {
          result = fieldValueMeta.getDate(row[fieldIndex]);
        }
      } else {
        if (log.isDetailed()) {
          logDetailed(
              BaseMessages.getString(PKG, "ZendeskInput.Warning.IgnoringAdditionalInputRows"));
        }
      }
    }

    if (firstRow) {
      if (log.isBasic()) {
        logBasic(BaseMessages.getString(PKG, "ZendeskInput.Error.NoIncomingRows"));
      }
    }

    return result;
  }
  public void analyseImpact(
      List<DatabaseImpact> impact,
      TransMeta transMeta,
      StepMeta stepMeta,
      RowMetaInterface prev,
      String input[],
      String output[],
      RowMetaInterface info) {
    // The keys are read-only...
    for (int i = 0; i < keyField.length; i++) {
      ValueMetaInterface v = prev.searchValueMeta(keyField[i]);
      DatabaseImpact ii =
          new DatabaseImpact(
              DatabaseImpact.TYPE_IMPACT_READ_WRITE,
              transMeta.getName(),
              stepMeta.getName(),
              databaseWriteMeta.getDatabaseName(),
              tablename,
              keyLookup[i],
              keyField[i],
              v != null ? v.getOrigin() : "?", // $NON-NLS-1$
              "", //$NON-NLS-1$
              useHash
                  ? Messages.getString("ConcurrentCombinationLookupMeta.ReadAndInsert.Label")
                  : Messages.getString(
                      "ConcurrentCombinationLookupMeta.LookupAndInsert.Label") //$NON-NLS-1$
              // //$NON-NLS-2$
              );
      impact.add(ii);
    }

    // Do we lookup-on the hash-field?
    if (useHash) {
      DatabaseImpact ii =
          new DatabaseImpact(
              DatabaseImpact.TYPE_IMPACT_READ_WRITE,
              transMeta.getName(),
              stepMeta.getName(),
              databaseWriteMeta.getDatabaseName(),
              tablename,
              hashField,
              "", //$NON-NLS-1$
              "", //$NON-NLS-1$
              "", //$NON-NLS-1$
              Messages.getString("ConcurrentCombinationLookupMeta.KeyLookup.Label") // $NON-NLS-1$
              );
      impact.add(ii);
    }
  }
Beispiel #20
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);
    }
  }
  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);
    }
  }
Beispiel #22
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);
   }
 }
 /**
  * *************************************** formatting routines for "unformatted" output
  * ****************************************.
  *
  * @param valueMeta the value meta
  * @param valueData the value data
  * @return the byte[]
  * @throws KettleValueException the kettle value exception
  */
 static byte[] convertChar(ValueMetaInterface valueMeta, Object valueData)
     throws KettleValueException {
   String string = valueMeta.getString(valueData);
   if (string != null) {
     return (string.getBytes());
   }
   return null;
 }
  protected int getDataForRow(TableItem item, Object[] row) {
    int nrErrors = 0;

    // Display the correct line item...
    //
    String strNr;
    lineNr++;
    try {
      strNr = wFields.getNumberColumn().getValueMeta().getString(new Long(lineNr));
    } catch (Exception e) {
      strNr = Integer.toString(lineNr);
    }
    item.setText(0, strNr);

    for (int c = 0; c < rowMeta.size(); c++) {
      ValueMetaInterface v = rowMeta.getValueMeta(c);
      String show;
      try {
        show = v.getString(row[c]);
        if (v.isBinary() && show != null && show.length() > MAX_BINARY_STRING_PREVIEW_SIZE) {
          // We want to limit the size of the strings during preview to keep all SWT widgets happy.
          //
          show = show.substring(0, MAX_BINARY_STRING_PREVIEW_SIZE);
        }
      } catch (KettleValueException e) {
        nrErrors++;
        if (nrErrors < 25) {
          log.logError(Const.getStackTracker(e));
        }
        show = null;
      } catch (ArrayIndexOutOfBoundsException e) {
        nrErrors++;
        if (nrErrors < 25) {
          log.logError(Const.getStackTracker(e));
        }
        show = null;
      }

      if (show != null) {
        item.setText(c + 1, show);
      }
    }

    return nrErrors;
  }
  @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);
      }
    }
  }
 public void getFields(
     RowMetaInterface inputRowMeta,
     String name,
     RowMetaInterface[] info,
     StepMeta nextStep,
     VariableSpace space,
     Repository repository,
     IMetaStore metaStore)
     throws KettleStepException {
   // Set the sorted properties: ascending/descending
   for (int i = 0; i < fieldName.length; i++) {
     int idx = inputRowMeta.indexOfValue(fieldName[i]);
     if (idx >= 0) {
       ValueMetaInterface valueMeta = inputRowMeta.getValueMeta(idx);
       valueMeta.setSortedDescending(!ascending[i]);
       valueMeta.setCaseInsensitive(!caseSensitive[i]);
       valueMeta.setCollatorDisabled(!collatorEnabled[i]);
       valueMeta.setCollatorStrength(collatorStrength[i]);
       // Also see if lazy conversion is active on these key fields.
       // If so we want to automatically convert them to the normal storage type.
       // This will improve performance, see also: PDI-346
       //
       valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
       valueMeta.setStorageMetadata(null);
     }
   }
 }
  public void analyseImpact(
      List<DatabaseImpact> impact,
      TransMeta transMeta,
      StepMeta stepinfo,
      RowMetaInterface prev,
      String input[],
      String output[],
      RowMetaInterface info) {
    // The keys are read-only...
    for (int i = 0; i < streamKeyField1.length; i++) {
      ValueMetaInterface v = prev.searchValueMeta(streamKeyField1[i]);
      DatabaseImpact ii =
          new DatabaseImpact(
              DatabaseImpact.TYPE_IMPACT_READ,
              transMeta.getName(),
              stepinfo.getName(),
              databaseMeta.getDatabaseName(),
              tablename,
              tableKeyField[i],
              streamKeyField1[i],
              v != null ? v.getOrigin() : "?", // $NON-NLS-1$
              "", //$NON-NLS-1$
              Messages.getString("DatabaseLookupMeta.Impact.Key") // $NON-NLS-1$
              );
      impact.add(ii);
    }

    // The Return fields are read-only too...
    for (int i = 0; i < returnValueField.length; i++) {
      DatabaseImpact ii =
          new DatabaseImpact(
              DatabaseImpact.TYPE_IMPACT_READ,
              transMeta.getName(),
              stepinfo.getName(),
              databaseMeta.getDatabaseName(),
              tablename,
              returnValueField[i],
              "", //$NON-NLS-1$
              "", //$NON-NLS-1$
              "", //$NON-NLS-1$
              Messages.getString("DatabaseLookupMeta.Impact.ReturnValue") // $NON-NLS-1$
              );
      impact.add(ii);
    }
  }
Beispiel #29
0
 private void writeField(ValueMetaInterface valueMeta, Object valueData, String element)
     throws KettleStepException {
   try {
     String str = XMLHandler.addTagValue(element, valueMeta.getString(valueData), false);
     if (str != null) data.writer.write(str.toCharArray());
   } catch (Exception e) {
     throw new KettleStepException("Error writing line :", e); // $NON-NLS-1$
   }
 }
 private void assertGetFieldDefinition(
     ValueMetaInterface valueMetaInterface, String expectedType) {
   assertEquals(
       expectedType,
       impalaDatabaseMeta.getFieldDefinition(valueMetaInterface, null, null, false, false, false));
   assertEquals(
       valueMetaInterface.getName() + " " + expectedType,
       impalaDatabaseMeta.getFieldDefinition(valueMetaInterface, null, null, false, true, false));
 }