当前位置: 首页>>代码示例>>Java>>正文


Java ValueMetaInterface.convertData方法代码示例

本文整理汇总了Java中org.pentaho.di.core.row.ValueMetaInterface.convertData方法的典型用法代码示例。如果您正苦于以下问题:Java ValueMetaInterface.convertData方法的具体用法?Java ValueMetaInterface.convertData怎么用?Java ValueMetaInterface.convertData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.pentaho.di.core.row.ValueMetaInterface的用法示例。


在下文中一共展示了ValueMetaInterface.convertData方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRow

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
@Override
public Row getRow() {
    final DataSetHeader header = getHeader();
    final Object[] values = new Object[header.size()];

    if (row != null) {
        for (int i = 0; i < header.size(); i++) {
            final Column column = header.getSelectItem(i).getColumn();
            final int kettleIndex = rowMeta.indexOfValue(column.getName());
            final Object rawValue = row[kettleIndex];
            try {
                final ValueMetaInterface valueMeta = rowMeta.getValueMeta(kettleIndex);
                values[i] = valueMeta.convertData(valueMeta, rawValue);
            } catch (KettleValueException e) {
                throw new MetaModelException(e);
            }
        }
    }

    return new DefaultRow(header, values);
}
 
开发者ID:datacleaner,项目名称:pdi-datacleaner,代码行数:22,代码来源:KettleDataSet.java

示例2: getSessionVariablesData

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
private void getSessionVariablesData() throws KettleException {
  data.outputRowMeta = data.inputRowMeta.clone();
  meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore );

  // convert the data to the desired data type
  data.conversionMeta = data.outputRowMeta.cloneToType( ValueMetaInterface.TYPE_STRING );
  data.extraData = new Object[ meta.getFieldName().length ];
  for ( int i = 0; i < meta.getFieldName().length; i++ ) {
    ValueMetaInterface targetMeta = data.outputRowMeta.getValueMeta( data.inputRowMeta.size() + i );
    ValueMetaInterface sourceMeta = data.conversionMeta.getValueMeta( data.inputRowMeta.size() + i );
    data.extraData[ i ] =
      targetMeta.convertData( sourceMeta, getValue( meta.getVariableName()[ i ], getRowDefaultValue( i ) ) );
  }
}
 
开发者ID:pentaho,项目名称:pdi-platform-utils-plugin,代码行数:15,代码来源:GetSessionVariableStep.java

