Java Code Examples for org.pentaho.di.core.row.ValueMetaInterface#TYPE_NONE

The following examples show how to use org.pentaho.di.core.row.ValueMetaInterface#TYPE_NONE . 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: ExcelWriterMetaInjection.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public List<StepInjectionMetaEntry> getStepInjectionMetadataEntries() throws KettleException {
  List<StepInjectionMetaEntry> all = new ArrayList<StepInjectionMetaEntry>();

  StepInjectionMetaEntry fieldsEntry =
    new StepInjectionMetaEntry( "FIELDS",
      ValueMetaInterface.TYPE_NONE, BaseMessages.getString( PKG, "ExcelWriterMetaInjection.AllFields" ) );
  all.add( fieldsEntry );

  StepInjectionMetaEntry fieldEntry =
    new StepInjectionMetaEntry( "FIELD",
      ValueMetaInterface.TYPE_NONE, BaseMessages.getString( PKG, "ExcelWriterMetaInjection.AllFields" ) );
  fieldsEntry.getDetails().add( fieldEntry );

  for ( Entry entry : Entry.values() ) {
    if ( entry.getValueType() != ValueMetaInterface.TYPE_NONE ) {
      StepInjectionMetaEntry metaEntry =
        new StepInjectionMetaEntry( entry.name(), entry.getValueType(), entry.getDescription() );
      fieldEntry.getDetails().add( metaEntry );
    }
  }

  return all;
}
 
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: BaseStepMetaInjection.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected void addTopLevelStepMetaInjectionEntries( List<StepInjectionMetaEntry> list,
  StepMetaInjectionEnumEntry[] allEntries ) {
  for ( StepMetaInjectionEnumEntry entry : allEntries ) {
    if ( entry.getParent() == null && entry.getValueType() != ValueMetaInterface.TYPE_NONE ) {
      list.add( createStepMetaInjectionEntry( entry ) );
    }
  }
}
 
Example 4
Source File: GetVariableMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void readData( Node stepnode ) throws KettleXMLException {
  try {
    Node fields = XMLHandler.getSubNode( stepnode, "fields" );
    int count = XMLHandler.countNodes( fields, "field" );

    allocate( count );

    for ( int i = 0; i < count; i++ ) {
      Node fnode = XMLHandler.getSubNodeByNr( fields, "field", i );

      fieldDefinitions[i].setFieldName( XMLHandler.getTagValue( fnode, "name" ) );
      fieldDefinitions[i].setVariableString( XMLHandler.getTagValue( fnode, "variable" ) );
      fieldDefinitions[i].setFieldType(
        ValueMetaFactory.getIdForValueMeta( XMLHandler.getTagValue( fnode, "type" ) ) );
      fieldDefinitions[i].setFieldFormat( XMLHandler.getTagValue( fnode, "format" ) );
      fieldDefinitions[i].setCurrency( XMLHandler.getTagValue( fnode, "currency" ) );
      fieldDefinitions[i].setDecimal( XMLHandler.getTagValue( fnode, "decimal" ) );
      fieldDefinitions[i].setGroup( XMLHandler.getTagValue( fnode, "group" ) );
      fieldDefinitions[i].setFieldLength( Const.toInt( XMLHandler.getTagValue( fnode, "length" ), -1 ) );
      fieldDefinitions[i].setFieldPrecision( Const.toInt( XMLHandler.getTagValue( fnode, "precision" ), -1 ) );
      fieldDefinitions[i].setTrimType(
        ValueMetaString.getTrimTypeByCode( XMLHandler.getTagValue( fnode, "trim_type" ) ) );

      // Backward compatibility
      //
      if ( fieldDefinitions[i].getFieldType() == ValueMetaInterface.TYPE_NONE ) {
        fieldDefinitions[i].setFieldType( ValueMetaInterface.TYPE_STRING );
      }
    }
  } catch ( Exception e ) {
    throw new KettleXMLException( "Unable to read step information from XML", e );
  }
}
 
Example 5
Source File: DataSetDialog.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
/**
 * Look at the metadata specified here and create the table accordingly...
 * - Create a table for the Database Group type
 * - Create a metadata file for the CSV group type
 */
