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

The following examples show how to use org.pentaho.di.core.row.ValueMetaInterface#setLength() . 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: 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 2
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 3
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 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: ValueMetaInternetAddress.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public ValueMetaInterface getMetadataPreview( DatabaseMeta databaseMeta, ResultSet rs )
  throws KettleDatabaseException {

  try {
    if ( "INET".equalsIgnoreCase( rs.getString( "TYPE_NAME" ) ) ) {
      ValueMetaInterface vmi = super.getMetadataPreview( databaseMeta, rs );
      ValueMetaInterface valueMeta = new ValueMetaInternetAddress( name );
      valueMeta.setLength( vmi.getLength() );
      valueMeta.setOriginalColumnType( vmi.getOriginalColumnType() );
      valueMeta.setOriginalColumnTypeName( vmi.getOriginalColumnTypeName() );
      valueMeta.setOriginalNullable( vmi.getOriginalNullable() );
      valueMeta.setOriginalPrecision( vmi.getOriginalPrecision() );
      valueMeta.setOriginalScale( vmi.getOriginalScale() );
      valueMeta.setOriginalSigned( vmi.getOriginalSigned() );
      return valueMeta;
    }
  } catch ( SQLException e ) {
    throw new KettleDatabaseException( e );
  }
  return null;
}
 
Example 6
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 7
Source File: UniqueRowsMeta.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 {
  // change the case insensitive flag too
  for ( int i = 0; i < compareFields.length; i++ ) {
    int idx = row.indexOfValue( compareFields[i] );
    if ( idx >= 0 ) {
      row.getValueMeta( idx ).setCaseInsensitive( caseInsensitive[i] );
    }
  }
  if ( countRows ) {
    ValueMetaInterface v = new ValueMetaInteger( countField );
    v.setLength( ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0 );
    v.setOrigin( name );
    row.addValueMeta( v );
  }
}
 
Example 8
Source File: FieldsChangeSequenceMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) {
  if ( !Utils.isEmpty( resultfieldName ) ) {
    ValueMetaInterface v = new ValueMetaInteger( resultfieldName );
    v.setLength( ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0 );
    v.setOrigin( name );
    r.addValueMeta( v );
  }
}
 
Example 9
Source File: ValueMetaTimestamp.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public ValueMetaInterface getValueFromSQLType( DatabaseMeta databaseMeta, String name, ResultSetMetaData rm,
                                               int index, boolean ignoreLength, boolean lazyConversion )
  throws KettleDatabaseException {

  try {
    int type = rm.getColumnType( index );
    if ( type == java.sql.Types.TIMESTAMP ) {
      int length = rm.getScale( index );
      ValueMetaInterface valueMeta;
      if ( databaseMeta.supportsTimestampDataType() ) {
        valueMeta = new ValueMetaTimestamp( name );
      } else {
        valueMeta = new ValueMetaDate( name );
      }
      valueMeta.setLength( length );

      // Also get original column details, comment, etc.
      //
      getOriginalColumnMetadata( valueMeta, rm, index, ignoreLength );

      return valueMeta;
    }

    return null;
  } catch ( Exception e ) {
    throw new KettleDatabaseException( "Error evaluating timestamp value metadata", e );
  }
}
 
Example 10
Source File: JobGenerator.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private ValueMetaInterface getValueForLogicalColumn(DatabaseMeta databaseMeta, LogicalColumn column) {
  String columnName = ConceptUtil.getName(column, locale);
  String phColumnName = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME);
  DataType columnType = column.getDataType();
  String lengthString = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_LENGTH);
  int length = Const.toInt(lengthString, -1);
  String precisionString = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PRECISION);
  int precision = Const.toInt(precisionString, -1);

  int type=ValueMetaInterface.TYPE_STRING;
  switch(columnType) {
  case UNKNOWN:
  case URL:
  case STRING: precision=-1; break;
  case IMAGE:
  case BINARY: type = ValueMetaInterface.TYPE_BINARY; precision=-1; break;
  case BOOLEAN: type = ValueMetaInterface.TYPE_BOOLEAN; length=-1; precision=-1; break;
  case DATE: type = ValueMetaInterface.TYPE_DATE; length=-1; precision=-1; break;
  case NUMERIC:
    if (precision<=0 && length<15) {
      type = ValueMetaInterface.TYPE_INTEGER;
    } else {
      if (length>=15) {
        type = ValueMetaInterface.TYPE_BIGNUMBER;
      } else {
        type = ValueMetaInterface.TYPE_NUMBER;
      }
    }
    break;
    default:
      break;
  }
  ValueMetaInterface value = new ValueMeta(databaseMeta.quoteField(Const.NVL(phColumnName, columnName)), type);
  value.setLength(length, precision);
  return value;
}
 
