Java Code Examples for org.pentaho.di.core.row.RowMetaInterface#getDate()

The following examples show how to use org.pentaho.di.core.row.RowMetaInterface#getDate() . 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: TableProducer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method is called when a row is written to another step (even if there is no next step)
 *
 * @param rowMeta the metadata of the row
 * @param row     the data of the row
 * @throws org.pentaho.di.core.exception.KettleStepException an exception that can be thrown to hard stop the step
 */
public void rowWrittenEvent( final RowMetaInterface rowMeta, final Object[] row ) throws KettleStepException {
  if ( firstCall ) {
    this.tableModel = createTableModel( rowMeta );
    firstCall = false;
  }

  if ( queryLimit > 0 && rowsWritten > queryLimit ) {
    return;
  }

  try {
    rowsWritten += 1;

    final int count = tableModel.getColumnCount();
    final Object dataRow[] = new Object[ count ];
    for ( int columnNo = 0; columnNo < count; columnNo++ ) {
      final ValueMetaInterface valueMeta = rowMeta.getValueMeta( columnNo );

      switch( valueMeta.getType() ) {
        case ValueMetaInterface.TYPE_BIGNUMBER:
          dataRow[ columnNo ] = rowMeta.getBigNumber( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          dataRow[ columnNo ] = rowMeta.getBoolean( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_DATE:
          dataRow[ columnNo ] = rowMeta.getDate( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_INTEGER:
          dataRow[ columnNo ] = rowMeta.getInteger( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_NONE:
          dataRow[ columnNo ] = rowMeta.getString( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          dataRow[ columnNo ] = rowMeta.getNumber( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_STRING:
          dataRow[ columnNo ] = rowMeta.getString( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_BINARY:
          dataRow[ columnNo ] = rowMeta.getBinary( row, columnNo );
          break;
        default:
          dataRow[ columnNo ] = rowMeta.getString( row, columnNo );
      }
    }
    tableModel.addRow( dataRow );
  } catch ( final KettleValueException kve ) {
    throw new KettleStepException( kve );
  } catch ( final Exception e ) {
    throw new KettleStepException( e );
  }
}
 
Example 2
Source File: InlineEtlQueryExecutor.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void processRow( MemoryResultSet memResults, final RowMetaInterface rowMeta, final Object[] row )
  throws KettleStepException {
  if ( memResults == null ) {
    return;
  }
  try {
    Object[] pentahoRow = new Object[memResults.getColumnCount()];
    for ( int columnNo = 0; columnNo < memResults.getColumnCount(); columnNo++ ) {
      ValueMetaInterface valueMeta = rowMeta.getValueMeta( columnNo );

      switch ( valueMeta.getType() ) {
        case ValueMetaInterface.TYPE_BIGNUMBER:
          pentahoRow[columnNo] = rowMeta.getBigNumber( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          pentahoRow[columnNo] = rowMeta.getBoolean( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_DATE:
          pentahoRow[columnNo] = rowMeta.getDate( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_INTEGER:
          pentahoRow[columnNo] = rowMeta.getInteger( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_NONE:
          pentahoRow[columnNo] = rowMeta.getString( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          pentahoRow[columnNo] = rowMeta.getNumber( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_STRING:
          pentahoRow[columnNo] = rowMeta.getString( row, columnNo );
          break;
        default:
          pentahoRow[columnNo] = rowMeta.getString( row, columnNo );
      }
    }

    if ( logger.isDebugEnabled() ) {
      StringBuffer sb = new StringBuffer();
      for ( int i = 0; i < pentahoRow.length; i++ ) {
        sb.append( pentahoRow[i] ).append( "; " ); //$NON-NLS-1$
      }
      logger.debug( sb.toString() );
    }

    memResults.addRow( pentahoRow );
  } catch ( KettleValueException e ) {
    throw new KettleStepException( e );
  }
}
 
Example 3
Source File: TeraFast.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Write a single row to the temporary data file.
 *
 * @param rowMetaInterface
 *          describe the row of data
 *
 * @param row
 *          row entries
 * @throws KettleException
 *           ...
 */
@SuppressWarnings( "ArrayToString" )
public void writeToDataFile( RowMetaInterface rowMetaInterface, Object[] row ) throws KettleException {
  // Write the data to the output
  ValueMetaInterface valueMeta = null;

  for ( int i = 0; i < row.length; i++ ) {
    if ( row[i] == null ) {
      break; // no more rows
    }
    valueMeta = rowMetaInterface.getValueMeta( i );
    if ( row[i] != null ) {
      switch ( valueMeta.getType() ) {
        case ValueMetaInterface.TYPE_STRING:
          String s = rowMetaInterface.getString( row, i );
          dataFilePrintStream.print( pad( valueMeta, s.toString() ) );
          break;
        case ValueMetaInterface.TYPE_INTEGER:
          Long l = rowMetaInterface.getInteger( row, i );
          dataFilePrintStream.print( pad( valueMeta, l.toString() ) );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          Double d = rowMetaInterface.getNumber( row, i );
          dataFilePrintStream.print( pad( valueMeta, d.toString() ) );
          break;
        case ValueMetaInterface.TYPE_BIGNUMBER:
          BigDecimal bd = rowMetaInterface.getBigNumber( row, i );
          dataFilePrintStream.print( pad( valueMeta, bd.toString() ) );
          break;
        case ValueMetaInterface.TYPE_DATE:
          Date dt = rowMetaInterface.getDate( row, i );
          dataFilePrintStream.print( simpleDateFormat.format( dt ) );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          Boolean b = rowMetaInterface.getBoolean( row, i );
          if ( b.booleanValue() ) {
            dataFilePrintStream.print( "Y" );
          } else {
            dataFilePrintStream.print( "N" );
          }
          break;
        case ValueMetaInterface.TYPE_BINARY:
          byte[] byt = rowMetaInterface.getBinary( row, i );
          // REVIEW - this does an implicit byt.toString, which can't be what was intended.
          dataFilePrintStream.print( byt );
          break;
        default:
          throw new KettleException( BaseMessages.getString(
            PKG, "TeraFast.Exception.TypeNotSupported", valueMeta.getType() ) );
      }
    }
    dataFilePrintStream.print( FastloadControlBuilder.DATAFILE_COLUMN_SEPERATOR );
  }
  dataFilePrintStream.print( Const.CR );
}
 
Example 4
Source File: GPBulkDataOutput.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void writeLine( RowMetaInterface mi, Object[] row ) throws KettleException {
  if ( first ) {
    first = false;

    enclosure = meta.getEnclosure();

    // Setup up the fields we need to take for each of the rows
    // as this speeds up processing.
    fieldNumbers = new int[meta.getFieldStream().length];
    for ( int i = 0; i < fieldNumbers.length; i++ ) {
      fieldNumbers[i] = mi.indexOfValue( meta.getFieldStream()[i] );
      if ( fieldNumbers[i] < 0 ) {
        throw new KettleException( "Could not find field " + meta.getFieldStream()[i] + " in stream" );
      }
    }

    sdfDate = new SimpleDateFormat( "yyyy-MM-dd" );
    sdfDateTime = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" );
  }

  // Write the data to the output
  ValueMetaInterface v = null;
  int number = 0;
  for ( int i = 0; i < fieldNumbers.length; i++ ) {
    if ( i != 0 ) {
      output.print( "," );
    }
    number = fieldNumbers[i];
    v = mi.getValueMeta( number );
    if ( row[number] == null ) {
      // TODO (SB): special check for null in case of Strings.
      output.print( enclosure );
      output.print( enclosure );
    } else {
      switch ( v.getType() ) {
        case ValueMetaInterface.TYPE_STRING:
          String s = mi.getString( row, number );
          if ( s.indexOf( enclosure ) >= 0 ) {
            s = createEscapedString( s, enclosure );
          }
          output.print( enclosure );
          output.print( s );
          output.print( enclosure );
          break;
        case ValueMetaInterface.TYPE_INTEGER:
          Long l = mi.getInteger( row, number );
          output.print( enclosure );
          output.print( l );
          output.print( enclosure );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          Double d = mi.getNumber( row, number );
          output.print( enclosure );
          output.print( d );
          output.print( enclosure );
          break;
        case ValueMetaInterface.TYPE_BIGNUMBER:
          BigDecimal bd = mi.getBigNumber( row, number );
          output.print( enclosure );
          output.print( bd );
          output.print( enclosure );
          break;
        case ValueMetaInterface.TYPE_DATE:
          Date dt = mi.getDate( row, number );
          output.print( enclosure );
          String mask = meta.getDateMask()[i];
          if ( GPBulkLoaderMeta.DATE_MASK_DATETIME.equals( mask ) ) {
            output.print( sdfDateTime.format( dt ) );
          } else {
            // Default is date format
            output.print( sdfDate.format( dt ) );
          }
          output.print( enclosure );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          Boolean b = mi.getBoolean( row, number );
          output.print( enclosure );
          if ( b.booleanValue() ) {
            output.print( "Y" );
          } else {
            output.print( "N" );
          }
          output.print( enclosure );
          break;
        case ValueMetaInterface.TYPE_BINARY:
          byte[] byt = mi.getBinary( row, number );
          output.print( "<startlob>" );
          output.print( byt );
          output.print( "<endlob>" );
          break;
        default:
          throw new KettleException( "Unsupported type" );
      }
    }
  }
  output.print( Const.CR );
}