Skip to content

Commit

Permalink
[BACKLOG-21186] Fixed sorting step metrics (#5241)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricksjames authored and Kurtis Walker committed Apr 16, 2018
1 parent 60d6c47 commit 788ee2c
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 102 deletions.
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -1325,4 +1325,20 @@ void setPreparedStatementValue( DatabaseMeta databaseMeta, PreparedStatement pre
String getDatabaseColumnTypeDefinition( DatabaseInterface databaseInterface, String tk, String pk,
boolean use_autoinc, boolean add_fieldname, boolean add_cr );

/**
* Is Ignore Whitespace
* Only applicable for TYPE_STRING comparisons
*
* @return true if whitespace should be ignored during string comparison
*/
boolean isIgnoreWhitespace();

/**
* Set Ignore Whitespace
* Only applicable for TYPE_STRING comparisons
*
* @param ignoreWhitespace true if whitespace should be ignored during string comparison
*/
void setIgnoreWhitespace( boolean ignoreWhitespace );

}
Expand Up @@ -177,6 +177,8 @@ public class ValueMetaBase implements ValueMetaInterface {
protected int originalNullable;
protected boolean originalSigned;

protected boolean ignoreWhitespace;

private static final LogChannelInterface log = KettleLogStore.getLogChannelInterfaceFactory().create( "ValueMetaBase" );

/**
Expand Down Expand Up @@ -3631,6 +3633,11 @@ public int compare( Object data1, Object data2 ) throws KettleValueException {
String one = getString( data1 );
String two = getString( data2 );

if ( ignoreWhitespace ) {
one = one.trim();
two = two.trim();
}

if ( collatorDisabled ) {
if ( caseInsensitive ) {
cmp = one.compareToIgnoreCase( two );
Expand Down Expand Up @@ -4600,6 +4607,16 @@ public void setDateFormatTimeZone( TimeZone dateFormatTimeZone ) {
dateFormatChanged = true;
}

@Override
public boolean isIgnoreWhitespace() {
return ignoreWhitespace;
}

@Override
public void setIgnoreWhitespace( boolean ignoreWhitespace ) {
this.ignoreWhitespace = ignoreWhitespace;
}

@Override
public void drawValue( PrimitiveGCInterface gc, Object value ) throws KettleValueException {
// Just draw the string by default.
Expand Down
Expand Up @@ -504,6 +504,65 @@ public void testCompare_emptyIsNotNull() throws KettleValueException {
assertSignum( 0, meta.compare( "1 ", " 1 " ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1 ", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1 ", "1 " ) ); // "1" == "1"

meta.setTrimType( ValueMetaInterface.TRIM_TYPE_NONE );
meta.setIgnoreWhitespace( true );

assertSignum( 0, meta.compare( null, null ) ); // null == null
assertSignum( -1, meta.compare( null, "" ) ); // null < ""
assertSignum( -1, meta.compare( null, " " ) ); // null < ""
assertSignum( -1, meta.compare( null, " 1" ) ); // null < "1"
assertSignum( -1, meta.compare( null, " 1 " ) ); // null < "1"
assertSignum( -1, meta.compare( null, "1" ) ); // null < "1"
assertSignum( -1, meta.compare( null, "1 " ) ); // null < "1"

assertSignum( 1, meta.compare( "", null ) ); // "" > null
assertSignum( 0, meta.compare( "", "" ) ); // "" == ""
assertSignum( 0, meta.compare( "", " " ) ); // "" == ""
assertSignum( -1, meta.compare( "", " 1" ) ); // "" < "1"
assertSignum( -1, meta.compare( "", " 1 " ) ); // "" < "1"
assertSignum( -1, meta.compare( "", "1" ) ); // "" < "1"
assertSignum( -1, meta.compare( "", "1 " ) ); // "" < "1"

assertSignum( 1, meta.compare( " ", null ) ); // "" > null
assertSignum( 0, meta.compare( " ", "" ) ); // "" == ""
assertSignum( 0, meta.compare( " ", " " ) ); // "" == ""
assertSignum( -1, meta.compare( " ", " 1" ) ); // "" < "1"
assertSignum( -1, meta.compare( " ", " 1 " ) ); // "" < "1"
assertSignum( -1, meta.compare( " ", "1" ) ); // "" < "1"
assertSignum( -1, meta.compare( " ", "1 " ) ); // "" < "1"

assertSignum( 1, meta.compare( " 1", null ) ); // "1" > null
assertSignum( 1, meta.compare( " 1", "" ) ); // "1" > ""
assertSignum( 1, meta.compare( " 1", " " ) ); // "1" > ""
assertSignum( 0, meta.compare( " 1", " 1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1", " 1 " ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1", "1 " ) ); // "1" == "1"

assertSignum( 1, meta.compare( " 1 ", null ) ); // "1" > null
assertSignum( 1, meta.compare( " 1 ", "" ) ); // "1" > ""
assertSignum( 1, meta.compare( " 1 ", " " ) ); // "1" > ""
assertSignum( 0, meta.compare( " 1 ", " 1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1 ", " 1 " ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1 ", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1 ", "1 " ) ); // "1" == "1"

assertSignum( 1, meta.compare( "1", null ) ); // "1" > null
assertSignum( 1, meta.compare( "1", "" ) ); // "1" > ""
assertSignum( 1, meta.compare( "1", " " ) ); // "1" > ""
assertSignum( 0, meta.compare( "1", " 1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1", " 1 " ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1", "1 " ) ); // "1" == "1"

assertSignum( 1, meta.compare( "1 ", null ) ); // "1" > null
assertSignum( 1, meta.compare( "1 ", "" ) ); // "1" > ""
assertSignum( 1, meta.compare( "1 ", " " ) ); // "1" > ""
assertSignum( 0, meta.compare( "1 ", " 1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1 ", " 1 " ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1 ", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1 ", "1 " ) ); // "1" == "1"
}

@Test
Expand Down Expand Up @@ -753,7 +812,64 @@ public void testCompare_emptyIsNull() throws KettleValueException {
assertSignum( 0, meta.compare( "1 ", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1 ", "1 " ) ); // "1" == "1"

meta.setTrimType( ValueMetaInterface.TRIM_TYPE_NONE );
meta.setIgnoreWhitespace( true );

assertSignum( 0, meta.compare( null, null ) ); // null == null
assertSignum( 0, meta.compare( null, "" ) ); // null == null
assertSignum( -1, meta.compare( null, " " ) ); // null < null //TODO: Is it correct?
assertSignum( -1, meta.compare( null, " 1" ) ); // null < "1"
assertSignum( -1, meta.compare( null, " 1 " ) ); // null < "1"
assertSignum( -1, meta.compare( null, "1" ) ); // null < "1"
assertSignum( -1, meta.compare( null, "1 " ) ); // null < "1"

assertSignum( 0, meta.compare( "", null ) ); // null == null
assertSignum( 0, meta.compare( "", "" ) ); // null == null
assertSignum( -1, meta.compare( "", " " ) ); // null < null //TODO: Is it correct?
assertSignum( -1, meta.compare( "", " 1" ) ); // null < "1"
assertSignum( -1, meta.compare( "", " 1 " ) ); // null < "1"
assertSignum( -1, meta.compare( "", "1" ) ); // null < "1"
assertSignum( -1, meta.compare( "", "1 " ) ); // null < "1"

assertSignum( 1, meta.compare( " ", null ) ); // null > null //TODO: Is it correct?
assertSignum( 1, meta.compare( " ", "" ) ); // null > null //TODO: Is it correct?
assertSignum( 0, meta.compare( " ", " " ) ); // null == null
assertSignum( -1, meta.compare( " ", " 1" ) ); // null < "1"
assertSignum( -1, meta.compare( " ", " 1 " ) ); // null < "1"
assertSignum( -1, meta.compare( " ", "1" ) ); // null < "1"
assertSignum( -1, meta.compare( " ", "1 " ) ); // null < "1"

assertSignum( 1, meta.compare( " 1", null ) ); // "1" > null
assertSignum( 1, meta.compare( " 1", "" ) ); // "1" > null
assertSignum( 1, meta.compare( " 1", " " ) ); // "1" > null
assertSignum( 0, meta.compare( " 1", " 1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1", " 1 " ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1", "1 " ) ); // "1" == "1"

assertSignum( 1, meta.compare( " 1 ", null ) ); // "1" > null
assertSignum( 1, meta.compare( " 1 ", "" ) ); // "1" > null
assertSignum( 1, meta.compare( " 1 ", " " ) ); // "1" > null
assertSignum( 0, meta.compare( " 1 ", " 1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1 ", " 1 " ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1 ", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( " 1 ", "1 " ) ); // "1" == "1"

assertSignum( 1, meta.compare( "1", null ) ); // "1" > null
assertSignum( 1, meta.compare( "1", "" ) ); // "1" > null
assertSignum( 1, meta.compare( "1", " " ) ); // "1" > null
assertSignum( 0, meta.compare( "1", " 1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1", " 1 " ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1", "1 " ) ); // "1" == "1"

assertSignum( 1, meta.compare( "1 ", null ) ); // "1" > null
assertSignum( 1, meta.compare( "1 ", "" ) ); // "1" > null
assertSignum( 1, meta.compare( "1 ", " " ) ); // "1" > null
assertSignum( 0, meta.compare( "1 ", " 1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1 ", " 1 " ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1 ", "1" ) ); // "1" == "1"
assertSignum( 0, meta.compare( "1 ", "1 " ) ); // "1" == "1"
}

@Test
Expand Down
7 changes: 0 additions & 7 deletions ui/src/main/java/org/pentaho/di/ui/core/widget/TableView.java
Expand Up @@ -159,7 +159,6 @@ public interface TableViewModifyListener {
private boolean sortable;
private int lastRowCount;
private boolean fieldChanged;
private boolean insertImage;

private Menu mRow;

Expand Down Expand Up @@ -1316,9 +1315,6 @@ public void setSelection( int[] selectedItems ) {
}

public void sortTable( int sortField, boolean sortingDescending ) {
sortTable( sortField, sortingDescending, true );
}
public void sortTable( int sortField, boolean sortingDescending, boolean resetRowNums ) {
boolean shouldRefresh = false;
if ( this.sortfieldLast == -1 && this.sortingDescendingLast == null ) {
// first time through, so update
Expand Down Expand Up @@ -1482,9 +1478,6 @@ public int compare( Object[] r1, Object[] r2 ) {
table.setSortDirection( sortingDescending ? SWT.DOWN : SWT.UP );

lastRowCount = table.getItemCount();
if ( resetRowNums ) {
setRowNums();
}
} catch ( Exception e ) {
new ErrorDialog( this.getShell(), BaseMessages.getString( PKG, "TableView.ErrorDialog.title" ), BaseMessages
.getString( PKG, "TableView.ErrorDialog.description" ), e );
Expand Down

0 comments on commit 788ee2c

Please sign in to comment.