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

The following examples show how to use org.pentaho.di.core.row.ValueMetaInterface#setPrecision() . 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: 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 2
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 3
Source File: CombinationLookupMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
                       VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  ValueMetaInterface v = new ValueMetaInteger( technicalKeyField );
  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 );
      }
    }
  }
}
 
Example 4
Source File: EnterValueDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private ValueMetaAndData getValue( String valuename ) throws KettleValueException {
  try {
    int valtype = ValueMetaFactory.getIdForValueMeta( wValueType.getText() );
    ValueMetaAndData val = new ValueMetaAndData( valuename, wInputString.getText() );

    ValueMetaInterface valueMeta = ValueMetaFactory.cloneValueMeta( val.getValueMeta(), valtype );
    Object valueData = val.getValueData();

    int formatIndex = wFormat.getSelectionIndex();
    valueMeta.setConversionMask( formatIndex >= 0 ? wFormat.getItem( formatIndex ) : wFormat.getText() );
    valueMeta.setLength( Const.toInt( wLength.getText(), -1 ) );
    valueMeta.setPrecision( Const.toInt( wPrecision.getText(), -1 ) );
    val.setValueMeta( valueMeta );

    ValueMetaInterface stringValueMeta = new ValueMetaString( valuename );
    stringValueMeta.setConversionMetadata( valueMeta );

    Object targetData = stringValueMeta.convertDataUsingConversionMetaData( valueData );
    val.setValueData( targetData );

    return val;
  } catch ( Exception e ) {
    throw new KettleValueException( e );
  }
}
 
Example 5
Source File: CalculatorMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private ValueMetaInterface getValueMeta( CalculatorMetaFunction fn, String origin ) {
  ValueMetaInterface v;
  // What if the user didn't specify a data type?
  // In that case we look for the default data type
  //
  int defaultResultType = fn.getValueType();
  if ( defaultResultType == ValueMetaInterface.TYPE_NONE ) {
    defaultResultType = CalculatorMetaFunction.getCalcFunctionDefaultResultType( fn.getCalcType() );
  }
  try {
    v = ValueMetaFactory.createValueMeta( fn.getFieldName(), defaultResultType );
  } catch ( Exception ex ) {
    return null;
  }
  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;
}
 
Example 6
Source File: DataGridMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
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++ ) {
    try {
      if ( !Utils.isEmpty( fieldName[i] ) ) {
        int type = ValueMetaFactory.getIdForValueMeta( fieldType[i] );
        if ( type == ValueMetaInterface.TYPE_NONE ) {
          type = ValueMetaInterface.TYPE_STRING;
        }
        ValueMetaInterface v = ValueMetaFactory.createValueMeta( fieldName[i], type );
        v.setLength( fieldLength[i] );
        v.setPrecision( fieldPrecision[i] );
        v.setOrigin( name );
        v.setConversionMask( fieldFormat[i] );
        v.setCurrencySymbol( currency[i] );
        v.setGroupingSymbol( group[i] );
        v.setDecimalSymbol( decimal[i] );

        rowMeta.addValueMeta( v );
      }
    } catch ( Exception e ) {
      throw new KettleStepException( "Unable to create value of type " + fieldType[i], e );
    }
  }
}
 
Example 7
Source File: TransformClassBase.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings( "unchecked" )
public static void getFields( boolean clearResultFields, RowMetaInterface row, String originStepname,
  RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, List<?> fields ) throws KettleStepException {
  if ( clearResultFields ) {
    row.clear();
  }
  for ( FieldInfo fi : (List<FieldInfo>) fields ) {
    try {
      ValueMetaInterface v = ValueMetaFactory.createValueMeta( fi.name, fi.type );
      v.setLength( fi.length );
      v.setPrecision( fi.precision );
      v.setOrigin( originStepname );
      row.addValueMeta( v );
    } catch ( Exception e ) {
      throw new KettleStepException( e );
    }
  }
}
 
