Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add charset option #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
<version>3.0.4</version>
<configuration>
<skip>${air.check.skip-findbugs}</skip>
<jvmArgs>-Xmx${air.build.jvmsize}</jvmArgs>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/teradata/tpcds/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Options
public static final boolean DEFAULT_NO_SEXISM = false;
public static final int DEFAULT_PARALLELISM = 1;
public static final boolean DEFAULT_OVERWRITE = false;
public static final String DEFAULT_CHARSET = "ISO_8859_1";

@Option(name = {"--scale", "-s"}, title = "scale", description = "Volume of data to generate in GB (Default: 1)")
public double scale = DEFAULT_SCALE;
Expand All @@ -43,6 +44,9 @@ public class Options
@Option(name = {"--table", "-t"}, title = "table", description = "Build only the specified table. If this property is not specified, all tables will be generated")
public String table = DEFAULT_TABLE;

@Option(name = {"--charset"}, title = "charset", description = "Charset used for output files. (Default: ISO_8859_1)")
public String charset = DEFAULT_CHARSET;

@Option(name = {"--null"}, title = "null", description = "String representation for null values (Default: the empty string)")
public String nullString = DEFAULT_NULL_STRING;

Expand Down Expand Up @@ -77,7 +81,8 @@ public Session toSession()
doNotTerminate,
noSexism,
parallelism,
overwrite);
overwrite,
charset);
}

private static Optional<Table> toTableOptional(String table)
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/com/teradata/tpcds/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.Optional;

import static com.teradata.tpcds.Options.DEFAULT_CHARSET;
import static com.teradata.tpcds.Options.DEFAULT_DIRECTORY;
import static com.teradata.tpcds.Options.DEFAULT_DO_NOT_TERMINATE;
import static com.teradata.tpcds.Options.DEFAULT_NO_SEXISM;
Expand All @@ -39,13 +40,14 @@ public class Session
private final int parallelism;
private final int chunkNumber;
private final boolean overwrite;
private final String charset;

public Session(double scale, String targetDirectory, String suffix, Optional<Table> table, String nullString, char separator, boolean doNotTerminate, boolean noSexism, int parallelism, boolean overwrite)
public Session(double scale, String targetDirectory, String suffix, Optional<Table> table, String nullString, char separator, boolean doNotTerminate, boolean noSexism, int parallelism, boolean overwrite, String charset)
{
this(scale, targetDirectory, suffix, table, nullString, separator, doNotTerminate, noSexism, parallelism, 1, overwrite);
this(scale, targetDirectory, suffix, table, nullString, separator, doNotTerminate, noSexism, parallelism, 1, overwrite, charset);
}

public Session(double scale, String targetDirectory, String suffix, Optional<Table> table, String nullString, char separator, boolean doNotTerminate, boolean noSexism, int parallelism, int chunkNumber, boolean overwrite)
public Session(double scale, String targetDirectory, String suffix, Optional<Table> table, String nullString, char separator, boolean doNotTerminate, boolean noSexism, int parallelism, int chunkNumber, boolean overwrite, String charset)
{
this.scaling = new Scaling(scale);
this.targetDirectory = targetDirectory;
Expand All @@ -58,6 +60,7 @@ public Session(double scale, String targetDirectory, String suffix, Optional<Tab
this.parallelism = parallelism;
this.chunkNumber = chunkNumber;
this.overwrite = overwrite;
this.charset = charset;
}

public static Session getDefaultSession()
Expand All @@ -78,7 +81,8 @@ public Session withTable(Table table)
this.noSexism,
this.parallelism,
this.chunkNumber,
this.overwrite
this.overwrite,
this.charset
);
}

Expand All @@ -95,7 +99,8 @@ public Session withScale(double scale)
this.noSexism,
this.parallelism,
this.chunkNumber,
this.overwrite
this.overwrite,
this.charset
);
}

Expand All @@ -112,7 +117,8 @@ public Session withParallelism(int parallelism)
this.noSexism,
parallelism,
this.chunkNumber,
this.overwrite
this.overwrite,
this.charset
);
}

Expand All @@ -129,7 +135,8 @@ public Session withChunkNumber(int chunkNumber)
this.noSexism,
this.parallelism,
chunkNumber,
this.overwrite
this.overwrite,
this.charset
);
}

Expand All @@ -146,7 +153,8 @@ public Session withNoSexism(boolean noSexism)
noSexism,
this.parallelism,
this.chunkNumber,
this.overwrite
this.overwrite,
this.charset
);
}

Expand Down Expand Up @@ -208,6 +216,11 @@ public int getChunkNumber()
return chunkNumber;
}

public String getCharset()
{
return charset;
}

public boolean shouldOverwrite()
{
return overwrite;
Expand Down Expand Up @@ -246,6 +259,9 @@ public String getCommandLineArguments()
if (overwrite != DEFAULT_OVERWRITE) {
output.append("--overwrite ");
}
if (!charset.equals(DEFAULT_CHARSET)) {
output.append("--charset ").append(charset).append(" ");
}

// remove trailing space
if (output.length() > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/teradata/tpcds/TableGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -77,7 +77,7 @@ private OutputStreamWriter addFileWriterForTable(Table table)
}
}

return new OutputStreamWriter(new FileOutputStream(path, true), StandardCharsets.ISO_8859_1);
return new OutputStreamWriter(new FileOutputStream(path, true), Charset.forName(session.getCharset()));
}

private String getPath(Table table)
Expand Down