Example 11
Source File: TextFileOutputMeta.java    From pentaho-kettle with Apache License 2.0 5 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 {
  // No values are added to the row in this type of step
  // However, in case of Fixed length records,
  // the field precisions and lengths are altered!

  for ( int i = 0; i < outputFields.length; i++ ) {
    TextFileField field = outputFields[i];
    ValueMetaInterface v = row.searchValueMeta( field.getName() );
    if ( v != null ) {
      v.setLength( field.getLength() );
      v.setPrecision( field.getPrecision() );
      if ( field.getFormat() != null ) {
        v.setConversionMask( field.getFormat() );
      }
      v.setDecimalSymbol( field.getDecimalSymbol() );
      v.setGroupingSymbol( field.getGroupingSymbol() );
      v.setCurrencySymbol( field.getCurrencySymbol() );
      v.setOutputPaddingEnabled( isPadded() );
      v.setTrimType( field.getTrimType() );
      if ( !Utils.isEmpty( getEncoding() ) ) {
        v.setStringEncoding( getEncoding() );
      }

      // enable output padding by default to be compatible with v2.5.x
      //
      v.setOutputPaddingEnabled( true );
    }
  }
}
 
Example 12
Source File: SalesforceUpsertMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  String realfieldname = space.environmentSubstitute( getSalesforceIDFieldName() );
  if ( !Utils.isEmpty( realfieldname ) ) {
    ValueMetaInterface v = new ValueMetaString( realfieldname );
    v.setLength( 18 );
    v.setOrigin( name );
    r.addValueMeta( v );
  }
}
 
Example 13
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 14
Source File: ValueMetaFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ) throws KettlePluginException {
  PluginInterface stringPlugin = pluginRegistry.getPlugin( ValueMetaPluginType.class, String.valueOf( type ) );
  if ( stringPlugin == null ) {
    throw new KettlePluginException( "Unable to locate value meta plugin of type (id) " + type );
  }
  ValueMetaInterface valueMeta = pluginRegistry.loadClass( stringPlugin, ValueMetaInterface.class );
  valueMeta.setName( name );
  valueMeta.setLength( length, precision );
  return valueMeta;
}
 
Example 15
Source File: MySQLDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc,
                                            boolean addFieldName, boolean addCr ) {
  String retval = "";

  String fieldname = v.getName();
  if ( v.getLength() == DatabaseMeta.CLOB_LENGTH ) {
    v.setLength( getMaxTextFieldLength() );
  }
  int length = v.getLength();
  int precision = v.getPrecision();

  if ( addFieldName ) {
    retval += fieldname + " ";
  }

  int type = v.getType();
  switch ( type ) {
    case ValueMetaInterface.TYPE_TIMESTAMP:
    case ValueMetaInterface.TYPE_DATE:
      retval += "DATETIME";
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      if ( supportsBooleanDataType() ) {
        retval += "BOOLEAN";
      } else {
        retval += "CHAR(1)";
      }
      break;

    case ValueMetaInterface.TYPE_NUMBER:
    case ValueMetaInterface.TYPE_INTEGER:
    case ValueMetaInterface.TYPE_BIGNUMBER:
      if ( fieldname.equalsIgnoreCase( tk ) || // Technical key
        fieldname.equalsIgnoreCase( pk ) // Primary key
      ) {
        if ( useAutoinc ) {
          retval += "BIGINT AUTO_INCREMENT NOT NULL PRIMARY KEY";
        } else {
          retval += "BIGINT NOT NULL PRIMARY KEY";
        }
      } else {
        // Integer values...
        if ( precision == 0 ) {
          if ( length > 9 ) {
            if ( length < 19 ) {
              // can hold signed values between -9223372036854775808 and 9223372036854775807
              // 18 significant digits
              retval += "BIGINT";
            } else {
              retval += "DECIMAL(" + length + ")";
            }
          } else {
            retval += "INT";
          }
        } else {
          // Floating point values...
          if ( length > 15 ) {
            retval += "DECIMAL(" + length;
            if ( precision > 0 ) {
              retval += ", " + precision;
            }
            retval += ")";
          } else {
            // A double-precision floating-point number is accurate to approximately 15 decimal places.
            // http://mysql.mirrors-r-us.net/doc/refman/5.1/en/numeric-type-overview.html
            retval += "DOUBLE";
          }
        }
      }
      break;
    case ValueMetaInterface.TYPE_STRING:
      if ( length > 0 ) {
        if ( length == 1 ) {
          retval += "CHAR(1)";
        } else if ( length < 256 ) {
          retval += "VARCHAR(" + length + ")";
        } else if ( length < 65536 ) {
          retval += "TEXT";
        } else if ( length < 16777216 ) {
          retval += "MEDIUMTEXT";
        } else {
          retval += "LONGTEXT";
        }
      } else {
        retval += "TINYTEXT";
      }
      break;
    case ValueMetaInterface.TYPE_BINARY:
      retval += "LONGBLOB";
      break;
    default:
      retval += " UNKNOWN";
      break;
  }

  if ( addCr ) {
    retval += Const.CR;
  }

  return retval;
}
 