Example 8
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 9
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 10
Source File: FixedInputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  try {
    for ( int i = 0; i < fieldDefinition.length; i++ ) {
      FixedFileInputField field = fieldDefinition[i];

      ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( field.getName(), field.getType() );
      valueMeta.setConversionMask( field.getFormat() );
      valueMeta.setTrimType( field.getTrimType() );
      valueMeta.setLength( field.getLength() );
      valueMeta.setPrecision( field.getPrecision() );
      valueMeta.setConversionMask( field.getFormat() );
      valueMeta.setDecimalSymbol( field.getDecimal() );
      valueMeta.setGroupingSymbol( field.getGrouping() );
      valueMeta.setCurrencySymbol( field.getCurrency() );
      valueMeta.setStringEncoding( space.environmentSubstitute( encoding ) );
      if ( lazyConversionActive ) {
        valueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING );
      }

      // In case we want to convert Strings...
      //
      ValueMetaInterface storageMetadata =
        ValueMetaFactory.cloneValueMeta( valueMeta, ValueMetaInterface.TYPE_STRING );
      storageMetadata.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );

      valueMeta.setStorageMetadata( storageMetadata );

      valueMeta.setOrigin( origin );

      rowMeta.addValueMeta( valueMeta );
    }
  } catch ( Exception e ) {
    throw new KettleStepException( e );
  }
}
 
