Java Code Examples for org.pentaho.di.core.row.RowDataUtil#addValueData()

The following examples show how to use org.pentaho.di.core.row.RowDataUtil#addValueData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UniqueRows.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private Object[] addCounter( RowMetaInterface outputRowMeta, Object[] r, long count ) {
  if ( meta.isCountRows() ) {
    Object[] outputRow = RowDataUtil.addValueData( r, outputRowMeta.size() - 1, new Long( count ) );

    return outputRow;
  } else {
    return r; // nothing to do
  }
}
 
Example 2
Source File: RowMetaAndData.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void addValue( ValueMetaInterface valueMeta, Object valueData ) {
  if ( valueMeta.isInteger() && ( valueData instanceof ObjectId ) ) {
    valueData = new LongObjectId( (ObjectId) valueData ).longValue();
  }
  data = RowDataUtil.addValueData( data, rowMeta.size(), valueData );
  rowMeta.addValueMeta( valueMeta );
}
 
Example 3
Source File: JsonOutput.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings( "unchecked" )
private void outPutRow( Object[] rowData ) throws KettleStepException {
  // We can now output an object
  data.jg = new JSONObject();
  data.jg.put( data.realBlocName, data.ja );
  String value = data.jg.toJSONString();

  if ( data.outputValue && data.outputRowMeta != null ) {
    Object[] outputRowData = RowDataUtil.addValueData( rowData, data.inputRowMetaSize, value );
    incrementLinesOutput();
    putRow( data.outputRowMeta, outputRowData );
  }

  if ( data.writeToFile && !data.ja.isEmpty() ) {
    // Open a file
    if ( !openNewFile() ) {
      throw new KettleStepException( BaseMessages.getString(
        PKG, "JsonOutput.Error.OpenNewFile", buildFilename() ) );
    }
    // Write data to file
    try {
      data.writer.write( value );
    } catch ( Exception e ) {
      throw new KettleStepException( BaseMessages.getString( PKG, "JsonOutput.Error.Writing" ), e );
    }
    // Close file
    closeFile();
  }
  // Data are safe
  data.rowsAreSafe = true;
  data.ja = new JSONArray();
}
 
Example 4
Source File: DummyPlugin.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (DummyPluginMeta) smi;
  data = (DummyPluginData) sdi;

  Object[] r = getRow();    // get row, blocks when needed!
  if ( r == null ) { // no more input to be expected...
    setOutputDone();
    return false;
  }

  if ( first ) {
    first = false;

    data.outputRowMeta = getInputRowMeta().clone();
    meta.getFields( data.outputRowMeta, getStepname(), null, null, this );
  }

  Object extraValue = meta.getValue().getValueData();

  Object[] outputRow = RowDataUtil.addValueData( r, data.outputRowMeta.size() - 1, extraValue );

  putRow( data.outputRowMeta, outputRow );     // copy row to possible alternate rowset(s).

  if ( checkFeedback( getLinesRead() ) ) {
    logBasic( "Linenr " + getLinesRead() );  // Some basic logging every 5000 rows.
  }

  return true;
}
 
Example 5
Source File: GroupBy.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void handleLastOfGroup() throws KettleException {
  if ( meta.passAllRows() ) {
    // ALL ROWS

    if ( data.previous != null ) {
      calcAggregate( data.previous );
      addToBuffer( data.previous );
    }
    data.groupResult = getAggregateResult();

    Object[] row = getRowFromBuffer();

    long lineNr = 0;
    while ( row != null ) {
      int size = data.inputRowMeta.size();
      row = RowDataUtil.addRowData( row, size, data.groupResult );
      size += data.groupResult.length;
      lineNr++;

      if ( meta.isAddingLineNrInGroup() && !Utils.isEmpty( meta.getLineNrInGroupField() ) ) {
        Object lineNrValue = new Long( lineNr );
        // ValueMetaInterface lineNrValueMeta = new ValueMeta(meta.getLineNrInGroupField(),
        // ValueMetaInterface.TYPE_INTEGER);
        // lineNrValueMeta.setLength(9);
        row = RowDataUtil.addValueData( row, size, lineNrValue );
        size++;
      }

      addCumulativeSums( row );
      addCumulativeAverages( row );

      putRow( data.outputRowMeta, row );
      row = getRowFromBuffer();
    }
    closeInput();
  } else {
    // JUST THE GROUP + AGGREGATE

    // Don't forget the last set of rows...
    if ( data.previous != null ) {
      calcAggregate( data.previous );
    }
    Object[] result = buildResult( data.previous );
    if ( result != null ) {
      putRow( data.groupAggMeta, result );
    }
  }
}
 
