Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Issue #40
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcasters committed Jan 27, 2019
1 parent 84807bc commit fc03d58
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/pentaho/di/dataset/DataSetCsvGroup.java
Expand Up @@ -4,6 +4,7 @@
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.csv.QuoteMode;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.vfs2.FileObject;
import org.pentaho.di.core.exception.KettleDatabaseException;
Expand Down Expand Up @@ -110,7 +111,7 @@ public static final List<Object[]> getAllRows( LogChannelInterface log, DataSetG

try (
Reader reader = new InputStreamReader( new BufferedInputStream( KettleVFS.getInputStream( file ) ) );
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT);
CSVParser csvParser = new CSVParser(reader, getCsvFormat( setRowMeta ));
) {
for ( CSVRecord csvRecord : csvParser ) {
if (csvRecord.getRecordNumber()>1) {
Expand Down Expand Up @@ -244,7 +245,8 @@ public static final void writeDataSetData( LoggingObjectInterface loggingObject,
FileObject file = KettleVFS.getFileObject( dataSetFilename );
outputStream = KettleVFS.getOutputStream( file, false );
writer = new BufferedWriter( new OutputStreamWriter( outputStream ) );
csvPrinter = new CSVPrinter( writer, CSVFormat.DEFAULT.withHeader( rowMeta.getFieldNames() ) );
CSVFormat csvFormat = getCsvFormat(rowMeta);
csvPrinter = new CSVPrinter( writer, csvFormat );

for ( Object[] row : rows ) {
List<String> strings = new ArrayList<>();
Expand Down Expand Up @@ -277,6 +279,10 @@ public static final void writeDataSetData( LoggingObjectInterface loggingObject,
}
}

public static CSVFormat getCsvFormat(RowMetaInterface rowMeta) {
return CSVFormat.DEFAULT.withHeader( rowMeta.getFieldNames() ).withQuote( '\"' ).withQuoteMode( QuoteMode.MINIMAL );
}


public static void createTable( DataSetGroup group, String tableName, RowMetaInterface rowMeta ) throws KettleDatabaseException {

Expand Down

0 comments on commit fc03d58

Please sign in to comment.