Example 11
Source File: ScriptValuesMetaMod.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getFields( RowMetaInterface row, String originStepname, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  try {
    for ( int i = 0; i < fieldname.length; i++ ) {
      if ( !Utils.isEmpty( fieldname[i] ) ) {
        int valueIndex = -1;
        ValueMetaInterface v;
        if ( replace[i] ) {
          valueIndex = row.indexOfValue( fieldname[i] );
          if ( valueIndex < 0 ) {
            // The field was not found using the "name" field
            if ( Utils.isEmpty( rename[i] ) ) {
              // There is no "rename" field to try; Therefore we cannot find the
              // field to replace
              throw new KettleStepException( BaseMessages.getString(
                PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", fieldname[i] ) );
            } else {
              // Lookup the field to replace using the "rename" field
              valueIndex = row.indexOfValue( rename[i] );
              if ( valueIndex < 0 ) {
                // The field was not found using the "rename" field"; Therefore
                // we cannot find the field to replace
                //
                throw new KettleStepException( BaseMessages.getString(
                  PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", rename[i] ) );
              }
            }
          }

          // Change the data type to match what's specified...
          //
          ValueMetaInterface source = row.getValueMeta( valueIndex );
          v = ValueMetaFactory.cloneValueMeta( source, type[i] );
          row.setValueMeta( valueIndex, v );
        } else {
          if ( !Utils.isEmpty( rename[i] ) ) {
            v = ValueMetaFactory.createValueMeta( rename[i], type[i] );
          } else {
            v = ValueMetaFactory.createValueMeta( fieldname[i], type[i] );
          }
        }
        v.setLength( length[i] );
        v.setPrecision( precision[i] );
        v.setOrigin( originStepname );
        if ( !replace[i] ) {
          row.addValueMeta( v );
        }
      }
    }
  } catch ( KettleException e ) {
    throw new KettleStepException( e );
  }
}
 
Example 12
Source File: SelectValuesMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ) throws KettlePluginException {
  if ( meta != null && meta.length > 0 ) {
    // METADATA mode: change the meta-data of the values mentioned...

    for ( int i = 0; i < meta.length; i++ ) {
      SelectMetadataChange metaChange = meta[i];

      int idx = inputRowMeta.indexOfValue( metaChange.getName() );
      boolean metaTypeChangeUsesNewTypeDefaults = false; // Normal behavior as of 5.x or so
      if ( space != null ) {
        metaTypeChangeUsesNewTypeDefaults = ValueMetaBase.convertStringToBoolean(
            space.getVariable( Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "N" ) );
      }
      if ( idx >= 0 ) { // We found the value

        // This is the value we need to change:
        ValueMetaInterface v = inputRowMeta.getValueMeta( idx );

        // Do we need to rename ?
        if ( !v.getName().equals( metaChange.getRename() ) && !Utils.isEmpty( metaChange.getRename() ) ) {
          v.setName( metaChange.getRename() );
          v.setOrigin( name );
          // need to reinsert to check name conflicts
          inputRowMeta.setValueMeta( idx, v );
        }
        // Change the type?
        if ( metaChange.getType() != ValueMetaInterface.TYPE_NONE && v.getType() != metaChange.getType() ) {
          // Fix for PDI-16388 - clone copies over the conversion mask instead of using the default for the new type
          if ( !metaTypeChangeUsesNewTypeDefaults ) {
            v = ValueMetaFactory.cloneValueMeta( v, metaChange.getType() );
          } else {
            v = ValueMetaFactory.createValueMeta( v.getName(), metaChange.getType() );
          }

          // This is now a copy, replace it in the row!
          //
          inputRowMeta.setValueMeta( idx, v );

          // This also moves the data to normal storage type
          //
          v.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
        }
        if ( metaChange.getLength() != UNDEFINED ) {
          v.setLength( metaChange.getLength() );
          v.setOrigin( name );
        }
        if ( metaChange.getPrecision() != UNDEFINED ) {
          v.setPrecision( metaChange.getPrecision() );
          v.setOrigin( name );
        }
        if ( metaChange.getStorageType() >= 0 ) {
          v.setStorageType( metaChange.getStorageType() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getConversionMask() ) ) {
          v.setConversionMask( metaChange.getConversionMask() );
          v.setOrigin( name );
        }

        v.setDateFormatLenient( metaChange.isDateFormatLenient() );
        v.setDateFormatLocale( EnvUtil.createLocale( metaChange.getDateFormatLocale() ) );
        v.setDateFormatTimeZone( EnvUtil.createTimeZone( metaChange.getDateFormatTimeZone() ) );
        v.setLenientStringToNumber( metaChange.isLenientStringToNumber() );

        if ( !Utils.isEmpty( metaChange.getEncoding() ) ) {
          v.setStringEncoding( metaChange.getEncoding() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getDecimalSymbol() ) ) {
          v.setDecimalSymbol( metaChange.getDecimalSymbol() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getGroupingSymbol() ) ) {
          v.setGroupingSymbol( metaChange.getGroupingSymbol() );
          v.setOrigin( name );
        }
        if ( !Utils.isEmpty( metaChange.getCurrencySymbol() ) ) {
          v.setCurrencySymbol( metaChange.getCurrencySymbol() );
          v.setOrigin( name );
        }
      }
    }
  }
}
 
Example 13
Source File: GetFileNamesMeta.java    From pentaho-kettle with Apache License 2.0 4 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 {

  // the filename
  ValueMetaInterface filename = new ValueMetaString( "filename" );
  filename.setLength( 500 );
  filename.setPrecision( -1 );
  filename.setOrigin( name );
  row.addValueMeta( filename );

  // the short filename
  ValueMetaInterface short_filename = new ValueMetaString( "short_filename" );
  short_filename.setLength( 500 );
  short_filename.setPrecision( -1 );
  short_filename.setOrigin( name );
  row.addValueMeta( short_filename );

  // the path
  ValueMetaInterface path = new ValueMetaString( "path" );
  path.setLength( 500 );
  path.setPrecision( -1 );
  path.setOrigin( name );
  row.addValueMeta( path );

  // the type
  ValueMetaInterface type = new ValueMetaString( "type" );
  type.setLength( 500 );
  type.setPrecision( -1 );
  type.setOrigin( name );
  row.addValueMeta( type );

  // the exists
  ValueMetaInterface exists = new ValueMetaBoolean( "exists" );
  exists.setOrigin( name );
  row.addValueMeta( exists );

  // the ishidden
  ValueMetaInterface ishidden = new ValueMetaBoolean( "ishidden" );
  ishidden.setOrigin( name );
  row.addValueMeta( ishidden );

  // the isreadable
  ValueMetaInterface isreadable = new ValueMetaBoolean( "isreadable" );
  isreadable.setOrigin( name );
  row.addValueMeta( isreadable );

  // the iswriteable
  ValueMetaInterface iswriteable = new ValueMetaBoolean( "iswriteable" );
  iswriteable.setOrigin( name );
  row.addValueMeta( iswriteable );

  // the lastmodifiedtime
  ValueMetaInterface lastmodifiedtime = new ValueMetaDate( "lastmodifiedtime" );
  lastmodifiedtime.setOrigin( name );
  row.addValueMeta( lastmodifiedtime );

  // the size
  ValueMetaInterface size = new ValueMetaInteger( "size" );
  size.setOrigin( name );
  row.addValueMeta( size );

  // the extension
  ValueMetaInterface extension = new ValueMetaString( "extension" );
  extension.setOrigin( name );
  row.addValueMeta( extension );

  // the uri
  ValueMetaInterface uri = new ValueMetaString( "uri" );
  uri.setOrigin( name );
  row.addValueMeta( uri );

  // the rooturi
  ValueMetaInterface rooturi = new ValueMetaString( "rooturi" );
  rooturi.setOrigin( name );
  row.addValueMeta( rooturi );

  if ( includeRowNumber ) {
    ValueMetaInterface v = new ValueMetaInteger( space.environmentSubstitute( rowNumberField ) );
    v.setLength( ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0 );
    v.setOrigin( name );
    row.addValueMeta( v );
  }

}
 
Example 14
Source File: S3CsvInputMeta.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 {
  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 );
    }

    // 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 ( !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 );
  }
}
 