Example 6
Source File: StepMetastructure.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {

    Object[] r = getRow(); // Get row from input rowset & set row busy!
    Object[] metastructureRow = null;

    // initialize
    if ( first ) {
      first = false;

      // handle empty input
      if ( r == null ) {
        setOutputDone();
        return false;
      }

      // Create the row metadata for the output rows
      //
      data.outputRowMeta = new RowMeta();
      meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );
    }

    if ( r == null ) {
      metastructureRow = RowDataUtil.allocateRowData( data.outputRowMeta.size() );

      RowMetaInterface row = getInputRowMeta().clone();

      for ( int i = 0; i < row.size(); i++ ) {

        ValueMetaInterface v = row.getValueMeta( i );

        ValueMetaInterface v_position = data.outputRowMeta.getValueMeta( 0 );
        metastructureRow =
          RowDataUtil.addValueData( metastructureRow, 0, v_position.convertDataCompatible( v_position, new Long(
            i + 1 ) ) );

        metastructureRow = RowDataUtil.addValueData( metastructureRow, 1, v.getName() );
        metastructureRow = RowDataUtil.addValueData( metastructureRow, 2, v.getComments() );
        metastructureRow = RowDataUtil.addValueData( metastructureRow, 3, v.getTypeDesc() );

        ValueMetaInterface v_length = data.outputRowMeta.getValueMeta( 4 );
        metastructureRow =
          RowDataUtil.addValueData( metastructureRow, 4, v_length.convertDataCompatible( v_length, new Long( v
            .getLength() ) ) );

        ValueMetaInterface v_precision = data.outputRowMeta.getValueMeta( 5 );
        metastructureRow =
          RowDataUtil.addValueData( metastructureRow, 5, v_precision.convertDataCompatible(
            v_precision, new Long( v.getPrecision() ) ) );

        metastructureRow = RowDataUtil.addValueData( metastructureRow, 6, v.getOrigin() );

        if ( meta.isOutputRowcount() ) {
          ValueMetaInterface v_rowCount = data.outputRowMeta.getValueMeta( 7 );
          metastructureRow =
            RowDataUtil.addValueData( metastructureRow, 7, v_rowCount.convertDataCompatible(
              v_rowCount, new Long( data.rowCount ) ) );
        }
        putRow( data.outputRowMeta, metastructureRow.clone() );
      }

      // We're done, call it a day
      //
      setOutputDone();
      return false;
    }

    data.rowCount++;

    return true;

  }
 
Example 7
Source File: TableExists.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException {
  meta = (TableExistsMeta) smi;
  data = (TableExistsData) sdi;

  boolean sendToErrorRow = false;
  String errorMessage = null;

  Object[] r = getRow(); // Get row from input rowset & set row busy!
  if ( r == null ) { // no more input to be expected...

    setOutputDone();
    return false;
  }

  boolean tablexists = false;
  try {
    if ( first ) {
      first = false;
      data.outputRowMeta = getInputRowMeta().clone();
      meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

      // Check is tablename field is provided
      if ( Utils.isEmpty( meta.getDynamicTablenameField() ) ) {
        logError( BaseMessages.getString( PKG, "TableExists.Error.TablenameFieldMissing" ) );
        throw new KettleException( BaseMessages.getString( PKG, "TableExists.Error.TablenameFieldMissing" ) );
      }

      // cache the position of the field
      if ( data.indexOfTablename < 0 ) {
        data.indexOfTablename = getInputRowMeta().indexOfValue( meta.getDynamicTablenameField() );
        if ( data.indexOfTablename < 0 ) {
          // The field is unreachable !
          logError( BaseMessages.getString( PKG, "TableExists.Exception.CouldnotFindField" )
            + "[" + meta.getDynamicTablenameField() + "]" );
          throw new KettleException( BaseMessages.getString(
            PKG, "TableExists.Exception.CouldnotFindField", meta.getDynamicTablenameField() ) );
        }
      }
    } // End If first

    // get tablename
    String tablename = getInputRowMeta().getString( r, data.indexOfTablename );

    // Check if table exists on the specified connection
    tablexists = data.db.checkTableExists( data.realSchemaname, tablename );

    Object[] outputRowData = RowDataUtil.addValueData( r, getInputRowMeta().size(), tablexists );

    // add new values to the row.
    putRow( data.outputRowMeta, outputRowData ); // copy row to output rowset(s);

    if ( log.isRowLevel() ) {
      logRowlevel( BaseMessages.getString( PKG, "TableExists.LineNumber", getLinesRead()
        + " : " + getInputRowMeta().getString( r ) ) );
    }
  } catch ( KettleException e ) {
    if ( getStepMeta().isDoingErrorHandling() ) {
      sendToErrorRow = true;
      errorMessage = e.toString();
    } else {
      logError( BaseMessages.getString( PKG, "TableExists.ErrorInStepRunning" + " : " + e.getMessage() ) );
      throw new KettleStepException( BaseMessages.getString( PKG, "TableExists.Log.ErrorInStep" ), e );
    }
    if ( sendToErrorRow ) {
      // Simply add this row to the error row
      putError( getInputRowMeta(), r, 1, errorMessage, meta.getResultFieldName(), "TableExistsO01" );
    }
  }

  return true;
}