protected void createTable() {
  try {
    verifySettings();

    DataSet set = new DataSet();
    getInfo( set );
    DataSetGroup group = set.getGroup();

    String tableName = wTableName.getText();

    // Calculate the row metadata of the table
    //
    RowMetaInterface rowMeta = new RowMeta();
    int nrFields = wFieldMapping.nrNonEmpty();
    for ( int i = 0; i < nrFields; i++ ) {
      TableItem item = wFieldMapping.getNonEmpty( i );
      int colnr = 2;
      String columnName = item.getText( colnr++ );
      if ( StringUtil.isEmpty( columnName ) ) {
        throw new KettleException( BaseMessages.getString( PKG, "DataSetDialog.Error.NoColumnName", Integer.toString( i ) ) );
      }
      int fieldType = ValueMetaFactory.getIdForValueMeta( item.getText( colnr++ ) );
      if ( fieldType == ValueMetaInterface.TYPE_NONE ) {
        throw new KettleException( BaseMessages.getString( PKG, "DataSetDialog.Error.NoDataType", Integer.toString( i ) ) );
      }
      int length = Const.toInt( item.getText( colnr++ ), -1 );
      int precision = Const.toInt( item.getText( colnr++ ), -1 );

      ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( columnName, fieldType, length, precision );
      rowMeta.addValueMeta( valueMeta );
    }

    group.createTable( tableName, rowMeta );

  } catch ( Exception e ) {
    new ErrorDialog( shell, "Error", "Error retrieving metadata from dataset table", e );
  }

}
 
Example 6
Source File: ValueMetaFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static int getIdForValueMeta( String valueMetaName ) {
  for ( PluginInterface plugin : pluginRegistry.getPlugins( ValueMetaPluginType.class ) ) {
    if ( valueMetaName != null && valueMetaName.equalsIgnoreCase( plugin.getName() ) ) {
      return Integer.valueOf( plugin.getIds()[0] );
    }
  }
  return ValueMetaInterface.TYPE_NONE;
}
 
Example 7
Source File: JavaScriptUtils.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static Object convertFromJs( Object value, int type, String fieldName ) throws KettleValueException {
  String classType = value.getClass().getName();
  switch ( type ) {
    case ValueMetaInterface.TYPE_NUMBER:
      return jsToNumber( value, classType );

    case ValueMetaInterface.TYPE_INTEGER:
      return jsToInteger( value, value.getClass() );

    case ValueMetaInterface.TYPE_STRING:
      return jsToString( value, classType );

    case ValueMetaInterface.TYPE_DATE:
      return jsToDate( value, classType );

    case ValueMetaInterface.TYPE_BOOLEAN:
      return value;

    case ValueMetaInterface.TYPE_BIGNUMBER:
      return jsToBigNumber( value, classType );

    case ValueMetaInterface.TYPE_BINARY:
      return Context.jsToJava( value, byte[].class );

    case ValueMetaInterface.TYPE_NONE:
      throw new KettleValueException( "No data output data type was specified for new field ["
        + fieldName + "]" );

    default:
      return Context.jsToJava( value, Object.class );
  }
}
 
Example 8
Source File: PhysicalTableImporter.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static DataTypeSettings getDataTypeSettings( ValueMetaInterface v ) {
  DataTypeSettings dataTypeSettings = new DataTypeSettings( DataTypeSettings.DATA_TYPE_STRING );
  switch ( v.getType() ) {
    case ValueMetaInterface.TYPE_BIGNUMBER:
    case ValueMetaInterface.TYPE_INTEGER:
    case ValueMetaInterface.TYPE_NUMBER:
      dataTypeSettings.setType( DataTypeSettings.DATA_TYPE_NUMERIC );
      break;

    case ValueMetaInterface.TYPE_BINARY:
      dataTypeSettings.setType( DataTypeSettings.DATA_TYPE_BINARY );
      break;

    case ValueMetaInterface.TYPE_BOOLEAN:
      dataTypeSettings.setType( DataTypeSettings.DATA_TYPE_BOOLEAN );
      break;

    case ValueMetaInterface.TYPE_DATE:
      dataTypeSettings.setType( DataTypeSettings.DATA_TYPE_DATE );
      break;

    case ValueMetaInterface.TYPE_STRING:
      dataTypeSettings.setType( DataTypeSettings.DATA_TYPE_STRING );
      break;

    case ValueMetaInterface.TYPE_NONE:
      dataTypeSettings.setType( DataTypeSettings.DATA_TYPE_UNKNOWN );
      break;

    default:
      break;
  }
  dataTypeSettings.setLength( v.getLength() );
  dataTypeSettings.setPrecision( v.getPrecision() );

  return dataTypeSettings;
}
 
Example 9
Source File: HBaseValueMeta.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
/**
 * Set the type for this field from a string
 *
 * @param hbaseType the type for this field as a string
 * @throws IllegalArgumentException if the type is unknown
 */