Example 15
Source File: GetRepositoryNamesMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  // the directory and name of the object
  //
  ValueMetaInterface object = new ValueMetaString( "object" );
  object.setLength( 500 );
  object.setPrecision( -1 );
  object.setOrigin( origin );
  row.addValueMeta( object );

  // the directory
  //
  ValueMetaInterface directory = new ValueMetaString( "directory" );
  directory.setLength( 500 );
  directory.setPrecision( -1 );
  directory.setOrigin( origin );
  row.addValueMeta( directory );

  // the name
  //
  ValueMetaInterface name = new ValueMetaString( "name" );
  name.setLength( 500 );
  name.setPrecision( -1 );
  name.setOrigin( origin );
  row.addValueMeta( name );

  // the object type
  //
  ValueMetaInterface objectType = new ValueMetaString( "object_type" );
  objectType.setLength( 500 );
  objectType.setPrecision( -1 );
  objectType.setOrigin( origin );
  row.addValueMeta( objectType );

  // object_id
  //
  ValueMetaInterface objectId = new ValueMetaString( "object_id" );
  object.setLength( 500 );
  object.setPrecision( -1 );
  objectId.setOrigin( origin );
  row.addValueMeta( objectId );

  // modified by
  //
  ValueMetaInterface modifiedBy = new ValueMetaString( "modified_by" );
  object.setLength( 500 );
  object.setPrecision( -1 );
  modifiedBy.setOrigin( origin );
  row.addValueMeta( modifiedBy );

  // modified date
  //
  ValueMetaInterface modifiedDate = new ValueMetaDate( "modified_date" );
  modifiedDate.setOrigin( origin );
  row.addValueMeta( modifiedDate );

  // description
  //
  ValueMetaInterface description = new ValueMetaString( "description" );
  description.setLength( 500 );
  description.setPrecision( -1 );
  description.setOrigin( origin );
  row.addValueMeta( description );

  if ( includeRowNumber ) {
    ValueMetaInterface v = new ValueMetaInteger( space.environmentSubstitute( rowNumberField ) );
    v.setLength( ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0 );
    v.setOrigin( origin );
    row.addValueMeta( v );
  }

}
 
