Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#setConversionMask()

The following examples show how to use org.pentaho.di.core.row.ValueMetaInterface#setConversionMask() . 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: SetValueConstant.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void updateField( Object[] r ) throws Exception {
  // Loop through fields
  for ( int i = 0; i < data.getFieldnr(); i++ ) {
    // DO CONVERSION OF THE DEFAULT VALUE ...
    // Entered by user
    ValueMetaInterface targetValueMeta = data.getOutputRowMeta().getValueMeta( data.getFieldnrs()[i] );
    ValueMetaInterface sourceValueMeta = data.getConvertRowMeta().getValueMeta( data.getFieldnrs()[i] );

    if ( !Utils.isEmpty( meta.getField( i ).getReplaceMask() ) ) {
      sourceValueMeta.setConversionMask( meta.getField( i ).getReplaceMask() );
    }

    sourceValueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
    r[data.getFieldnrs()[i]] = targetValueMeta.convertData( sourceValueMeta, data.getRealReplaceByValues()[i] );
    targetValueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
  }
}
 
Example 2
Source File: JsonRowMeta.java    From kettle-beam with Apache License 2.0 6 votes vote down vote up
public static RowMetaInterface fromJson(String rowMetaJson) throws ParseException, KettlePluginException {
  JSONParser parser = new JSONParser();
  JSONObject jRowMeta = (JSONObject) parser.parse( rowMetaJson );

  RowMetaInterface rowMeta = new RowMeta(  );

  JSONArray jValues = (JSONArray) jRowMeta.get("values");
  for (int v=0;v<jValues.size();v++) {
    JSONObject jValue = (JSONObject) jValues.get( v );
    String name = (String) jValue.get("name");
    long type = (long)jValue.get("type");
    long length = (long)jValue.get("length");
    long precision = (long)jValue.get("precision");
    String conversionMask = (String) jValue.get("conversionMask");
    ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( name, (int)type, (int)length, (int)precision );
    valueMeta.setConversionMask( conversionMask );
    rowMeta.addValueMeta( valueMeta );
  }

  return rowMeta;

}
 
Example 3
Source File: GetPreviousRowFieldMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  // Add new field?
  for ( int i = 0; i < fieldOutStream.length; i++ ) {
    if ( !Utils.isEmpty( fieldOutStream[i] ) ) {
      int index = inputRowMeta.indexOfValue( fieldInStream[i] );
      if ( index >= 0 ) {
        ValueMetaInterface in = inputRowMeta.getValueMeta( index );
        try {
          ValueMetaInterface v =
            ValueMetaFactory.createValueMeta( space.environmentSubstitute( fieldOutStream[i] ), in.getType() );
          v.setName( space.environmentSubstitute( fieldOutStream[i] ) );
          v.setLength( in.getLength() );
          v.setPrecision( in.getPrecision() );
          v.setConversionMask( in.getConversionMask() );
          v.setOrigin( name );
          inputRowMeta.addValueMeta( v );
        } catch ( Exception e ) {
          throw new KettleStepException( e );
        }
      }
    }
  }
}
 
Example 4
Source File: RegexEvalMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private ValueMetaInterface constructValueMeta( ValueMetaInterface sourceValueMeta, String fieldName, int i,
  String name ) throws KettlePluginException {
  int type = fieldType[i];
  if ( type == ValueMetaInterface.TYPE_NONE ) {
    type = ValueMetaInterface.TYPE_STRING;
  }
  ValueMetaInterface v;
  if ( sourceValueMeta == null ) {
    v = ValueMetaFactory.createValueMeta( fieldName, type );
  } else {
    v = ValueMetaFactory.cloneValueMeta( sourceValueMeta, type );
  }
  v.setLength( fieldLength[i] );
  v.setPrecision( 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] );

  return v;
}
 