Example 16
Source File: NormaliserMeta.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 {

  // Get a unique list of the occurrences of the type
  //
  List<String> norm_occ = new ArrayList<>();
  List<String> field_occ = new ArrayList<>();
  int maxlen = 0;
  for ( int i = 0; i < normaliserFields.length; i++ ) {
    if ( !norm_occ.contains( normaliserFields[i].getNorm() ) ) {
      norm_occ.add( normaliserFields[i].getNorm() );
      field_occ.add( normaliserFields[i].getName() );
    }

    if ( normaliserFields[i].getValue().length() > maxlen ) {
      maxlen = normaliserFields[i].getValue().length();
    }
  }

  // Then add the type field!
  //
  ValueMetaInterface typefield_value = new ValueMetaString( typeField );
  typefield_value.setOrigin( name );
  typefield_value.setLength( maxlen );
  row.addValueMeta( typefield_value );

  // Loop over the distinct list of fieldNorm[i]
  // Add the new fields that need to be created.
  // Use the same data type as the original fieldname...
  //
  for ( int i = 0; i < norm_occ.size(); i++ ) {
    String normname = norm_occ.get( i );
    String fieldname = field_occ.get( i );
    ValueMetaInterface v = row.searchValueMeta( fieldname );
    if ( v != null ) {
      v = v.clone();
    } else {
      throw new KettleStepException( BaseMessages.getString( PKG, "NormaliserMeta.Exception.UnableToFindField", fieldname ) );
    }
    v.setName( normname );
    v.setOrigin( name );
    row.addValueMeta( v );
  }

  // Now remove all the normalized fields...
  //
  for ( int i = 0; i < normaliserFields.length; i++ ) {
    int idx = row.indexOfValue( normaliserFields[i].getName() );
    if ( idx >= 0 ) {
      row.removeValueMeta( idx );
    }
  }
}
 
