From 84194de998e5ceffd95373526450e872d6a8045e Mon Sep 17 00:00:00 2001 From: Bruno Costa Date: Tue, 1 Sep 2020 20:52:54 +0100 Subject: [PATCH] [PDI-18869] - "TPT Bulk Loader" step is Missing SET operator in the Script --- .../TeraDataBulkLoaderRoutines.java | 5 ++-- .../TeraDataBulkLoaderRoutinesTest.java | 25 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/pentaho/di/trans/steps/teradatabulkloader/TeraDataBulkLoaderRoutines.java b/core/src/main/java/org/pentaho/di/trans/steps/teradatabulkloader/TeraDataBulkLoaderRoutines.java index a886a53fd..f974a1b16 100644 --- a/core/src/main/java/org/pentaho/di/trans/steps/teradatabulkloader/TeraDataBulkLoaderRoutines.java +++ b/core/src/main/java/org/pentaho/di/trans/steps/teradatabulkloader/TeraDataBulkLoaderRoutines.java @@ -132,11 +132,12 @@ private String createInsertCommand( boolean isPreview ) { * * @return the string */ - private String createUpsertCommand( boolean isPreview ) { + @VisibleForTesting + String createUpsertCommand( boolean isPreview ) { StringBuffer updatecmd = new StringBuffer(); StringBuffer insertcmd = new StringBuffer(); - updatecmd.append( " UPDATE " + getTargetSchema( isPreview ) + '.' + ( isPreview ? this.meta.getTableName() : parent.environmentSubstitute( this.meta.getTableName() ) + " SET\n" ) ); + updatecmd.append( " UPDATE " + getTargetSchema( isPreview ) + '.' + ( isPreview ? this.meta.getTableName() : parent.environmentSubstitute( this.meta.getTableName() ) ) + " SET\n" ); String[] fieldTable = this.meta.getFieldTable(); String[] fieldStream = this.meta.getFieldStream(); Boolean[] fieldUpdate = this.meta.getFieldUpdate(); diff --git a/core/src/test/java/org/pentaho/di/trans/steps/teradatabulkloader/TeraDataBulkLoaderRoutinesTest.java b/core/src/test/java/org/pentaho/di/trans/steps/teradatabulkloader/TeraDataBulkLoaderRoutinesTest.java index a8e1fd1d5..374af7e31 100644 --- a/core/src/test/java/org/pentaho/di/trans/steps/teradatabulkloader/TeraDataBulkLoaderRoutinesTest.java +++ b/core/src/test/java/org/pentaho/di/trans/steps/teradatabulkloader/TeraDataBulkLoaderRoutinesTest.java @@ -2,7 +2,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2020 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -27,6 +27,7 @@ import org.pentaho.di.core.variables.Variables; import java.io.File; +import java.util.UUID; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -269,4 +270,26 @@ public void getDropTablesTest() { String dropTables = teraDataBulkLoaderRoutines.getDropTables( true ); assertEquals( expectedDropTables, dropTables ); } + + @Test + public void testCreateUpsertCommandPreview() { + + String tableName = UUID.randomUUID().toString(); + String schemaName = UUID.randomUUID().toString(); + + String[] fieldTable = new String[] {}; + String[] fieldStream = new String[] {}; + Boolean[] fieldUpdate = new Boolean[] {}; + + when( teraDataBulkLoaderMetaMock.getSchemaName() ).thenReturn( schemaName ); + when( teraDataBulkLoaderMetaMock.getTableName() ).thenReturn( tableName ); + when( teraDataBulkLoaderMetaMock.getFieldTable() ).thenReturn( fieldTable ); + when( teraDataBulkLoaderMetaMock.getFieldStream() ).thenReturn( fieldStream ); + when( teraDataBulkLoaderMetaMock.getFieldUpdate() ).thenReturn( fieldUpdate ); + when( teraDataBulkLoaderMetaMock.getKeyStream() ).thenReturn( new String[] {} ); + + String upsertCommand = this.teraDataBulkLoaderRoutines.createUpsertCommand( true ); + assertEquals( true, upsertCommand.startsWith( "' UPDATE " + schemaName + "." + tableName + " SET\n" ) ); + + } }