Example 5
Source File: SasInputMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: JsonInputField.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public ValueMetaInterface toValueMeta( String fieldOriginStepName, VariableSpace vspace ) throws KettlePluginException {
  int type = getType();
  if ( type == ValueMetaInterface.TYPE_NONE ) {
    type = ValueMetaInterface.TYPE_STRING;
  }
  ValueMetaInterface v =
      ValueMetaFactory.createValueMeta( vspace != null ? vspace.environmentSubstitute( getName() ) : getName(), type );
  v.setLength( getLength() );
  v.setPrecision( getPrecision() );
  v.setOrigin( fieldOriginStepName );
  v.setConversionMask( getFormat() );
  v.setDecimalSymbol( getDecimalSymbol() );
  v.setGroupingSymbol( getGroupSymbol() );
  v.setCurrencySymbol( getCurrencySymbol() );
  v.setTrimType( getTrimType() );
  return v;
}
 
Example 7
Source File: ConstantMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void getFields( RowMetaInterface rowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  for ( int i = 0; i < fieldName.length; i++ ) {
    if ( fieldName[i] != null && fieldName[i].length() != 0 ) {
      int type = ValueMetaFactory.getIdForValueMeta( fieldType[i] );
      if ( type == ValueMetaInterface.TYPE_NONE ) {
        type = ValueMetaInterface.TYPE_STRING;
      }
      try {
        ValueMetaInterface v = ValueMetaFactory.createValueMeta( fieldName[i], type );
        v.setLength( fieldLength[i] );
        v.setPrecision( fieldPrecision[i] );
        v.setOrigin( name );
        v.setConversionMask( fieldFormat[i] );
        rowMeta.addValueMeta( v );
      } catch ( Exception e ) {
        throw new KettleStepException( e );
      }
    }
  }
}
 
Example 8
Source File: StringToKettleFn.java    From kettle-beam with Apache License 2.0 5 votes vote down vote up
@ProcessElement
public void processElement( ProcessContext processContext ) {

  try {

    String inputString = processContext.element();
    inputCounter.inc();

    String[] components = inputString.split( separator, -1 );

    // TODO: implement enclosure in FileDefinition
    //

    Object[] row = RowDataUtil.allocateRowData( rowMeta.size() );
    int index = 0;
    while ( index < rowMeta.size() && index < components.length ) {
      String sourceString = components[ index ];
      ValueMetaInterface valueMeta = rowMeta.getValueMeta( index );
      ValueMetaInterface stringMeta = new ValueMetaString( "SourceString" );
      stringMeta.setConversionMask( valueMeta.getConversionMask() );
      try {
        row[ index ] = valueMeta.convertDataFromString( sourceString, stringMeta, null, null, ValueMetaInterface.TRIM_TYPE_NONE );
      } catch ( KettleValueException ve ) {
        throw new KettleException( "Unable to convert value '" + sourceString + "' to value : " + valueMeta.toStringMeta(), ve );
      }
      index++;
    }

    // Pass the row to the process context
    //
    processContext.output( new KettleRow( row ) );
    writtenCounter.inc();

  } catch ( Exception e ) {
    Metrics.counter( "error", stepname ).inc();
    LOG.error( "Error converting input data into Kettle rows " + processContext.element() + ", " + e.getMessage() );
    throw new RuntimeException( "Error converting input data into Kettle rows", e );

  }
}
 
Example 9
Source File: ValueMetaFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void cloneInfo( ValueMetaInterface source, ValueMetaInterface target ) throws KettlePluginException {
  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.setCollatorDisabled( source.isCollatorDisabled() );
  target.setCollatorStrength( source.getCollatorStrength() );
  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() );
}
 
