Skip to content

Commit

Permalink
[BACKLOG-9795] - Add Metadata Injection (MDI) support to the Dimensio…
Browse files Browse the repository at this point in the history
…n lookup/update Step - add TYPE_OF_RETURN_FIELD property (#3391)

[BACKLOG-9795] - Add Metadata Injection (MDI) support to the Dimension lookup/update Step - update test
  • Loading branch information
AndreyBurikhin authored and Ben Morrise committed Jan 23, 2017
1 parent 10c4b35 commit f09c19f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -1699,7 +1699,7 @@ public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
data = (DimensionLookupData) sdi;

if ( super.init( smi, sdi ) ) {
meta.normalizeAllocationFields();
meta.actualizeWithInjectedValues();
data.min_date = meta.getMinDate();
data.max_date = meta.getMaxDate();

Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -174,6 +174,9 @@ public class DimensionLookupMeta extends BaseStepMeta implements StepMetaInterfa
@Injection( name = "UPDATE_TYPE", group = "FIELDS", converter = UpdateTypeCodeConverter.class )
private int[] fieldUpdate;

@Injection( name = "TYPE_OF_RETURN_FIELD", group = "FIELDS", converter = ReturnTypeCodeConverter.class )
private int[] returnType = {};

/** Name of the technical key (surrogate key) field to return from the dimension */
@Injection( name = "TECHNICAL_KEY_FIELD" )
private String keyField;
Expand Down Expand Up @@ -430,6 +433,21 @@ public void setFieldUpdate( int[] fieldUpdate ) {
this.fieldUpdate = fieldUpdate;
}

/**
* @return Returns the returnType.
*/
public int[] getReturnType() {
return returnType;
}

/**
* @param returnType
* The returnType to set.
*/
public void setReturnType( int[] returnType ) {
this.returnType = returnType;
}

/**
* @return Returns the keyField.
*/
Expand Down Expand Up @@ -550,6 +568,13 @@ public void setVersionField( String versionField ) {
this.versionField = versionField;
}

public void actualizeWithInjectedValues() {
if ( !update && returnType.length > 0 ) {
fieldUpdate = returnType;
}
normalizeAllocationFields();
}

@Override
public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException {
readData( stepnode, databases );
Expand All @@ -562,6 +587,7 @@ public void allocate( int nrkeys, int nrfields ) {
fieldStream = new String[nrfields];
fieldLookup = new String[nrfields];
fieldUpdate = new int[nrfields];
returnType = new int[nrfields];
}

@Override
Expand All @@ -579,6 +605,7 @@ public Object clone() {
System.arraycopy( fieldStream, 0, retval.fieldStream, 0, nrfields );
System.arraycopy( fieldLookup, 0, retval.fieldLookup, 0, nrfields );
System.arraycopy( fieldUpdate, 0, retval.fieldUpdate, 0, nrfields );
System.arraycopy( returnType, 0, retval.returnType, 0, nrfields );

return retval;
}
Expand Down Expand Up @@ -802,7 +829,7 @@ public void getFields( RowMetaInterface row, String name, RowMetaInterface[] inf

@Override
public String getXML() {
normalizeAllocationFields();
actualizeWithInjectedValues();
StringBuilder retval = new StringBuilder( 512 );

retval.append( " " ).append( XMLHandler.addTagValue( "schema", schemaName ) );
Expand Down Expand Up @@ -1927,6 +1954,7 @@ public void normalizeAllocationFields() {
int fieldsGroupSize = fieldLookup.length;
fieldStream = normalizeAllocation( fieldStream, fieldsGroupSize );
fieldUpdate = normalizeAllocation( fieldUpdate, fieldsGroupSize );
returnType = normalizeAllocation( returnType, fieldsGroupSize );
}
}

Expand Down Expand Up @@ -1972,4 +2000,11 @@ public int string2intPrimitive( String v ) throws KettleValueException {
}
}

public static class ReturnTypeCodeConverter extends InjectionTypeConverter {
@Override
public int string2intPrimitive( String v ) throws KettleValueException {
return DimensionLookupMeta.getUpdateType( false, v );
}
}

}
Expand Up @@ -184,6 +184,7 @@ DimensionLookup.Injection.FIELDS=Fields
DimensionLookup.Injection.DATABASE_FIELDNAME=The database table field name.
DimensionLookup.Injection.STREAM_FIELDNAME=The name of the field in the stream.
DimensionLookup.Injection.UPDATE_TYPE=Specify the type.
DimensionLookup.Injection.TYPE_OF_RETURN_FIELD=Specify the type.
DimensionLookup.Injection.STREAM_DATE_FIELD=The stream date field.
DimensionLookup.Injection.DATE_RANGE_START_FIELD=The name of the date range start field.
DimensionLookup.Injection.DATE_RANGE_END_FIELD=The name of the date range end field.
Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2016-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -27,6 +27,7 @@
import org.junit.Test;
import org.pentaho.di.core.injection.BaseMetadataInjectionTest;
import org.pentaho.di.core.row.ValueMetaInterface;
import org.pentaho.di.core.row.value.ValueMetaFactory;
import org.pentaho.di.core.row.value.ValueMetaString;

public class DimensionLookupMetaInjectionTest extends BaseMetadataInjectionTest<DimensionLookupMeta> {
Expand Down Expand Up @@ -181,6 +182,14 @@ public String get() {
.getStartDateAlternativeCode( 0 ) ), "f" );
Assert.assertEquals( 0, meta.getStartDateAlternative() );

String[] valueMetaNames = ValueMetaFactory.getValueMetaNames();
checkStringToInt( "TYPE_OF_RETURN_FIELD", new IntGetter() {
@Override
public int get() {
return meta.getReturnType()[0];
}
}, valueMetaNames, getTypeCodes( valueMetaNames ) );

skipPropertyTest( "ALTERNATIVE_START_OPTION" );

skipPropertyTest( "UPDATE_TYPE" );
Expand Down
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -1350,10 +1350,16 @@ public void getData() {
// key creation.
if ( DimensionLookupMeta.CREATION_METHOD_AUTOINC.equals( techKeyCreation ) ) {
wAutoinc.setSelection( true );
wSeqButton.setSelection( false );
wTableMax.setSelection( false );
} else if ( ( DimensionLookupMeta.CREATION_METHOD_SEQUENCE.equals( techKeyCreation ) ) ) {
wSeqButton.setSelection( true );
wAutoinc.setSelection( false );
wTableMax.setSelection( false );
} else { // the rest
wTableMax.setSelection( true );
wAutoinc.setSelection( false );
wSeqButton.setSelection( false );
input.setTechKeyCreation( DimensionLookupMeta.CREATION_METHOD_TABLEMAX );
}
if ( input.getSequenceName() != null ) {
Expand Down

0 comments on commit f09c19f

Please sign in to comment.