Example 16
Source File: ParGzipCsvInputMeta.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 17
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 18
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 19
Source File: ScriptMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getFields( RowMetaInterface row, String originStepname, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  for ( int i = 0; i < fieldname.length; i++ ) {
    if ( !Utils.isEmpty( fieldname[i] ) ) {
      String fieldName;
      int replaceIndex;
      int fieldType;

      if ( replace[i] ) {
        // Look up the field to replace...
        //
        if ( row.searchValueMeta( fieldname[i] ) == null && Utils.isEmpty( rename[i] ) ) {
          throw new KettleStepException( BaseMessages.getString(
            PKG, "ScriptMeta.Exception.FieldToReplaceNotFound", fieldname[i] ) );
        }
        replaceIndex = row.indexOfValue( rename[i] );

        // Change the data type to match what's specified...
        //
        fieldType = type[i];
        fieldName = rename[i];
      } else {
        replaceIndex = -1;
        fieldType = type[i];
        if ( rename[i] != null && rename[i].length() != 0 ) {
          fieldName = rename[i];
        } else {
          fieldName = fieldname[i];
        }
      }
      try {
        ValueMetaInterface v = ValueMetaFactory.createValueMeta( fieldName, fieldType );
        v.setLength( length[i] );
        v.setPrecision( precision[i] );
        v.setOrigin( originStepname );
        if ( replace[i] && replaceIndex >= 0 ) {
          row.setValueMeta( replaceIndex, v );
        } else {
          row.addValueMeta( v );
        }
      } catch ( KettlePluginException e ) {
        // Ignore errors
      }
    }
  }
}
 
Example 20
Source File: GetSubFoldersMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  // the folderName
  ValueMetaInterface folderName = new ValueMetaString( "folderName" );
  folderName.setLength( 500 );
  folderName.setPrecision( -1 );
  folderName.setOrigin( name );
  row.addValueMeta( folderName );

  // the short folderName
  ValueMetaInterface short_folderName = new ValueMetaString( "short_folderName" );
  short_folderName.setLength( 500 );
  short_folderName.setPrecision( -1 );
  short_folderName.setOrigin( name );
  row.addValueMeta( short_folderName );

  // the path
  ValueMetaInterface path = new ValueMetaString( "path" );
  path.setLength( 500 );
  path.setPrecision( -1 );
  path.setOrigin( name );
  row.addValueMeta( path );

  // the ishidden
  ValueMetaInterface ishidden = new ValueMetaBoolean( "ishidden" );
  ishidden.setOrigin( name );
  row.addValueMeta( ishidden );

  // the isreadable
  ValueMetaInterface isreadable = new ValueMetaBoolean( "isreadable" );
  isreadable.setOrigin( name );
  row.addValueMeta( isreadable );

  // the iswriteable
  ValueMetaInterface iswriteable = new ValueMetaBoolean( "iswriteable" );
  iswriteable.setOrigin( name );
  row.addValueMeta( iswriteable );

  // the lastmodifiedtime
  ValueMetaInterface lastmodifiedtime = new ValueMetaDate( "lastmodifiedtime" );
  lastmodifiedtime.setOrigin( name );
  row.addValueMeta( lastmodifiedtime );

  // the uri
  ValueMetaInterface uri = new ValueMetaString( "uri" );
  uri.setOrigin( name );
  row.addValueMeta( uri );

  // the rooturi
  ValueMetaInterface rooturi = new ValueMetaString( "rooturi" );
  rooturi.setOrigin( name );
  row.addValueMeta( rooturi );

  // childrens
  ValueMetaInterface childrens =
    new ValueMetaInteger( space.environmentSubstitute( "childrens" ) );
  childrens.setLength( ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0 );
  childrens.setOrigin( name );
  row.addValueMeta( childrens );

  if ( includeRowNumber ) {
    ValueMetaInterface v = new ValueMetaInteger( space.environmentSubstitute( rowNumberField ) );
    v.setLength( ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0 );
    v.setOrigin( name );
    row.addValueMeta( v );
  }

}