Example 10
Source File: GoogleSpreadsheetInputMeta.java    From pdi-google-spreadsheet-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    try {
        inputRowMeta.clear(); // Start with a clean slate, eats the input

        for (TextFileInputField field : inputFields) {
            ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(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.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
            valueMeta.setDateFormatLenient(true);
            valueMeta.setStringEncoding("UTF-8");

            ValueMetaInterface storageMetadata = ValueMetaFactory.cloneValueMeta(valueMeta, 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(name);

            inputRowMeta.addValueMeta(valueMeta);
        }
    } catch (Exception e) {

    }
}
 
Example 11
Source File: DataSet.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
/**
 * Get standard Kettle row metadata from the defined data set fields
 *
 * @param columnName true if you want the field names to be called after the columns, false if you prefer the field names in the result.
 * @return The row metadata
 * @throws KettlePluginException
 */
public RowMetaInterface getSetRowMeta( boolean columnName ) throws KettlePluginException {
  RowMetaInterface rowMeta = new RowMeta();
  for ( DataSetField field : getFields() ) {
    ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(
      columnName ? field.getColumnName() : field.getFieldName(),
      field.getType(),
      field.getLength(),
      field.getPrecision() );
    valueMeta.setComments( field.getComment() );
    valueMeta.setConversionMask( field.getFormat() );
    rowMeta.addValueMeta( valueMeta );
  }
  return rowMeta;
}
 
Example 12
Source File: CsvInputMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  try {
    rowMeta.clear(); // Start with a clean slate, eats the input

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

      ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( 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 =
        ValueMetaFactory.cloneValueMeta( valueMeta, 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 ( !Utils.isEmpty( filenameField ) && includingFilename ) {
      ValueMetaInterface filenameMeta = new ValueMetaString( filenameField );
      filenameMeta.setOrigin( origin );
      if ( lazyConversionActive ) {
        filenameMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
        filenameMeta.setStorageMetadata( new ValueMetaString( filenameField ) );
      }
      rowMeta.addValueMeta( filenameMeta );
    }

    if ( !Utils.isEmpty( rowNumField ) ) {
      ValueMetaInterface rowNumMeta = new ValueMetaInteger( rowNumField );
      rowNumMeta.setLength( 10 );
      rowNumMeta.setOrigin( origin );
      rowMeta.addValueMeta( rowNumMeta );
    }
  } catch ( Exception e ) {
    throw new KettleStepException( e );
  }

}
 
Example 13
Source File: ValueMetaBase.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Compare 2 values of the same data type
 *
 * @param data1
 *          the first value
 * @param meta2
 *          the second value's metadata
 * @param data2
 *          the second value
 * @return 0 if the values are equal, -1 if data1 is smaller than data2 and +1 if it's larger.
 * @throws KettleValueException
 *           In case we get conversion errors
 */
@Override
public int compare( Object data1, ValueMetaInterface meta2, Object data2 ) throws KettleValueException {
  if ( meta2 == null ) {
    throw new KettleValueException( toStringMeta()
        + " : Second meta data (meta2) is null, please check one of the previous steps." );
  }

  try {
    // Before we can compare data1 to data2 we need to make sure they have the
    // same data type etc.
    //
    if ( getType() == meta2.getType() ) {
      if ( getStorageType() == meta2.getStorageType() ) {
        return compare( data1, data2 );
      }

      // Convert the storage type to compare the data.
      //
      switch ( getStorageType() ) {
        case STORAGE_TYPE_NORMAL:
          return compare( data1, meta2.convertToNormalStorageType( data2 ) );
        case STORAGE_TYPE_BINARY_STRING:
          if ( storageMetadata != null && storageMetadata.getConversionMask() != null && !meta2.isNumber() ) {
            // BACKLOG-18754 - if there is a storage conversion mask, we should use
            // it as the mask for meta2 (meta2 can have specific storage type and type, so
            // it can't be used directly to convert data2 to binary string)
            ValueMetaInterface meta2StorageMask = meta2.clone();
            meta2StorageMask.setConversionMask( storageMetadata.getConversionMask() );
            return compare( data1, meta2StorageMask.convertToBinaryStringStorageType( data2 ) );
          } else {
            return compare( data1, meta2.convertToBinaryStringStorageType( data2 ) );
          }
        case STORAGE_TYPE_INDEXED:
          switch ( meta2.getStorageType() ) {
            case STORAGE_TYPE_INDEXED:
              return compare( data1, data2 ); // not accessible, just to make sure.
            case STORAGE_TYPE_NORMAL:
              return -meta2.compare( data2, convertToNormalStorageType( data1 ) );
            case STORAGE_TYPE_BINARY_STRING:
              return -meta2.compare( data2, convertToBinaryStringStorageType( data1 ) );
            default:
              throw new KettleValueException( meta2.toStringMeta() + " : Unknown storage type : "
                  + meta2.getStorageType() );

          }
        default:
          throw new KettleValueException( toStringMeta() + " : Unknown storage type : " + getStorageType() );
      }
    } else if ( ValueMetaInterface.TYPE_INTEGER == getType() && ValueMetaInterface.TYPE_NUMBER == meta2.getType() ) {
      // BACKLOG-18738
      // compare Double to Integer
      return -meta2.compare( data2, meta2.convertData( this, data1 ) );
    }

    // If the data types are not the same, the first one is the driver...
    // The second data type is converted to the first one.
    //
    return compare( data1, convertData( meta2, data2 ) );
  } catch ( Exception e ) {
    throw new KettleValueException(
        toStringMeta() + " : Unable to compare with value [" + meta2.toStringMeta() + "]", e );
  }
}
 
Example 14
Source File: JobHistoryDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private TableView createJobLogTableView( Composite parent ) {
  List<ColumnInfo> columnList = new ArrayList<ColumnInfo>();

  for ( LogTableField field : logTableFields ) {
    if ( !field.isLogField() ) {
      ColumnInfo column = new ColumnInfo( field.getName(), ColumnInfo.COLUMN_TYPE_TEXT, false, true );
      int valueType = field.getDataType();
      String conversionMask = null;

      switch ( field.getDataType() ) {
        case ValueMetaInterface.TYPE_INTEGER:
          conversionMask = "###,###,##0";
          column.setAllignement( SWT.RIGHT );
          break;
        case ValueMetaInterface.TYPE_DATE:
          conversionMask = "yyyy/MM/dd HH:mm:ss";
          column.setAllignement( SWT.CENTER );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          conversionMask = " ###,###,##0.00;-###,###,##0.00";
          column.setAllignement( SWT.RIGHT );
          break;
        case ValueMetaInterface.TYPE_STRING:
          column.setAllignement( SWT.LEFT );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          DatabaseMeta databaseMeta = logTable.getDatabaseMeta();
          if ( databaseMeta != null ) {
            if ( !databaseMeta.supportsBooleanDataType() ) {
              // Boolean gets converted to String!
              //
              valueType = ValueMetaInterface.TYPE_STRING;
            }
          }
          break;
        default:
          break;
      }

      ValueMetaInterface valueMeta = new ValueMeta( field.getFieldName(), valueType, field.getLength(), -1 );
      if ( conversionMask != null ) {
        valueMeta.setConversionMask( conversionMask );
      }
      column.setValueMeta( valueMeta );
      columnList.add( column );
    }
  }

  TableView tableView = new TableView( jobMeta, parent, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE,
    columnList.toArray( new ColumnInfo[columnList.size()] ), 1,
    true, // readonly!
    null,
    spoon.props );

  tableView.table.addSelectionListener( new SelectionAdapter() {
    @Override
    public void widgetSelected( SelectionEvent arg0 ) {
      showLogEntry();
    }
  } );

  return tableView;
}
 
Example 15
Source File: SelectValues.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Change the meta-data of certain fields.
 * <p/>
 * This, we can do VERY fast.
 * <p/>
 *
 * @param row The row to manipulate
 * @return the altered RowData array
 * @throws KettleValueException
 */
@VisibleForTesting
synchronized Object[] metadataValues( RowMetaInterface rowMeta, Object[] rowData ) throws KettleException {
  if ( data.firstmetadata ) {
    data.firstmetadata = false;

    data.metanrs = new int[ meta.getMeta().length ];
    for ( int i = 0; i < data.metanrs.length; i++ ) {
      data.metanrs[ i ] = rowMeta.indexOfValue( meta.getMeta()[ i ].getName() );
      if ( data.metanrs[ i ] < 0 ) {
        logError( BaseMessages
          .getString( PKG, "SelectValues.Log.CouldNotFindField", meta.getMeta()[ i ].getName() ) );
        setErrors( 1 );
        stopAll();
        return null;
      }
    }

    // Check for doubles in the selected fields...
    int[] cnt = new int[ meta.getMeta().length ];
    for ( int i = 0; i < meta.getMeta().length; i++ ) {
      cnt[ i ] = 0;
      for ( int j = 0; j < meta.getMeta().length; j++ ) {
        if ( meta.getMeta()[ i ].getName().equals( meta.getMeta()[ j ].getName() ) ) {
          cnt[ i ]++;
        }

        if ( cnt[ i ] > 1 ) {
          logError( BaseMessages.getString( PKG, "SelectValues.Log.FieldCouldNotSpecifiedMoreThanTwice2", meta
            .getMeta()[ i ].getName() ) );
          setErrors( 1 );
          stopAll();
          return null;
        }
      }
    }

    // Also apply the metadata on the row meta to allow us to convert the data correctly, with the correct mask.
    //
    for ( int i = 0; i < data.metanrs.length; i++ ) {
      SelectMetadataChange change = meta.getMeta()[ i ];
      ValueMetaInterface valueMeta = rowMeta.getValueMeta( data.metanrs[ i ] );
      if ( !Utils.isEmpty( change.getConversionMask() ) ) {
        valueMeta.setConversionMask( change.getConversionMask() );
      }

      valueMeta.setDateFormatLenient( change.isDateFormatLenient() );
      valueMeta.setDateFormatLocale( EnvUtil.createLocale( change.getDateFormatLocale() ) );
      valueMeta.setDateFormatTimeZone( EnvUtil.createTimeZone( change.getDateFormatTimeZone() ) );
      valueMeta.setLenientStringToNumber( change.isLenientStringToNumber() );

      if ( !Utils.isEmpty( change.getEncoding() ) ) {
        valueMeta.setStringEncoding( change.getEncoding() );
      }
      if ( !Utils.isEmpty( change.getDecimalSymbol() ) ) {
        valueMeta.setDecimalSymbol( change.getDecimalSymbol() );
      }
      if ( !Utils.isEmpty( change.getGroupingSymbol() ) ) {
        valueMeta.setGroupingSymbol( change.getGroupingSymbol() );
      }
      if ( !Utils.isEmpty( change.getCurrencySymbol() ) ) {
        valueMeta.setCurrencySymbol( change.getCurrencySymbol() );
      }
    }
  }

  //
  // Change the data too
  //
  for ( int i = 0; i < data.metanrs.length; i++ ) {
    int index = data.metanrs[ i ];
    ValueMetaInterface fromMeta = rowMeta.getValueMeta( index );
    ValueMetaInterface toMeta = data.metadataRowMeta.getValueMeta( index );

    // If we need to change from BINARY_STRING storage type to NORMAL...
    //
    try {
      if ( fromMeta.isStorageBinaryString()
        && meta.getMeta()[ i ].getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ) {
        rowData[ index ] = fromMeta.convertBinaryStringToNativeType( (byte[]) rowData[ index ] );
      }
      if ( meta.getMeta()[ i ].getType() != ValueMetaInterface.TYPE_NONE && fromMeta.getType() != toMeta.getType() ) {
        rowData[ index ] = toMeta.convertData( fromMeta, rowData[ index ] );
      }
    } catch ( KettleValueException e ) {
      throw new KettleConversionException( e.getMessage(), Collections.<Exception>singletonList( e ),
        Collections.singletonList( toMeta ), rowData );
    }
  }

  return rowData;
}
 
Example 16
Source File: KettleDatabaseRepositoryValueDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ValueMetaAndData loadValueMetaAndData( ObjectId id_value ) throws KettleException {
  ValueMetaAndData valueMetaAndData = new ValueMetaAndData();
  try {
    RowMetaAndData r = getValue( id_value );
    if ( r != null ) {
      String name = r.getString( KettleDatabaseRepository.FIELD_VALUE_NAME, null );
      int valtype = ValueMetaFactory.getIdForValueMeta(
        r.getString( KettleDatabaseRepository.FIELD_VALUE_VALUE_TYPE, null ) );
      boolean isNull = r.getBoolean( KettleDatabaseRepository.FIELD_VALUE_IS_NULL, false );
      ValueMetaInterface v = ValueMetaFactory.createValueMeta( name, valtype );
      valueMetaAndData.setValueMeta( v );

      if ( isNull ) {
        valueMetaAndData.setValueData( null );
      } else {
        ValueMetaInterface stringValueMeta = new ValueMetaString( name );
        ValueMetaInterface valueMeta = valueMetaAndData.getValueMeta();
        stringValueMeta.setConversionMetadata( valueMeta );

        valueMeta.setDecimalSymbol( ValueMetaAndData.VALUE_REPOSITORY_DECIMAL_SYMBOL );
        valueMeta.setGroupingSymbol( ValueMetaAndData.VALUE_REPOSITORY_GROUPING_SYMBOL );

        switch ( valueMeta.getType() ) {
          case ValueMetaInterface.TYPE_NUMBER:
            valueMeta.setConversionMask( ValueMetaAndData.VALUE_REPOSITORY_NUMBER_CONVERSION_MASK );
            break;
          case ValueMetaInterface.TYPE_INTEGER:
            valueMeta.setConversionMask( ValueMetaAndData.VALUE_REPOSITORY_INTEGER_CONVERSION_MASK );
            break;
          default:
            break;
        }

        String string = r.getString( "VALUE_STR", null );
        valueMetaAndData.setValueData( stringValueMeta.convertDataUsingConversionMetaData( string ) );

        // OK, now comes the dirty part...
        // We want the defaults back on there...
        //
        valueMeta = ValueMetaFactory.createValueMeta( name, valueMeta.getType() );
      }
    }

    return valueMetaAndData;
  } catch ( KettleException dbe ) {
    throw new KettleException( "Unable to load Value from repository with id_value=" + id_value, dbe );
  }
}
 
Example 17
Source File: GetVariableMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
    VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  // Determine the maximum length...
  //
  int length = -1;
  for ( int i = 0; i < fieldDefinitions.length; i++ ) {
    String variableString = fieldDefinitions[i].getVariableString();
    if ( variableString != null ) {
      String string = space.environmentSubstitute( variableString );
      if ( string.length() > length ) {
        length = string.length();
      }
    }
  }

  RowMetaInterface row = new RowMeta();
  for ( int i = 0; i < fieldDefinitions.length; i++ ) {
    ValueMetaInterface v;
    try {
      v = ValueMetaFactory.createValueMeta( fieldDefinitions[i].getFieldName(), fieldDefinitions[i].getFieldType() );
    } catch ( KettlePluginException e ) {
      throw new KettleStepException( e );
    }
    int fieldLength = fieldDefinitions[i].getFieldLength();
    if ( fieldLength < 0 ) {
      v.setLength( length );
    } else {
      v.setLength( fieldLength );
    }
    int fieldPrecision = fieldDefinitions[i].getFieldPrecision();
    if ( fieldPrecision >= 0 ) {
      v.setPrecision( fieldPrecision );
    }
    v.setConversionMask( fieldDefinitions[i].getFieldFormat() );
    v.setGroupingSymbol( fieldDefinitions[i].getGroup() );
    v.setDecimalSymbol( fieldDefinitions[i].getDecimal() );
    v.setCurrencySymbol( fieldDefinitions[i].getCurrency() );
    v.setTrimType( fieldDefinitions[i].getTrimType() );
    v.setOrigin( name );

    row.addValueMeta( v );
  }

  inputRowMeta.mergeRowMeta( row, name );
}
 
Example 18
Source File: FieldDefinition.java    From kettle-beam with Apache License 2.0 4 votes vote down vote up
public ValueMetaInterface getValueMeta() throws KettlePluginException {
  int type = ValueMetaFactory.getIdForValueMeta( kettleType );
  ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( name, type, length, precision );
  valueMeta.setConversionMask( formatMask );
  return valueMeta;
}
 
Example 19
Source File: TransHistoryDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private TableView createTransLogTableView( Composite parent ) {
  List<ColumnInfo> columnList = new ArrayList<ColumnInfo>();

  for ( LogTableField field : logTableFields ) {
    if ( !field.isLogField() ) {
      ColumnInfo column = new ColumnInfo( field.getName(), ColumnInfo.COLUMN_TYPE_TEXT, false, true );
      int valueType = field.getDataType();
      String conversionMask = null;

      switch ( field.getDataType() ) {
        case ValueMetaInterface.TYPE_INTEGER:
          conversionMask = "###,###,##0";
          column.setAllignement( SWT.RIGHT );
          break;
        case ValueMetaInterface.TYPE_DATE:
          conversionMask = "yyyy/MM/dd HH:mm:ss";
          column.setAllignement( SWT.CENTER );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          conversionMask = " ###,###,##0.00;-###,###,##0.00";
          column.setAllignement( SWT.RIGHT );
          break;
        case ValueMetaInterface.TYPE_STRING:
          column.setAllignement( SWT.LEFT );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          DatabaseMeta databaseMeta = logTable.getDatabaseMeta();
          if ( databaseMeta != null ) {
            if ( !databaseMeta.supportsBooleanDataType() ) {
              // Boolean gets converted to String!
              //
              valueType = ValueMetaInterface.TYPE_STRING;
            }
          }
          break;
        default:
          break;
      }

      ValueMetaInterface valueMeta = new ValueMeta( field.getFieldName(), valueType, field.getLength(), -1 );
      if ( conversionMask != null ) {
        valueMeta.setConversionMask( conversionMask );
      }
      column.setValueMeta( valueMeta );
      columnList.add( column );
    }
  }

  TableView tableView = new TableView( transMeta, parent, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE,
    columnList.toArray( new ColumnInfo[columnList.size()] ), 1,
    true, // readonly!
    null, spoon.props );

  tableView.table.addSelectionListener( new SelectionAdapter() {
    @Override
    public void widgetSelected( SelectionEvent arg0 ) {
      showLogEntry();
    }
  } );

  return tableView;
}
 
Example 20
Source File: IngresVectorwiseLoader.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 = (IngresVectorwiseLoaderMeta) smi;
  data = (IngresVectorwiseLoaderData) sdi;

  try {
    Object[] r = getRow(); // Get row from input rowset & set row busy!
    // no more input to be expected...
    if ( r == null ) {
      // only close output after the first row was processed
      // to prevent error (NPE) on empty rows set
      if ( !first ) {
        closeOutput();
      }

      if ( logWriter != null ) {
        logWriteThread.join();
        if ( logWriter.isErrorsOccured() ) {
          throw new SQLException( "The error was gotten from ingres sql process" );
        }
      }

      if ( vwLoadMonitorThread != null ) {
        vwLoadMonitorThread.join();
      }

      setOutputDone();
      return false;
    }

    if ( first ) {
      first = false;

      // Cache field indexes.
      //
      data.keynrs = new int[meta.getFieldStream().length];
      for ( int i = 0; i < data.keynrs.length; i++ ) {
        data.keynrs[i] = getInputRowMeta().indexOfValue( meta.getFieldStream()[i] );
      }
      data.bulkRowMeta = getInputRowMeta().clone();
      if ( meta.isUseStandardConversion() ) {
        for ( int i = 0; i < data.bulkRowMeta.size(); i++ ) {
          ValueMetaInterface valueMeta = data.bulkRowMeta.getValueMeta( i );
          if ( valueMeta.isStorageNormal() ) {
            if ( valueMeta.isDate() ) {
              valueMeta.setConversionMask( "yyyy-MM-dd HH:mm:ss" );
            } else if ( valueMeta.isNumeric() ) {
              valueMeta.setDecimalSymbol( "." );
              valueMeta.setGroupingSymbol( "" );
            }
          }
        }
      }

      // execute the client statement...
      //
      execute( meta );

      // Allocate a buffer
      //
      data.fileChannel = data.fifoOpener.getFileChannel();
      data.byteBuffer = ByteBuffer.allocate( data.bufferSize );
    }

    // check if SQL process is still running before processing row
    if ( !checkSqlProcessRunning( data.sqlProcess ) ) {
      throw new Exception( "Ingres SQL process has stopped" );
    }

    writeRowToBulk( data.bulkRowMeta, r );
    putRow( getInputRowMeta(), r );
    incrementLinesOutput();

    if ( checkFeedback( getLinesOutput() ) ) {
      logBasic( BaseMessages.getString( PKG, "IngresVectorwiseLoader.Log.LineNumber" ) + getLinesOutput() );
    }

    return true;

  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "IngresVectorwiseLoader.Log.ErrorInStep" ), e );
    setErrors( 1 );
    stopAll();
    setOutputDone(); // signal end to receiver(s)
    return false;
  }
}