SqlTransGenerator { private StepMeta generateIifStep( SQLField iifField, TransMeta transMeta, StepMeta lastStep ) { IifFunction iif = iifField.getIif(); FilterRowsMeta filterMeta = new FilterRowsMeta(); filterMeta.setCondition( iifField.getIif().getSqlCondition().getCondition() ); StepMeta filterStep = new StepMeta( iifField.getExpression(), filterMeta ); filterStep.setLocation( xLocation, 50 ); xLocation += 100; filterStep.setDraw( true ); lastStep = addToTrans( filterStep, transMeta, lastStep ); StepMetaInterface trueMetaInterface; ValueMetaInterface valueMeta = iif.getTrueValue().getValueMeta(); if ( iif.isTrueField() ) { CalculatorMeta trueMeta = new CalculatorMeta(); trueMetaInterface = trueMeta; trueMeta.allocate( 1 ); CalculatorMetaFunction function = new CalculatorMetaFunction(); function.setFieldName( Const.NVL( iifField.getAlias(), iifField.getField() ) ); function.setCalcType( CalculatorMetaFunction.CALC_COPY_OF_FIELD ); function.setValueType( valueMeta.getType() ); function.setValueLength( valueMeta.getLength() ); function.setValuePrecision( valueMeta.getPrecision() ); function.setFieldA( iif.getTrueValueString() ); function.setConversionMask( valueMeta.getConversionMask() ); trueMeta.getCalculation()[0] = function; } else { ConstantMeta trueMeta = new ConstantMeta(); trueMetaInterface = trueMeta; trueMeta.allocate( 1 ); trueMeta.getFieldName()[0] = Const.NVL( iifField.getAlias(), iifField.getField() ); trueMeta.getFieldType()[0] = iif.getTrueValue().getValueMeta().getTypeDesc(); trueMeta.getValue()[0] = iif.getTrueValue().toString(); trueMeta.getFieldFormat()[0] = valueMeta.getConversionMask(); } StepMeta trueStep = new StepMeta( "TRUE: " + iifField.getExpression(), trueMetaInterface ); trueStep.setLocation( xLocation, 50 ); trueStep.setDraw( true ); lastStep = addToTrans( trueStep, transMeta, filterStep ); StepMetaInterface falseMetaInterface; valueMeta = iif.getFalseValue().getValueMeta(); if ( iif.isFalseField() ) { CalculatorMeta falseMeta = new CalculatorMeta(); falseMetaInterface = falseMeta; falseMeta.allocate( 1 ); CalculatorMetaFunction function = new CalculatorMetaFunction(); function.setFieldName( Const.NVL( iifField.getAlias(), iifField.getField() ) ); function.setCalcType( CalculatorMetaFunction.CALC_COPY_OF_FIELD ); function.setValueType( valueMeta.getType() ); function.setValueLength( valueMeta.getLength() ); function.setValuePrecision( valueMeta.getPrecision() ); function.setFieldA( iif.getFalseValueString() ); function.setConversionMask( valueMeta.getConversionMask() ); falseMeta.getCalculation()[0] = function; } else { ConstantMeta falseMeta = new ConstantMeta(); falseMetaInterface = falseMeta; falseMeta.allocate( 1 ); falseMeta.getFieldName()[0] = Const.NVL( iifField.getAlias(), iifField.getField() ); falseMeta.getFieldType()[0] = iif.getFalseValue().getValueMeta().getTypeDesc(); falseMeta.getFieldFormat()[0] = valueMeta.getConversionMask(); falseMeta.getValue()[0] = iif.getFalseValue().toString(); } StepMeta falseStep = new StepMeta( "FALSE: " + iifField.getExpression(), falseMetaInterface ); falseStep.setLocation( xLocation, 150 ); xLocation += 100; falseStep.setDraw( true ); lastStep = addToTrans( falseStep, transMeta, filterStep ); List<StreamInterface> targetStreams = filterMeta.getStepIOMeta().getTargetStreams(); targetStreams.get( 0 ).setSubject( trueStep.getName() ); targetStreams.get( 1 ).setSubject( falseStep.getName() ); filterMeta.searchInfoAndTargetSteps( transMeta.getSteps() ); DummyTransMeta dummyMeta = new DummyTransMeta(); StepMeta dummyStep = new StepMeta( "Collect: " + iifField.getExpression(), dummyMeta ); dummyStep.setLocation( xLocation, 50 ); xLocation += 100; dummyStep.setDraw( true ); lastStep = addToTrans( dummyStep, transMeta, trueStep ); transMeta.addTransHop( new TransHopMeta( falseStep, dummyStep ) ); return lastStep; } SqlTransGenerator( SQL sql, int rowLimit );  SqlTransGenerator( SQL sql, int rowLimit, int serviceLimit ); TransMeta generateTransMeta(); SQL getSql(); String getInjectorStepName(); void setInjectorStepName( String injectorStepName ); String getResultStepName(); void setResultStepName( String resultStepName ); int getRowLimit(); int getServiceRowLimit();  }
@Test public void testGenerateIifStep() throws KettleException { SQL sql = new SQL( "SELECT IIF(10 > 1, 'TRUE', 'FALSE') FROM table" ); RowMetaInterface rowMeta = new RowMeta(); rowMeta.addValueMeta( new ValueMetaInteger( "foo" ) ); sql.parse( rowMeta ); SqlTransGenerator generator = new SqlTransGenerator( sql, 0 ); SelectValuesMeta selectValuesMeta = getSelectStepValuesMeta( generator.generateTransMeta() ); assertThat( selectValuesMeta.getSelectName(), equalTo( new String[] { "IIF(10 > 1, 'TRUE', 'FALSE')" } ) ); assertThat( selectValuesMeta.getSelectRename(), equalTo( new String[] { null } ) ); }