@Test public void testInputFileSurroundedBySingleQuotes() throws Exception { String datafile = "test-data-file"; loader = new GPBulkLoader( mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans ); DatabaseMeta dbMetaMock = mock( DatabaseMeta.class ); doReturn( "" ).when( dbMetaMock ).getQuotedSchemaTableCombination( anyString(), anyString() ); doReturn( "" ).when( dbMetaMock ).quoteField( anyString() ); GPBulkLoaderMeta meta = new GPBulkLoaderMeta(); meta.setLoadAction( "" ); meta.setFieldStream( new String[] { "" } ); meta.setFieldTable( new String[] { "" } ); meta.setDatabaseMeta( dbMetaMock ); meta.setDataFile( datafile ); String actual = loader.getControlFileContents( meta, null, null ); int first = actual.indexOf( datafile ); if ( first > 0 ) { if ( actual.charAt( first - 1 ) != '\'' || actual.charAt( first + datafile.length() ) != '\'' ) { Assert.fail( "Datafile name is not surrounded by single quotes. Actual control file: " + actual ); } } else { Assert.fail( "Datafile name not found in control file. Actual control file: " + actual ); } }
public String getControlFileContents( GPBulkLoaderMeta meta, RowMetaInterface rm, Object[] r ) throws KettleException { DatabaseMeta dm = meta.getDatabaseMeta(); String inputName = "'" + environmentSubstitute( meta.getDataFile() ) + "'"; String loadAction = meta.getLoadAction(); StringBuffer contents = new StringBuffer( 500 ); String tableName = dm.getQuotedSchemaTableCombination( environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta.getTableName() ) ); if ( loadAction.equalsIgnoreCase( "truncate" ) ) { contents.append( loadAction + " " ); contents.append( tableName + ";" ); contents.append( Const.CR ); } contents.append( "\\COPY " ); contents.append( tableName ); contents.append( " ( " ); String[] streamFields = meta.getFieldStream(); String[] tableFields = meta.getFieldTable(); if ( streamFields == null || streamFields.length == 0 ) { throw new KettleException( "No fields defined to load to database" ); } for ( int i = 0; i < streamFields.length; i++ ) { if ( i != 0 ) { contents.append( ", " ); } contents.append( dm.quoteField( tableFields[i] ) ); } contents.append( " ) " ); contents.append( " FROM " ); contents.append( inputName ); contents.append( " WITH CSV " ); contents.append( "LOG ERRORS INTO " ); contents.append( tableName + "_errors " ); contents.append( " SEGMENT REJECT LIMIT " ); contents.append( meta.getMaxErrors() ); return contents.toString(); }
GPBulkLoader extends BaseStep implements StepInterface { public String getControlFileContents( GPBulkLoaderMeta meta, RowMetaInterface rm, Object[] r ) throws KettleException { DatabaseMeta dm = meta.getDatabaseMeta(); String inputName = "'" + environmentSubstitute( meta.getDataFile() ) + "'"; String loadAction = meta.getLoadAction(); StringBuffer contents = new StringBuffer( 500 ); String tableName = dm.getQuotedSchemaTableCombination( environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta.getTableName() ) ); if ( loadAction.equalsIgnoreCase( "truncate" ) ) { contents.append( loadAction + " " ); contents.append( tableName + ";" ); contents.append( Const.CR ); } contents.append( "\\COPY " ); contents.append( tableName ); contents.append( " ( " ); String[] streamFields = meta.getFieldStream(); String[] tableFields = meta.getFieldTable(); if ( streamFields == null || streamFields.length == 0 ) { throw new KettleException( "No fields defined to load to database" ); } for ( int i = 0; i < streamFields.length; i++ ) { if ( i != 0 ) { contents.append( ", " ); } contents.append( dm.quoteField( tableFields[i] ) ); } contents.append( " ) " ); contents.append( " FROM " ); contents.append( inputName ); contents.append( " WITH CSV " ); contents.append( "LOG ERRORS INTO " ); contents.append( tableName + "_errors " ); contents.append( " SEGMENT REJECT LIMIT " ); contents.append( meta.getMaxErrors() ); return contents.toString(); } }
GPBulkLoader extends BaseStep implements StepInterface { public String getControlFileContents( GPBulkLoaderMeta meta, RowMetaInterface rm, Object[] r ) throws KettleException { DatabaseMeta dm = meta.getDatabaseMeta(); String inputName = "'" + environmentSubstitute( meta.getDataFile() ) + "'"; String loadAction = meta.getLoadAction(); StringBuffer contents = new StringBuffer( 500 ); String tableName = dm.getQuotedSchemaTableCombination( environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta.getTableName() ) ); if ( loadAction.equalsIgnoreCase( "truncate" ) ) { contents.append( loadAction + " " ); contents.append( tableName + ";" ); contents.append( Const.CR ); } contents.append( "\\COPY " ); contents.append( tableName ); contents.append( " ( " ); String[] streamFields = meta.getFieldStream(); String[] tableFields = meta.getFieldTable(); if ( streamFields == null || streamFields.length == 0 ) { throw new KettleException( "No fields defined to load to database" ); } for ( int i = 0; i < streamFields.length; i++ ) { if ( i != 0 ) { contents.append( ", " ); } contents.append( dm.quoteField( tableFields[i] ) ); } contents.append( " ) " ); contents.append( " FROM " ); contents.append( inputName ); contents.append( " WITH CSV " ); contents.append( "LOG ERRORS INTO " ); contents.append( tableName + "_errors " ); contents.append( " SEGMENT REJECT LIMIT " ); contents.append( meta.getMaxErrors() ); return contents.toString(); } GPBulkLoader( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); }
GPBulkLoader extends BaseStep implements StepInterface { public String getControlFileContents( GPBulkLoaderMeta meta, RowMetaInterface rm, Object[] r ) throws KettleException { DatabaseMeta dm = meta.getDatabaseMeta(); String inputName = "'" + environmentSubstitute( meta.getDataFile() ) + "'"; String loadAction = meta.getLoadAction(); StringBuffer contents = new StringBuffer( 500 ); String tableName = dm.getQuotedSchemaTableCombination( environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta.getTableName() ) ); if ( loadAction.equalsIgnoreCase( "truncate" ) ) { contents.append( loadAction + " " ); contents.append( tableName + ";" ); contents.append( Const.CR ); } contents.append( "\\COPY " ); contents.append( tableName ); contents.append( " ( " ); String[] streamFields = meta.getFieldStream(); String[] tableFields = meta.getFieldTable(); if ( streamFields == null || streamFields.length == 0 ) { throw new KettleException( "No fields defined to load to database" ); } for ( int i = 0; i < streamFields.length; i++ ) { if ( i != 0 ) { contents.append( ", " ); } contents.append( dm.quoteField( tableFields[i] ) ); } contents.append( " ) " ); contents.append( " FROM " ); contents.append( inputName ); contents.append( " WITH CSV " ); contents.append( "LOG ERRORS INTO " ); contents.append( tableName + "_errors " ); contents.append( " SEGMENT REJECT LIMIT " ); contents.append( meta.getMaxErrors() ); return contents.toString(); } GPBulkLoader( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); String getControlFileContents( GPBulkLoaderMeta meta, RowMetaInterface rm, Object[] r ); void createControlFile( String filename, Object[] row, GPBulkLoaderMeta meta ); String createCommandLine( GPBulkLoaderMeta meta, boolean password ); boolean execute( GPBulkLoaderMeta meta, boolean wait ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }
GPBulkLoader extends BaseStep implements StepInterface { public String getControlFileContents( GPBulkLoaderMeta meta, RowMetaInterface rm, Object[] r ) throws KettleException { DatabaseMeta dm = meta.getDatabaseMeta(); String inputName = "'" + environmentSubstitute( meta.getDataFile() ) + "'"; String loadAction = meta.getLoadAction(); StringBuffer contents = new StringBuffer( 500 ); String tableName = dm.getQuotedSchemaTableCombination( environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta.getTableName() ) ); if ( loadAction.equalsIgnoreCase( "truncate" ) ) { contents.append( loadAction + " " ); contents.append( tableName + ";" ); contents.append( Const.CR ); } contents.append( "\\COPY " ); contents.append( tableName ); contents.append( " ( " ); String[] streamFields = meta.getFieldStream(); String[] tableFields = meta.getFieldTable(); if ( streamFields == null || streamFields.length == 0 ) { throw new KettleException( "No fields defined to load to database" ); } for ( int i = 0; i < streamFields.length; i++ ) { if ( i != 0 ) { contents.append( ", " ); } contents.append( dm.quoteField( tableFields[i] ) ); } contents.append( " ) " ); contents.append( " FROM " ); contents.append( inputName ); contents.append( " WITH CSV " ); contents.append( "LOG ERRORS INTO " ); contents.append( tableName + "_errors " ); contents.append( " SEGMENT REJECT LIMIT " ); contents.append( meta.getMaxErrors() ); return contents.toString(); } GPBulkLoader( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); String getControlFileContents( GPBulkLoaderMeta meta, RowMetaInterface rm, Object[] r ); void createControlFile( String filename, Object[] row, GPBulkLoaderMeta meta ); String createCommandLine( GPBulkLoaderMeta meta, boolean password ); boolean execute( GPBulkLoaderMeta meta, boolean wait ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi );  }