-
Notifications
You must be signed in to change notification settings - Fork 41
Fixes #24 - Teach Table Generator how to write to a HDFS file. #25
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,10 @@ | |
|
||
package com.teradata.tpcds; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.Optional; | ||
|
||
import static com.teradata.tpcds.Options.DEFAULT_DIRECTORY; | ||
|
@@ -26,38 +30,48 @@ | |
import static com.teradata.tpcds.Options.DEFAULT_SEPARATOR; | ||
import static com.teradata.tpcds.Options.DEFAULT_SUFFIX; | ||
|
||
public class Session | ||
public class Session implements Serializable | ||
{ | ||
private final Scaling scaling; | ||
private final String targetDirectory; | ||
private final String suffix; | ||
private final Optional<Table> table; | ||
private final Table table; | ||
private final String nullString; | ||
private final char separator; | ||
private final boolean doNotTerminate; | ||
private final boolean noSexism; | ||
private final int parallelism; | ||
private final int chunkNumber; | ||
private final boolean overwrite; | ||
private final SerializableHadoopConfiguration hadoopConfig; | ||
|
||
public Session(double scale, String targetDirectory, String suffix, Optional<Table> table, String nullString, char separator, boolean doNotTerminate, boolean noSexism, int parallelism, boolean overwrite) | ||
{ | ||
this(scale, targetDirectory, suffix, table, nullString, separator, doNotTerminate, noSexism, parallelism, 1, 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) | ||
{ | ||
this(scale, targetDirectory, suffix, table, nullString, separator, doNotTerminate, noSexism, parallelism, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the function arguments don't fit nicely on one line, can you put one per line?
|
||
chunkNumber, overwrite, null); | ||
} | ||
|
||
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, Configuration hadoopConfig) | ||
{ | ||
this.scaling = new Scaling(scale); | ||
this.targetDirectory = targetDirectory; | ||
this.suffix = suffix; | ||
this.table = table; | ||
this.table = table.isPresent() ? table.get() : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while you're here, it would be great to add |
||
this.nullString = nullString; | ||
this.separator = separator; | ||
this.doNotTerminate = doNotTerminate; | ||
this.noSexism = noSexism; | ||
this.parallelism = parallelism; | ||
this.chunkNumber = chunkNumber; | ||
this.overwrite = overwrite; | ||
this.hadoopConfig = new SerializableHadoopConfiguration(hadoopConfig); | ||
} | ||
|
||
public static Session getDefaultSession() | ||
|
@@ -71,7 +85,7 @@ public Session withTable(Table table) | |
this.scaling.getScale(), | ||
this.targetDirectory, | ||
this.suffix, | ||
Optional.of(table), | ||
Optional.ofNullable(table), | ||
this.nullString, | ||
this.separator, | ||
this.doNotTerminate, | ||
|
@@ -88,7 +102,7 @@ public Session withScale(double scale) | |
scale, | ||
this.targetDirectory, | ||
this.suffix, | ||
this.table, | ||
Optional.ofNullable(this.table), | ||
this.nullString, | ||
this.separator, | ||
this.doNotTerminate, | ||
|
@@ -105,7 +119,7 @@ public Session withParallelism(int parallelism) | |
this.scaling.getScale(), | ||
this.targetDirectory, | ||
this.suffix, | ||
this.table, | ||
Optional.ofNullable(this.table), | ||
this.nullString, | ||
this.separator, | ||
this.doNotTerminate, | ||
|
@@ -122,7 +136,7 @@ public Session withChunkNumber(int chunkNumber) | |
this.scaling.getScale(), | ||
this.targetDirectory, | ||
this.suffix, | ||
this.table, | ||
Optional.ofNullable(this.table), | ||
this.nullString, | ||
this.separator, | ||
this.doNotTerminate, | ||
|
@@ -139,7 +153,7 @@ public Session withNoSexism(boolean noSexism) | |
this.scaling.getScale(), | ||
this.targetDirectory, | ||
this.suffix, | ||
this.table, | ||
Optional.ofNullable(this.table), | ||
this.nullString, | ||
this.separator, | ||
this.doNotTerminate, | ||
|
@@ -150,6 +164,42 @@ public Session withNoSexism(boolean noSexism) | |
); | ||
} | ||
|
||
public Session withHadoop(Configuration hadoopConfig) | ||
{ | ||
return new Session( | ||
this.scaling.getScale(), | ||
this.targetDirectory, | ||
this.suffix, | ||
Optional.ofNullable(this.table), | ||
this.nullString, | ||
this.separator, | ||
this.doNotTerminate, | ||
noSexism, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.parallelism, | ||
this.chunkNumber, | ||
this.overwrite, | ||
hadoopConfig | ||
); | ||
} | ||
|
||
public Session withTargetDirectory(String targetDirectory) | ||
{ | ||
return new Session( | ||
this.scaling.getScale(), | ||
targetDirectory, | ||
this.suffix, | ||
Optional.ofNullable(this.table), | ||
this.nullString, | ||
this.separator, | ||
this.doNotTerminate, | ||
this.noSexism, | ||
this.parallelism, | ||
this.chunkNumber, | ||
this.overwrite, | ||
this.hadoopConfig.get() | ||
); | ||
} | ||
|
||
public Scaling getScaling() | ||
{ | ||
return scaling; | ||
|
@@ -167,15 +217,15 @@ public String getSuffix() | |
|
||
public boolean generateOnlyOneTable() | ||
{ | ||
return table.isPresent(); | ||
return Optional.ofNullable(table).isPresent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to convert to an optional here now, just check if it's not null |
||
} | ||
|
||
public Table getOnlyTableToGenerate() | ||
{ | ||
if (!table.isPresent()) { | ||
if (!Optional.ofNullable(table).isPresent()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same. Just check for null. |
||
throw new TpcdsException("table not present"); | ||
} | ||
return table.get(); | ||
return Optional.ofNullable(table).get(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
} | ||
|
||
public String getNullString() | ||
|
@@ -213,6 +263,11 @@ public boolean shouldOverwrite() | |
return overwrite; | ||
} | ||
|
||
public Configuration getHadoopConfig() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have this return an optional |
||
{ | ||
return this.hadoopConfig.get(); | ||
} | ||
|
||
public String getCommandLineArguments() | ||
{ | ||
StringBuilder output = new StringBuilder(); | ||
|
@@ -225,8 +280,8 @@ public String getCommandLineArguments() | |
if (!suffix.equals(DEFAULT_SUFFIX)) { | ||
output.append("--suffix ").append(suffix).append(" "); | ||
} | ||
if (table.isPresent()) { | ||
output.append("--table ").append(table.get().getName()).append(" "); | ||
if (Optional.ofNullable(table).isPresent()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just check for null |
||
output.append("--table ").append(Optional.ofNullable(table).get().getName()).append(" "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just do |
||
} | ||
if (!nullString.equals(DEFAULT_NULL_STRING)) { | ||
output.append("--null ").append(nullString).append(" "); | ||
|
@@ -255,3 +310,38 @@ public String getCommandLineArguments() | |
return output.toString(); | ||
} | ||
} | ||
|
||
class SerializableHadoopConfiguration implements Serializable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be private? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implements on a new line |
||
{ | ||
Configuration conf; | ||
|
||
public SerializableHadoopConfiguration(Configuration hadoopConf) | ||
{ | ||
this.conf = hadoopConf; | ||
|
||
if (this.conf == null) { | ||
this.conf = new Configuration(); | ||
} | ||
} | ||
|
||
public SerializableHadoopConfiguration() | ||
{ | ||
this.conf = new Configuration(); | ||
} | ||
|
||
public Configuration get() | ||
{ | ||
return this.conf; | ||
} | ||
|
||
private void writeObject(java.io.ObjectOutputStream out) throws IOException | ||
{ | ||
this.conf.write(out); | ||
} | ||
|
||
private void readObject(java.io.ObjectInputStream in) throws IOException | ||
{ | ||
this.conf = new Configuration(); | ||
this.conf.readFields(in); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implements should be on a newline to match the style of the rest of the project. (I thought that would be caught by checkstyle, but I guess not)