Example 17
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 18
Source File: TableCompareMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void getFields( RowMetaInterface inputRowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  if ( Utils.isEmpty( nrErrorsField ) ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "TableCompareMeta.Exception.NrErrorsFieldIsNotSpecified" ) );
  }
  if ( Utils.isEmpty( nrRecordsReferenceField ) ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "TableCompareMeta.Exception.NrRecordsReferenceFieldNotSpecified" ) );
  }
  if ( Utils.isEmpty( nrRecordsCompareField ) ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "TableCompareMeta.Exception.NrRecordsCompareFieldNotSpecified" ) );
  }
  if ( Utils.isEmpty( nrErrorsLeftJoinField ) ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "TableCompareMeta.Exception.NrErrorsLeftJoinFieldNotSpecified" ) );
  }
  if ( Utils.isEmpty( nrErrorsInnerJoinField ) ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "TableCompareMeta.Exception.NrErrorsInnerJoinFieldNotSpecified" ) );
  }
  if ( Utils.isEmpty( nrErrorsRightJoinField ) ) {
    throw new KettleStepException( BaseMessages.getString(
      PKG, "TableCompareMeta.Exception.NrErrorsRightJoinFieldNotSpecified" ) );
  }

  ValueMetaInterface nrErrorsValueMeta = new ValueMetaInteger( nrErrorsField );
  nrErrorsValueMeta.setLength( 9 );
  nrErrorsValueMeta.setOrigin( origin );
  inputRowMeta.addValueMeta( nrErrorsValueMeta );

  ValueMetaInterface nrRecordsReference =
    new ValueMetaInteger( nrRecordsReferenceField );
  nrRecordsReference.setLength( 9 );
  nrRecordsReference.setOrigin( origin );
  inputRowMeta.addValueMeta( nrRecordsReference );

  ValueMetaInterface nrRecordsCompare = new ValueMetaInteger( nrRecordsCompareField );
  nrRecordsCompare.setLength( 9 );
  nrRecordsCompare.setOrigin( origin );
  inputRowMeta.addValueMeta( nrRecordsCompare );

  ValueMetaInterface nrErrorsLeft = new ValueMetaInteger( nrErrorsLeftJoinField );
  nrErrorsLeft.setLength( 9 );
  nrErrorsLeft.setOrigin( origin );
  inputRowMeta.addValueMeta( nrErrorsLeft );

  ValueMetaInterface nrErrorsInner = new ValueMetaInteger( nrErrorsInnerJoinField );
  nrErrorsInner.setLength( 9 );
  nrErrorsInner.setOrigin( origin );
  inputRowMeta.addValueMeta( nrErrorsInner );

  ValueMetaInterface nrErrorsRight = new ValueMetaInteger( nrErrorsRightJoinField );
  nrErrorsRight.setLength( 9 );
  nrErrorsRight.setOrigin( origin );
  inputRowMeta.addValueMeta( nrErrorsRight );
}
 
Example 19
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 20
Source File: PostgreSQLDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public String getFieldDefinition( ValueMetaInterface v, String tk, String pk, boolean useAutoinc,
                                  boolean addFieldName, boolean addCr ) {
  String retval = "";

  String fieldname = v.getName();
  if ( v.getLength() == DatabaseMeta.CLOB_LENGTH ) {
    v.setLength( getMaxTextFieldLength() );
  }
  int length = v.getLength();
  int precision = v.getPrecision();

  if ( addFieldName ) {
    retval += fieldname + " ";
  }

  int type = v.getType();
  switch ( type ) {
    case ValueMetaInterface.TYPE_TIMESTAMP:
    case ValueMetaInterface.TYPE_DATE:
      retval += "TIMESTAMP";
      break;
    case ValueMetaInterface.TYPE_BOOLEAN:
      if ( supportsBooleanDataType() ) {
        retval += "BOOLEAN";
      } else {
        retval += "CHAR(1)";
      }
      break;
    case ValueMetaInterface.TYPE_NUMBER:
    case ValueMetaInterface.TYPE_INTEGER:
    case ValueMetaInterface.TYPE_BIGNUMBER:
      if ( fieldname.equalsIgnoreCase( tk ) || // Technical key
          fieldname.equalsIgnoreCase( pk ) // Primary key
      ) {
        retval += "BIGSERIAL";
      } else {
        if ( length > 0 ) {
          if ( precision > 0 || length > 18 ) {
            // Numeric(Precision, Scale): Precision = total length; Scale = decimal places
            retval += "NUMERIC(" + ( length + precision ) + ", " + precision + ")";
          } else {
            if ( length > 9 ) {
              retval += "BIGINT";
            } else {
              if ( length < 5 ) {
                retval += "SMALLINT";
              } else {
                retval += "INTEGER";
              }
            }
          }

        } else {
          retval += "DOUBLE PRECISION";
        }
      }
      break;
    case ValueMetaInterface.TYPE_STRING:
      if ( length < 1 || length >= DatabaseMeta.CLOB_LENGTH ) {
        retval += "TEXT";
      } else {
        retval += "VARCHAR(" + length + ")";
      }
      break;
    default:
      retval += " UNKNOWN";
      break;
  }

  if ( addCr ) {
    retval += Const.CR;
  }

  return retval;
}