示例3: setValueToRow

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
private void setValueToRow(String value, int fieldnr) throws KettleValueException {
	
	XMLInputSaxField xmlInputField = (XMLInputSaxField) fields.get(fieldnr);

	switch (xmlInputField.getTrimType())
	{
	case XMLInputSaxField.TYPE_TRIM_LEFT:
		value = Const.ltrim(value);
		break;
	case XMLInputSaxField.TYPE_TRIM_RIGHT:
		value = Const.rtrim(value);
		break;
	case XMLInputSaxField.TYPE_TRIM_BOTH:
		value = Const.trim(value);
		break;
	default:
		break;
	}

	// DO CONVERSIONS...
	ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(fieldnr);
	ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(fieldnr);
	row[fieldnr] = targetValueMeta.convertData(sourceValueMeta, value);

	// Do we need to repeat this field if it is null?
	if (xmlInputField.isRepeated())
	{
		if (row[fieldnr]==null && data.previousRow != null)
		{
			Object previous = data.previousRow[fieldnr];
			row[fieldnr] = previous;
		}
	}
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:35,代码来源:XMLInputSaxDataRetriever.java

示例4: updateField

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
private void updateField(Object[] r) throws Exception
{
	// Loop through fields
	for(int i=0;i<data.fieldnr;i++)
	{		
		// DO CONVERSION OF THE DEFAULT VALUE ...
		// Entered by user
		ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(i);
		ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(i);
		if(!Const.isEmpty(meta.getReplaceMask()[i])) sourceValueMeta.setConversionMask(meta.getReplaceMask()[i]);
		r[i] = targetValueMeta.convertData(sourceValueMeta, data.realReplaceByvalues[i]);
	}
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:14,代码来源:SetValueConstant.java

示例5: replaceNull

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
public void replaceNull(Object[] row, int i) throws Exception
{
	if(row[i]==null) 
	{
		// DO CONVERSION OF THE DEFAULT VALUE ...
		// Entered by user
		ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(i);
		ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(i);
		if(!Const.isEmpty(data.realconversionMask)) sourceValueMeta.setConversionMask(data.realconversionMask);
		row[i] = targetValueMeta.convertData(sourceValueMeta, data.realReplaceByValue);
	 }
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:13,代码来源:IfNull.java

示例6: updateField

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
private void updateField(Object[] r) throws Exception
{
	// Loop through fields
	for(int i=0;i<data.fieldnr;i++)
	{		
		// DO CONVERSION OF THE DEFAULT VALUE ...
		// Entered by user
		ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(data.fieldnrs[i]);
		ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(data.fieldnrs[i]);
		if(!Const.isEmpty(meta.getReplaceMask()[i])) sourceValueMeta.setConversionMask(meta.getReplaceMask()[i]);
		r[data.fieldnrs[i]] = targetValueMeta.convertData(sourceValueMeta, data.realReplaceByvalues[i]);
	}
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:14,代码来源:SetValueConstant.java

示例7: replaceNull

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
public void replaceNull(Object[] row, ValueMetaInterface sourceValueMeta, int i, String realReplaceByValue, String realconversionMask) throws Exception
{
	// DO CONVERSION OF THE DEFAULT VALUE ...
	// Entered by user
	ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(i);
	if(!Const.isEmpty(realconversionMask)) sourceValueMeta.setConversionMask(realconversionMask);
	row[i] = targetValueMeta.convertData(sourceValueMeta, realReplaceByValue);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:9,代码来源:IfNull.java

示例8: generateRandomRows

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
/**
 * Generate some random rows to send to python in the case where a single variable (data frame) is being extracted
 * and we want to try and determine the types of the output fields
 *
 * @param inputMeta incoming row meta
 * @param r         Random instance to use
 * @return a list of randomly generated rows with types matching the incoming row types.
 * @throws KettleException if a problem occurs
 */
protected static List<Object[]> generateRandomRows( RowMetaInterface inputMeta, Random r ) throws KettleException {
  List<Object[]> rows = new ArrayList<Object[]>( NUM_RANDOM_ROWS );
  // ValueMetaInterface numericVM = new ValueMeta( "num", ValueMetaInterface.TYPE_NUMBER ); //$NON-NLS-1$
  ValueMetaInterface numericVM = ValueMetaFactory.createValueMeta( "num", ValueMetaInterface.TYPE_NUMBER ); //$NON-NLS-1$

  for ( int i = 0; i < NUM_RANDOM_ROWS; i++ ) {
    Object[] currentRow = new Object[inputMeta.size()];
    for ( int j = 0; j < inputMeta.size(); j++ ) {
      ValueMetaInterface vm = inputMeta.getValueMeta( j );

      ValueMetaInterface tempVM = vm.clone();
      tempVM.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );

      Object newVal;
      double d = r.nextDouble();
      switch ( vm.getType() ) {
        case ValueMetaInterface.TYPE_NUMBER:
        case ValueMetaInterface.TYPE_INTEGER:
        case ValueMetaInterface.TYPE_BIGNUMBER:
          d *= 100.0;
          newVal = d;
          if ( vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ) {
            newVal = tempVM.convertData( numericVM, newVal );
          }
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? vm.convertData( numericVM, newVal ) :
                  tempVM.convertToBinaryStringStorageType( newVal );
          break;
        case ValueMetaInterface.TYPE_DATE:
          newVal = new Date( new Date().getTime() + (long) ( d * 100000 ) );
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? newVal :
                  tempVM.convertToBinaryStringStorageType( newVal );
          break;
        case ValueMetaInterface.TYPE_TIMESTAMP:
          newVal = new Timestamp( new Date().getTime() + (long) ( d * 100000 ) );
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? newVal :
                  tempVM.convertToBinaryStringStorageType( newVal );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          newVal = r.nextBoolean();
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? newVal :
                  tempVM.convertToBinaryStringStorageType( newVal );
          break;
        default:
          newVal = d < 0.5 ? "value1" : "value2";
          currentRow[j] =
              vm.getStorageType() == ValueMetaInterface.STORAGE_TYPE_NORMAL ? newVal :
                  tempVM.convertToBinaryStringStorageType( newVal );
      }
    }
    rows.add( currentRow );
  }
  return rows;
}
 
开发者ID:pentaho-labs,项目名称:pentaho-cpython-plugin,代码行数:67,代码来源:CPythonScriptExecutorData.java

示例9: getRowDataValue

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
private Object getRowDataValue(final String fieldName, final ValueMetaInterface targetValueMeta, final ValueMetaInterface sourceValueMeta, final Object value, final DateFormat df) throws KettleException
{
    if (value == null) {
        return value;
    }

    if (ValueMetaInterface.TYPE_STRING == targetValueMeta.getType()) {
        return targetValueMeta.convertData(sourceValueMeta, value.toString());
    }
    
    if (ValueMetaInterface.TYPE_NUMBER == targetValueMeta.getType()) {
        return targetValueMeta.convertData(sourceValueMeta, Double.valueOf(value.toString()));
    }
    
    if (ValueMetaInterface.TYPE_INTEGER == targetValueMeta.getType()) {
        return targetValueMeta.convertData(sourceValueMeta, Long.valueOf(value.toString()));
    }
    
    if (ValueMetaInterface.TYPE_BIGNUMBER == targetValueMeta.getType()) {
        return targetValueMeta.convertData(sourceValueMeta, new BigDecimal(value.toString()));
    }
    
    if (ValueMetaInterface.TYPE_BOOLEAN == targetValueMeta.getType()) {
        return targetValueMeta.convertData(sourceValueMeta, Boolean.valueOf(value.toString()));
    }
    
    if (ValueMetaInterface.TYPE_BINARY == targetValueMeta.getType()) {
        return targetValueMeta.convertData(sourceValueMeta, value);
    }

    if (ValueMetaInterface.TYPE_DATE == targetValueMeta.getType()) {
        try {
            return targetValueMeta.convertData(sourceValueMeta, df.parse(value.toString()));
        } catch (final ParseException e) {
            throw new KettleValueException("Unable to convert data type of value");
        }
    }

    if (value instanceof JSONObject || value instanceof JSONArray) {
        return targetValueMeta.convertData(targetValueMeta, "{" + fieldName + ":" + value.toString() + "}");
    }

    throw new KettleValueException("Unable to convert data type of value");
}
 
开发者ID:instaclick,项目名称:pdi-plugin-parsejsonstring,代码行数:45,代码来源:ParseJsonString.java

示例10: processRow

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
	Object[] rowData;
	
	if (data.readsRows)
	{
		rowData = getRow();
		if (rowData==null)
		{
			setOutputDone();
			return false;
		}
	}
	else
	{
		rowData=RowDataUtil.allocateRowData(0);
		incrementLinesRead();
	}
	
	// initialize 
	if (first && rowData!=null)
	{
		first=false;
		
           
           // Make output meta data
		//
		if (data.readsRows) {
			data.inputRowMeta = getInputRowMeta();
		}
		else {
			data.inputRowMeta = new RowMeta();
		}
           data.outputRowMeta = data.inputRowMeta.clone();
           meta.getFields(data.outputRowMeta, getStepname(), null, null, this);
           
           // Create a copy of the output row metadata to do the data conversion...
           //
           data.conversionMeta = data.outputRowMeta.clone();
           for (ValueMetaInterface valueMeta : data.conversionMeta.getValueMetaList()) {
           	valueMeta.setType(ValueMetaInterface.TYPE_STRING);
           }

           // Add the variables to the row...
           //
           // Keep the Object[] for speed.  Although this step will always be used in "small" amounts, there's always going to be those cases where performance is required.
           // 
           data.extraData = new Object[meta.getFieldName().length];
           for (int i=0;i<meta.getFieldName().length;i++)
           {
           	String newValue = environmentSubstitute(meta.getVariableString()[i]);
           	if (log.isDetailed()) logDetailed("field ["+meta.getFieldName()[i]+"] has value ["+newValue+"]");
           	
           	// Convert the data to the desired data type...
           	//
           	ValueMetaInterface targetMeta = data.outputRowMeta.getValueMeta(data.inputRowMeta.size()+i);
           	ValueMetaInterface sourceMeta = data.conversionMeta.getValueMeta(data.inputRowMeta.size()+i); // String type + conversion masks, symbols, trim type, etc
           	data.extraData[i] = targetMeta.convertData(sourceMeta, newValue);
           }
	}
	
       rowData = RowDataUtil.addRowData(rowData, data.inputRowMeta.size(), data.extraData);
       
       putRow(data.outputRowMeta, rowData);		     
				
       if (!data.readsRows) // Just one row and then stop!
       {
           setOutputDone();
           return false;
       }
       
	return true;
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:74,代码来源:GetVariable.java

示例11: loadXML

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException {

    List<FieldMetadataBean> fieldBeans = getMetaFields();
    Node fields = XMLHandler.getSubNode( stepnode, "fields" );
    int nrfields = XMLHandler.countNodes( fields, "field" );
    HashMap<String, FieldMetadataBean> fieldMap = StepPluginUtils.getFieldMetadataBeansAsMap( fieldBeans );
    if ( fieldMap != null ) {
      for ( int i = 0; i < nrfields; i++ ) {

        Node fnode = XMLHandler.getSubNodeByNr( fields, "field", i );
        final String name = XMLHandler.getTagValue( fnode, "name" );
        FieldMetadataBean fieldBean = fieldMap.get( name );
        if ( fieldBean != null ) {
          try {
            Field field = fieldBean.getField();
            ValueMetaInterface valueMeta = fieldBean.getValueMeta();
            String valueString = XMLHandler.getTagValue( fnode, "value" );
            if ( valueString != null ) {
              Object convertedValue = valueMeta.convertData( new ValueMetaString(), valueString );
              System.out.println( "Converted value from " + valueString + " to " + convertedValue );
              // Check for Integer (java.Long) -> java int
              if ( ValueMetaInteger.class.isAssignableFrom( valueMeta.getClass() ) ) {
                if ( Integer.TYPE.isAssignableFrom( field.getType() ) ) {
                  convertedValue = ( (Long) convertedValue ).intValue();
                } else if ( Short.TYPE.isAssignableFrom( field.getType() ) ) {
                  convertedValue = ( (Long) convertedValue ).shortValue();
                }
              }
              // TODO Dates/times?

              StepPluginUtils.setValueOfFieldToObject( this, field, convertedValue );
            } else {
              System.out.println( "No value in XML for " + field.getName() + ", using default" );
            }
          } catch ( KettleException e ) {
            throw new KettleXMLException( "No such field: " + name, e );
          }
        } else {
          System.out.println( "No such field: " + name + ", ignoring..." );
        }
      }
    }
  }
 
开发者ID:mattyb149,项目名称:pdi-pojo,代码行数:44,代码来源:StepPluginPOJO.java

示例12: getAttributeValue

import org.pentaho.di.core.row.ValueMetaInterface; //导入方法依赖的package包/类
private Object getAttributeValue(LDAPInputField field,Attribute attr, int i, Object outputRowData) throws Exception {

		if(field.getType() ==  ValueMetaInterface.TYPE_BINARY) {
			// It's a binary field
			// no need to convert, just return the value as it
			try  {
				return (byte[])attr.get();
			}catch(java.lang.ClassCastException e){
				return attr.get().toString().getBytes();
			}
		}
		
		String retval=null;
		if(field.getReturnType() == LDAPInputField.FETCH_ATTRIBUTE_AS_BINARY && field.getType() ==  ValueMetaInterface.TYPE_STRING) {
			// Convert byte[] to string
			return LDAPConnection.extractBytesAndConvertToString(attr, field.isObjectSid());
		}
		
		// extract as string
		retval=extractString(attr); 	
		
		// DO Trimming!
		switch (field.getTrimType()) {
			case LDAPInputField.TYPE_TRIM_LEFT:
				retval = Const.ltrim(retval);
			break;
			case LDAPInputField.TYPE_TRIM_RIGHT:
				retval = Const.rtrim(retval);
			break;
			case LDAPInputField.TYPE_TRIM_BOTH:
				retval = Const.trim(retval);
			break;
			default:
			break;
		}
		
		// DO CONVERSIONS...
		//
		ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(i);
		ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(i);
		return targetValueMeta.convertData(sourceValueMeta, retval);
		
	}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:44,代码来源:LDAPInput.java


注:本文中的org.pentaho.di.core.row.ValueMetaInterface.convertData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。