public void setHBaseTypeFromString( String hbaseType )
  throws IllegalArgumentException {
  if ( hbaseType.equalsIgnoreCase( "Integer" ) ) {
    setType( ValueMeta.getType( hbaseType ) );
    setIsLongOrDouble( false );
    return;
  }
  if ( hbaseType.equalsIgnoreCase( "Long" ) ) {
    setType( ValueMeta.getType( "Integer" ) );
    setIsLongOrDouble( true );
    return;
  }
  if ( hbaseType.equals( "Float" ) ) {
    setType( ValueMeta.getType( "Number" ) );
    setIsLongOrDouble( false );
    return;
  }
  if ( hbaseType.equals( "Double" ) ) {
    setType( ValueMeta.getType( "Number" ) );
    setIsLongOrDouble( true );
    return;
  }

  // default
  int type = ValueMeta.getType( hbaseType );
  if ( type == ValueMetaInterface.TYPE_NONE ) {
    throw new IllegalArgumentException( BaseMessages.getString( PKG,
      "HBaseValueMeta.Error.UnknownType", hbaseType ) );
  }

  setType( type );
}
 
Example 10
Source File: InlineEtlQueryExecutor.java    From pentaho-metadata with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void processRow( MemoryResultSet memResults, final RowMetaInterface rowMeta, final Object[] row )
  throws KettleStepException {
  if ( memResults == null ) {
    return;
  }
  try {
    Object[] pentahoRow = new Object[memResults.getColumnCount()];
    for ( int columnNo = 0; columnNo < memResults.getColumnCount(); columnNo++ ) {
      ValueMetaInterface valueMeta = rowMeta.getValueMeta( columnNo );

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

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

    memResults.addRow( pentahoRow );
  } catch ( KettleValueException e ) {
    throw new KettleStepException( e );
  }
}
 
Example 11
Source File: ExcelInputDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Processing excel workbook, filling fields
 *
 * @param fields   RowMetaInterface for filling fields
 * @param info     ExcelInputMeta
 * @param workbook excel workbook for processing
 * @throws KettlePluginException
 */
private void processingWorkbook( RowMetaInterface fields, ExcelInputMeta info, KWorkbook workbook )
  throws KettlePluginException {
  int nrSheets = workbook.getNumberOfSheets();
  for ( int j = 0; j < nrSheets; j++ ) {
    KSheet sheet = workbook.getSheet( j );

    // See if it's a selected sheet:
    int sheetIndex;
    if ( info.readAllSheets() ) {
      sheetIndex = 0;
    } else {
      sheetIndex = Const.indexOfString( sheet.getName(), info.getSheetName() );
    }
    if ( sheetIndex >= 0 ) {
      // We suppose it's the complete range we're looking for...
      //
      int rownr = 0;
      int startcol = 0;

      if ( info.readAllSheets() ) {
        if ( info.getStartColumn().length == 1 ) {
          startcol = info.getStartColumn()[ 0 ];
        }
        if ( info.getStartRow().length == 1 ) {
          rownr = info.getStartRow()[ 0 ];
        }
      } else {
        rownr = info.getStartRow()[ sheetIndex ];
        startcol = info.getStartColumn()[ sheetIndex ];
      }

      boolean stop = false;
      for ( int colnr = startcol; !stop; colnr++ ) {
        try {
          String fieldname = null;
          int fieldtype = ValueMetaInterface.TYPE_NONE;

          KCell cell = sheet.getCell( colnr, rownr );
          if ( cell == null ) {
            stop = true;
          } else {
            if ( cell.getType() != KCellType.EMPTY ) {
              // We found a field.
              fieldname = cell.getContents();
            }

            // System.out.println("Fieldname = "+fieldname);

            KCell below = sheet.getCell( colnr, rownr + 1 );

            if ( below != null ) {
              if ( below.getType() == KCellType.BOOLEAN ) {
                fieldtype = ValueMetaInterface.TYPE_BOOLEAN;
              } else if ( below.getType() == KCellType.DATE ) {
                fieldtype = ValueMetaInterface.TYPE_DATE;
              } else if ( below.getType() == KCellType.LABEL ) {
                fieldtype = ValueMetaInterface.TYPE_STRING;
              } else if ( below.getType() == KCellType.NUMBER ) {
                fieldtype = ValueMetaInterface.TYPE_NUMBER;
              } else {
                fieldtype = ValueMetaInterface.TYPE_STRING;
              }
            } else {
              fieldtype = ValueMetaInterface.TYPE_STRING;
            }

            if ( Utils.isEmpty( fieldname ) ) {
              stop = true;
            } else {
              if ( fieldtype != ValueMetaInterface.TYPE_NONE ) {
                ValueMetaInterface field = ValueMetaFactory.createValueMeta( fieldname, fieldtype );
                fields.addValueMeta( field );
              }
            }
          }
        } catch ( ArrayIndexOutOfBoundsException aioobe ) {
          // System.out.println("index out of bounds at column "+colnr+" : "+aioobe.toString());
          stop = true;
        }
      }
    }
  }
}
 
Example 12
Source File: ValueMetaBaseTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testHashCodes() throws Exception {
  ValueMetaBase valueMetaString = new ValueMetaBase( );

  valueMetaString.type = ValueMetaInterface.TYPE_BOOLEAN;
  assertEquals( valueMetaString.hashCode( true ),  1231 );

  SimpleDateFormat sdf = new SimpleDateFormat( "dd/M/yyyy" );
  String dateInString = "1/1/2018";
  Date dateObj = sdf.parse( dateInString );
  valueMetaString.type = ValueMetaInterface.TYPE_DATE;
  assertEquals( valueMetaString.hashCode( dateObj ),  -1358655136 );

  Double numberObj = Double.valueOf( 5.1 );
  valueMetaString.type = ValueMetaInterface.TYPE_NUMBER;
  assertEquals( valueMetaString.hashCode( numberObj ),  645005312 );

  valueMetaString.type = ValueMetaInterface.TYPE_STRING;
  assertEquals( valueMetaString.hashCode( "test" ),  3556498 );

  Long longObj = 123L;
  valueMetaString.type = ValueMetaInterface.TYPE_INTEGER;
  assertEquals( valueMetaString.hashCode( longObj ), 123 );

  BigDecimal bDecimalObj = new BigDecimal( 123.1 );
  valueMetaString.type = ValueMetaInterface.TYPE_BIGNUMBER;
  assertEquals( valueMetaString.hashCode( bDecimalObj ),  465045870 );

  byte[] bBinary = new byte[2];
  bBinary[0] = 1;
  bBinary[1] = 0;
  valueMetaString.type = ValueMetaInterface.TYPE_BINARY;
  assertEquals( valueMetaString.hashCode( bBinary ),  992 );

  Timestamp timestampObj = Timestamp.valueOf( "2018-01-01 10:10:10.000000000" );
  valueMetaString.type = ValueMetaInterface.TYPE_TIMESTAMP;
  assertEquals( valueMetaString.hashCode( timestampObj ),  -1322045776 );

  byte[] ipAddr = new byte[]{127, 0, 0, 1};
  InetAddress addrObj = InetAddress.getByAddress( ipAddr );
  valueMetaString.type = ValueMetaInterface.TYPE_INET;
  assertEquals( valueMetaString.hashCode( addrObj ),  2130706433 );

  valueMetaString.type = ValueMetaInterface.TYPE_NONE;
  assertEquals( valueMetaString.hashCode( "any" ),  0 );
}
 
Example 13
Source File: MetaInjectTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void injectMetaFromMultipleInputSteps() throws KettleException {
  Map<TargetStepAttribute, SourceStepField> targetSourceMapping =
      new LinkedHashMap<TargetStepAttribute, SourceStepField>();
  targetSourceMapping.put( new TargetStepAttribute( INJECTOR_STEP_NAME, "DATA_TYPE", true ), new SourceStepField(
      "TYPE_INPUT", "col_type" ) );
  targetSourceMapping.put( new TargetStepAttribute( INJECTOR_STEP_NAME, "NAME", true ), new SourceStepField(
      "NAME_INPUT", "col_name" ) );
  meta.setTargetSourceMapping( targetSourceMapping );

  doReturn( new String[] { "NAME_INPUT", "TYPE_INPUT" } ).when( transMeta ).getPrevStepNames( any( StepMeta.class ) );

  RowSet nameInputRowSet = mock( RowSet.class );
  RowMeta nameRowMeta = new RowMeta();
  nameRowMeta.addValueMeta( new ValueMetaString( "col_name" ) );
  doReturn( nameRowMeta ).when( nameInputRowSet ).getRowMeta();
  doReturn( nameInputRowSet ).when( metaInject ).findInputRowSet( "NAME_INPUT" );

  RowSet typeInputRowSet = mock( RowSet.class );
  RowMeta typeRowMeta = new RowMeta();
  typeRowMeta.addValueMeta( new ValueMetaString( "col_type" ) );
  doReturn( typeRowMeta ).when( typeInputRowSet ).getRowMeta();
  doReturn( typeInputRowSet ).when( metaInject ).findInputRowSet( "TYPE_INPUT" );

  doReturn( new Object[] { "FIRST_NAME" } ).doReturn( null ).when( metaInject ).getRowFrom( nameInputRowSet );
  doReturn( new Object[] { "String" } ).doReturn( null ).when( metaInject ).getRowFrom( typeInputRowSet );

  List<StepInjectionMetaEntry> injectionMetaEntryList = new ArrayList<StepInjectionMetaEntry>();
  StepInjectionMetaEntry fields = new StepInjectionMetaEntry( "FIELDS", ValueMetaInterface.TYPE_NONE, "" );
  StepInjectionMetaEntry fieldEntry = new StepInjectionMetaEntry( "FIELD", ValueMetaInterface.TYPE_NONE, "" );
  fields.getDetails().add( fieldEntry );
  StepInjectionMetaEntry nameEntry = new StepInjectionMetaEntry( "NAME", ValueMetaInterface.TYPE_STRING, "" );
  fieldEntry.getDetails().add( nameEntry );
  StepInjectionMetaEntry dataEntry = new StepInjectionMetaEntry( "DATA_TYPE", ValueMetaInterface.TYPE_STRING, "" );
  fieldEntry.getDetails().add( dataEntry );
  injectionMetaEntryList.add( fields );
  doReturn( injectionMetaEntryList ).when( metaInjectionInterface ).getStepInjectionMetadataEntries();

  meta.setNoExecution( true );
  assertTrue( metaInject.init( meta, data ) );

  metaInject.processRow( meta, data );

  StepInjectionMetaEntry expectedNameEntry =
      new StepInjectionMetaEntry( "NAME", "FIRST_NAME", ValueMetaInterface.TYPE_STRING, "" );
  StepInjectionMetaEntry expectedDataEntry =
      new StepInjectionMetaEntry( "DATA_TYPE", "String", ValueMetaInterface.TYPE_STRING, "" );
  verify( metaInject, atLeastOnce() ).setEntryValueIfFieldExists( refEq( expectedNameEntry ), any(
      RowMetaAndData.class ), any( SourceStepField.class ) );
  verify( metaInject, atLeastOnce() ).setEntryValueIfFieldExists( refEq( expectedDataEntry ), any(
      RowMetaAndData.class ), any( SourceStepField.class ) );
}
 
Example 14
Source File: CsvInputMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void injectStepMetadataEntries( List<StepInjectionMetaEntry> metadata ) {
  for ( StepInjectionMetaEntry entry : metadata ) {
    KettleAttributeInterface attr = findAttribute( entry.getKey() );

    // Set top level attributes...
    //
    if ( entry.getValueType() != ValueMetaInterface.TYPE_NONE ) {
      if ( attr.getKey().equals( "FILENAME" ) ) {
        filename = (String) entry.getValue();
      } else if ( attr.getKey().equals( "FILENAME_FIELD" ) ) {
        filenameField = (String) entry.getValue();
      } else if ( attr.getKey().equals( "ROW_NUM_FIELD" ) ) {
        rowNumField = (String) entry.getValue();
      } else if ( attr.getKey().equals( "HEADER_PRESENT" ) ) {
        headerPresent = (Boolean) entry.getValue();
      } else if ( attr.getKey().equals( "DELIMITER" ) ) {
        delimiter = (String) entry.getValue();
      } else if ( attr.getKey().equals( "ENCLOSURE" ) ) {
        enclosure = (String) entry.getValue();
      } else if ( attr.getKey().equals( "BUFFERSIZE" ) ) {
        bufferSize = (String) entry.getValue();
      } else if ( attr.getKey().equals( "LAZY_CONVERSION" ) ) {
        lazyConversionActive = (Boolean) entry.getValue();
      } else if ( attr.getKey().equals( "PARALLEL" ) ) {
        runningInParallel = (Boolean) entry.getValue();
      } else if ( attr.getKey().equals( "NEWLINE_POSSIBLE" ) ) {
        newlinePossibleInFields = (Boolean) entry.getValue();
      } else if ( attr.getKey().equals( "ADD_FILENAME_RESULT" ) ) {
        isaddresult = (Boolean) entry.getValue();
      } else if ( attr.getKey().equals( "FORMAT" ) ) {
        fileFormat = (String) entry.getValue();
      } else if ( attr.getKey().equals( "ENCODING" ) ) {
        encoding = (String) entry.getValue();
      } else {
        throw new RuntimeException( "Unhandled metadata injection of attribute: "
          + attr.toString() + " - " + attr.getDescription() );
      }
    } else {
      if ( attr.getKey().equals( "FIELDS" ) ) {
        // This entry contains a list of lists...
        // Each list contains a single CSV input field definition (one line in the dialog)
        //
        List<StepInjectionMetaEntry> inputFieldEntries = entry.getDetails();
        inputFields = new TextFileInputField[inputFieldEntries.size()];
        for ( int row = 0; row < inputFieldEntries.size(); row++ ) {
          StepInjectionMetaEntry inputFieldEntry = inputFieldEntries.get( row );
          TextFileInputField inputField = new TextFileInputField();

          List<StepInjectionMetaEntry> fieldAttributes = inputFieldEntry.getDetails();
          for ( int i = 0; i < fieldAttributes.size(); i++ ) {
            StepInjectionMetaEntry fieldAttribute = fieldAttributes.get( i );
            KettleAttributeInterface fieldAttr = findAttribute( fieldAttribute.getKey() );

            String attributeValue = (String) fieldAttribute.getValue();
            if ( fieldAttr.getKey().equals( "FIELD_NAME" ) ) {
              inputField.setName( attributeValue );
            } else if ( fieldAttr.getKey().equals( "FIELD_TYPE" ) ) {
              inputField.setType( ValueMetaFactory.getIdForValueMeta( attributeValue ) );
            } else if ( fieldAttr.getKey().equals( "FIELD_FORMAT" ) ) {
              inputField.setFormat( attributeValue );
            } else if ( fieldAttr.getKey().equals( "FIELD_LENGTH" ) ) {
              inputField.setLength( attributeValue == null ? -1 : Integer.parseInt( attributeValue ) );
            } else if ( fieldAttr.getKey().equals( "FIELD_PRECISION" ) ) {
              inputField.setPrecision( attributeValue == null ? -1 : Integer.parseInt( attributeValue ) );
            } else if ( fieldAttr.getKey().equals( "FIELD_CURRENCY" ) ) {
              inputField.setCurrencySymbol( attributeValue );
            } else if ( fieldAttr.getKey().equals( "FIELD_DECIMAL" ) ) {
              inputField.setDecimalSymbol( attributeValue );
            } else if ( fieldAttr.getKey().equals( "FIELD_GROUP" ) ) {
              inputField.setGroupSymbol( attributeValue );
            } else if ( fieldAttr.getKey().equals( "FIELD_TRIM_TYPE" ) ) {
              inputField.setTrimType( ValueMetaString.getTrimTypeByCode( attributeValue ) );
            } else {
              throw new RuntimeException( "Unhandled metadata injection of attribute: "
                + fieldAttr.toString() + " - " + fieldAttr.getDescription() );
            }
          }

          inputFields[row] = inputField;
        }
      }
    }
  }
}
 
Example 15
Source File: SalesforceInputMetaInjectionTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws Exception {
  check( "SALESFORCE_URL", () ->  meta.getTargetURL() );
  check( "SALESFORCE_USERNAME", () ->  meta.getUsername() );
  check( "SALESFORCE_PASSWORD", () ->  meta.getPassword() );
  check( "TIME_OUT", () ->  meta.getTimeout() );
  check( "USE_COMPRESSION", () ->  meta.isCompression() );
  check( "MODULE", () ->  meta.getModule() );
  check( "INCLUDE_SQL_IN_OUTPUT", () ->  meta.includeSQL() );
  check( "SQL_FIELDNAME", () ->  meta.getSQLField() );
  check( "INCLUDE_TIMESTAMP_IN_OUTPUT", () ->  meta.includeTimestamp() );
  check( "TIMESTAMP_FIELDNAME", () ->  meta.getTimestampField() );
  check( "INCLUDE_URL_IN_OUTPUT", () ->  meta.includeTargetURL() );
  check( "URL_FIELDNAME", () ->  meta.getTargetURLField() );
  check( "INCLUDE_MODULE_IN_OUTPUT", () ->  meta.includeModule() );
  check( "MODULE_FIELDNAME", () ->  meta.getModuleField() );
  check( "INCLUDE_DELETION_DATE_IN_OUTPUT", () ->  meta.includeDeletionDate() );
  check( "DELETION_DATE_FIELDNAME", () ->  meta.getDeletionDateField() );
  check( "INCLUDE_ROWNUM_IN_OUTPUT", () ->  meta.includeRowNumber() );
  check( "ROWNUM_FIELDNAME", () ->  meta.getRowNumberField() );
  check( "QUERY_CONDITION", () ->  meta.getCondition() );
  check( "LIMIT", () ->  meta.getRowLimit() );
  check( "USE_SPECIFIED_QUERY", () ->  meta.isSpecifyQuery() );
  check( "SPECIFY_QUERY", () ->  meta.getQuery() );
  check( "END_DATE", () ->  meta.getReadTo() );
  check( "START_DATE", () ->  meta.getReadFrom() );
  check( "QUERY_ALL", () ->  meta.isQueryAll() );
  checkStringToInt( "RETRIEVE", () ->  meta.getRecordsFilter(),
    SalesforceConnectionUtils.recordsFilterCode,
    new int[]{ RECORDS_FILTER_ALL, RECORDS_FILTER_UPDATED, RECORDS_FILTER_DELETED } );
  check( "NAME", () ->  meta.getInputFields()[0].getName() );
  check( "FIELD", () ->  meta.getInputFields()[0].getField() );
  check( "LENGTH", () ->  meta.getInputFields()[0].getLength() );
  check( "FORMAT", () ->  meta.getInputFields()[0].getFormat() );
  check( "PRECISION", () ->  meta.getInputFields()[0].getPrecision() );
  check( "CURRENCY", () ->  meta.getInputFields()[0].getCurrencySymbol() );
  check( "DECIMAL", () ->  meta.getInputFields()[0].getDecimalSymbol() );
  check( "GROUP", () ->  meta.getInputFields()[0].getGroupSymbol() );
  check( "REPEAT", () ->  meta.getInputFields()[0].isRepeated() );
  check( "ISIDLOOKUP", () ->  meta.getInputFields()[0].isIdLookup() );
  checkStringToInt( "TRIM_TYPE", () ->  meta.getInputFields()[0].getTrimType(),
    SalesforceInputField.trimTypeCode,
    new int[]{ TYPE_TRIM_NONE, TYPE_TRIM_LEFT, TYPE_TRIM_RIGHT, TYPE_TRIM_BOTH });
  int[] types = new int[]{
    ValueMetaInterface.TYPE_NONE,
    ValueMetaInterface.TYPE_NUMBER,
    ValueMetaInterface.TYPE_STRING,
    ValueMetaInterface.TYPE_DATE,
    ValueMetaInterface.TYPE_BOOLEAN,
    ValueMetaInterface.TYPE_INTEGER,
    ValueMetaInterface.TYPE_BIGNUMBER,
    ValueMetaInterface.TYPE_SERIALIZABLE,
    ValueMetaInterface.TYPE_BINARY,
    ValueMetaInterface.TYPE_TIMESTAMP,
    ValueMetaInterface.TYPE_INET
  };
  ValueMetaString valueMeta = new ValueMetaString();
  checkStringToInt("TYPE", () ->  meta.getInputFields()[0].getType(),
    valueMeta.typeCodes, types );
}
 
Example 16
Source File: CalculatorMetaFunction.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static int getCalcFunctionDefaultResultType( int type ) {
  if ( type < 0 || type >= calcDefaultResultType.length ) {
    return ValueMetaInterface.TYPE_NONE;
  }
  return calcDefaultResultType[ type ];
}
 
Example 17
Source File: ValueMetaBaseTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test( expected = KettleException.class )
public void testGetValueUnknownType() throws Exception {
  ValueMetaBase valueMetaBase = new ValueMetaBase( "test", ValueMetaInterface.TYPE_NONE );
  valueMetaBase.getValue( XMLHandler.loadXMLString( "<value-data>not empty</value-data>" ).getFirstChild() );
}
 
Example 18
Source File: TableProducer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method is called when a row is written to another step (even if there is no next step)
 *
 * @param rowMeta the metadata of the row
 * @param row     the data of the row
 * @throws org.pentaho.di.core.exception.KettleStepException an exception that can be thrown to hard stop the step
 */
public void rowWrittenEvent( final RowMetaInterface rowMeta, final Object[] row ) throws KettleStepException {
  if ( firstCall ) {
    this.tableModel = createTableModel( rowMeta );
    firstCall = false;
  }

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

  try {
    rowsWritten += 1;

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

      switch( valueMeta.getType() ) {
        case ValueMetaInterface.TYPE_BIGNUMBER:
          dataRow[ columnNo ] = rowMeta.getBigNumber( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_BOOLEAN:
          dataRow[ columnNo ] = rowMeta.getBoolean( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_DATE:
          dataRow[ columnNo ] = rowMeta.getDate( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_INTEGER:
          dataRow[ columnNo ] = rowMeta.getInteger( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_NONE:
          dataRow[ columnNo ] = rowMeta.getString( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_NUMBER:
          dataRow[ columnNo ] = rowMeta.getNumber( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_STRING:
          dataRow[ columnNo ] = rowMeta.getString( row, columnNo );
          break;
        case ValueMetaInterface.TYPE_BINARY:
          dataRow[ columnNo ] = rowMeta.getBinary( row, columnNo );
          break;
        default:
          dataRow[ columnNo ] = rowMeta.getString( row, columnNo );
      }
    }
    tableModel.addRow( dataRow );
  } catch ( final KettleValueException kve ) {
    throw new KettleStepException( kve );
  } catch ( final Exception e ) {
    throw new KettleStepException( e );
  }
}
 
Example 19
Source File: MonetDBBulkLoaderMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void injectStepMetadataEntries( List<StepInjectionMetaEntry> metadata ) {
  for ( StepInjectionMetaEntry entry : metadata ) {
    KettleAttributeInterface attr = findAttribute( entry.getKey() );

    // Set top level attributes...
    //
    if ( entry.getValueType() != ValueMetaInterface.TYPE_NONE ) {

      if ( entry.getKey().equals( "SCHEMA" ) ) {
        schemaName = (String) entry.getValue();
      } else if ( entry.getKey().equals( "TABLE" ) ) {
        tableName = (String) entry.getValue();
      } else if ( entry.getKey().equals( "LOGFILE" ) ) {
        logFile = (String) entry.getValue();
      } else if ( entry.getKey().equals( "FIELD_SEPARATOR" ) ) {
        fieldSeparator = (String) entry.getValue();
      } else if ( entry.getKey().equals( "FIELD_ENCLOSURE" ) ) {
        fieldEnclosure = (String) entry.getValue();
      } else if ( entry.getKey().equals( "NULL_REPRESENTATION" ) ) {
        setNULLrepresentation( (String) entry.getValue() );
      } else if ( entry.getKey().equals( "ENCODING" ) ) {
        encoding = (String) entry.getValue();
      } else if ( entry.getKey().equals( "BUFFER_SIZE" ) ) {
        bufferSize = (String) entry.getValue();
      } else if ( entry.getKey().equals( "TRUNCATE" ) ) {
        truncate = (Boolean) entry.getValue();
      } else if ( entry.getKey().equals( "FULLY_QUOTE_SQL" ) ) {
        fullyQuoteSQL = (Boolean) entry.getValue();
      } else {
        throw new RuntimeException( "Unhandled metadata injection of attribute: "
            + attr.toString() + " - " + attr.getDescription() );
      }
    } else {
      // The data sets...
      //
      if ( attr.getKey().equals( "MAPPINGS" ) ) {
        List<StepInjectionMetaEntry> selectMappings = entry.getDetails();

        fieldTable = new String[selectMappings.size()];
        fieldStream = new String[selectMappings.size()];
        fieldFormatOk = new boolean[selectMappings.size()];

        for ( int row = 0; row < selectMappings.size(); row++ ) {
          StepInjectionMetaEntry selectField = selectMappings.get( row );

          List<StepInjectionMetaEntry> fieldAttributes = selectField.getDetails();
          //CHECKSTYLE:Indentation:OFF
          for ( int i = 0; i < fieldAttributes.size(); i++ ) {
            StepInjectionMetaEntry fieldAttribute = fieldAttributes.get( i );
            KettleAttributeInterface fieldAttr = findAttribute( fieldAttribute.getKey() );

            Object attributeValue = fieldAttribute.getValue();

            if ( attributeValue == null ) {
              continue;
            }

            if ( fieldAttr.getKey().equals( "STREAMNAME" ) ) {
              getFieldStream()[row] = (String) attributeValue;
            } else if ( fieldAttr.getKey().equals( "FIELDNAME" ) ) {
              getFieldTable()[row] = (String) attributeValue;
            } else if ( fieldAttr.getKey().equals( "FIELD_FORMAT_OK" ) ) {
              getFieldFormatOk()[row] = (Boolean) attributeValue;
            } else {
              throw new RuntimeException( "Unhandled metadata injection of attribute: "
                  + fieldAttr.toString() + " - " + fieldAttr.getDescription() );
            }
          }
        }
      }
      if ( !Utils.isEmpty( getFieldStream() ) ) {
        for ( int i = 0; i < getFieldStream().length; i++ ) {
          logDetailed( "row " + Integer.toString( i ) + ": stream=" + getFieldStream()[i]
              + " : table=" + getFieldTable()[i] );
        }
      }

    }
  }
}
 
Example 20
Source File: ValueMetaNone.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ValueMetaNone( String name ) {
  super( name, ValueMetaInterface.TYPE_NONE );
}