Skip to content

Commit

Permalink
Enum, More Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ETHenzlere committed Nov 30, 2023
1 parent 573967c commit c12e60a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 38 deletions.
2 changes: 1 addition & 1 deletion config/postgres/sample_templated_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/benchbase?sslmode=disable&amp;ApplicationName=templated&amp;reWriteBatchedInserts=true</url>
<username>admin</username>
<password>admin</password>
<password>password</password>
<isolation>TRANSACTION_SERIALIZABLE</isolation>
<batchsize>128</batchsize>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private String buildTemplatedValueString(List<TemplatedValue> params) {
String result = "";
for (TemplatedValue param : params) {
result += "new TemplatedValue("
+ "\"" + param.getDist() + "\"" + ","
+ "\"" + param.getDistribution() + "\"" + ","
+ "\"" + param.getMin() + "\"" + ","
+ "\"" + param.getMax() + "\"" + ","
+ "\"" + param.getSeed() + "\"" + ","
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.oltpbenchmark.api.Procedure;
import com.oltpbenchmark.api.SQLStmt;
import com.oltpbenchmark.benchmarks.templated.util.TemplatedValue;
import com.oltpbenchmark.benchmarks.templated.util.ValueGenerator;
import com.oltpbenchmark.distributions.ScrambledZipfianGenerator;
import com.oltpbenchmark.distributions.ZipfianGenerator;
import com.oltpbenchmark.util.TextGenerator;
Expand Down Expand Up @@ -75,14 +76,14 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para
for (int i = 0; i < paramsTypes.length; i++) {

TemplatedValue param = params.get(i);
boolean hasDist = param.getDist().length() > 0;
boolean hasDist = param.getDistribution() != null;
boolean hasValue = param.getValue().length() > 0;

if ((!hasDist && !hasValue) || paramsTypes[i].equalsIgnoreCase("NULL")) {
stmt.setNull(i + 1, Types.NULL);

} else if (hasDist) {
String distribution = param.getDist();
ValueGenerator distribution = param.getDistribution();
String paramType = paramsTypes[i].toLowerCase();
switch (paramType) {
case "integer":
Expand All @@ -91,11 +92,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para

switch (distribution) {

case "uniform":
case UNIFORM:
Random uniformRand = (Random) param.getGenerator();
stmt.setInt(i + 1, uniformRand.nextInt(min, max));
break;
case "binomial":
case BINOMIAL:
Random binomialRandom = (Random) param.getGenerator();
int bVal;
do {
Expand All @@ -104,11 +105,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para

stmt.setInt(i + 1, bVal);
break;
case "zipf":
case ZIPFIAN:
ZipfianGenerator zipfGen = (ZipfianGenerator) param.getGenerator();
stmt.setInt(i + 1, zipfGen.nextInt());
break;
case "scrambled":
case SCRAMBLED:
ScrambledZipfianGenerator scramGen = (ScrambledZipfianGenerator) param.getGenerator();
stmt.setInt(i + 1, scramGen.nextInt());
break;
Expand All @@ -123,11 +124,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para
float maxF = Float.parseFloat(param.getMaxString());
switch (distribution) {

case "uniform":
case UNIFORM:
Random uniformRand = (Random) param.getGenerator();
stmt.setFloat(i + 1, uniformRand.nextFloat(minF, maxF));
break;
case "binomial":
case BINOMIAL:
Random binomialRandom = (Random) param.getGenerator();
float fVal;
do {
Expand All @@ -146,11 +147,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para
Long maxL = param.getMax();
switch (distribution) {

case "uniform":
case UNIFORM:
Random uniformRand = (Random) param.getGenerator();
stmt.setLong(i + 1, uniformRand.nextLong(minL, maxL));
break;
case "binomial":
case BINOMIAL:
Random binomialRandom = (Random) param.getGenerator();
Long lVal;
do {
Expand All @@ -160,11 +161,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para

stmt.setLong(i + 1, lVal);
break;
case "zipf":
case ZIPFIAN:
ZipfianGenerator zipfGen = (ZipfianGenerator) param.getGenerator();
stmt.setLong(i + 1, zipfGen.nextLong());
break;
case "scrambled":
case SCRAMBLED:
ScrambledZipfianGenerator scramGen = (ScrambledZipfianGenerator) param.getGenerator();
stmt.setLong(i + 1, scramGen.nextLong());
break;
Expand All @@ -176,7 +177,7 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para
case "varchar":
case "string":
switch (distribution) {
case "uniform":
case UNIFORM:
Random strRandom = (Random) param.getGenerator();
stmt.setString(i + 1, TextGenerator.randomStr(strRandom, param.getMax().intValue()));
break;
Expand All @@ -189,11 +190,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para
Long stampMin = param.getMin();
Long stampMax = param.getMax();
switch (distribution) {
case "uniform":
case UNIFORM:
Random uniformRand = (Random) param.getGenerator();
stmt.setTimestamp(i + 1, new Timestamp(uniformRand.nextLong(stampMin, stampMax)));
break;
case "binomial":
case BINOMIAL:
Random binomialRandom = (Random) param.getGenerator();
Long lVal;
do {
Expand All @@ -203,11 +204,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para

stmt.setTimestamp(i + 1, new Timestamp(lVal));
break;
case "zipf":
case ZIPFIAN:
ZipfianGenerator zipfGen = (ZipfianGenerator) param.getGenerator();
stmt.setTimestamp(i + 1, new Timestamp(zipfGen.nextLong()));
break;
case "scrambled":
case SCRAMBLED:
ScrambledZipfianGenerator scramGen = (ScrambledZipfianGenerator) param.getGenerator();
stmt.setTimestamp(i + 1, new Timestamp(scramGen.nextLong()));
break;
Expand All @@ -220,11 +221,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para
Long dateMin = param.getMin();
Long dateMax = param.getMax();
switch (distribution) {
case "uniform":
case UNIFORM:
Random uniformRand = (Random) param.getGenerator();
stmt.setDate(i + 1, new Date(uniformRand.nextLong(dateMin, dateMax)));
break;
case "binomial":
case BINOMIAL:
Random binomialRandom = (Random) param.getGenerator();
Long lVal;
do {
Expand All @@ -234,11 +235,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para

stmt.setDate(i + 1, new Date(lVal));
break;
case "zipf":
case ZIPFIAN:
ZipfianGenerator zipfGen = (ZipfianGenerator) param.getGenerator();
stmt.setDate(i + 1, new Date(zipfGen.nextLong()));
break;
case "scrambled":
case SCRAMBLED:
ScrambledZipfianGenerator scramGen = (ScrambledZipfianGenerator) param.getGenerator();
stmt.setDate(i + 1, new Date(scramGen.nextLong()));
break;
Expand All @@ -251,11 +252,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para
Long timeMin = param.getMin();
Long timeMax = param.getMax();
switch (distribution) {
case "uniform":
case UNIFORM:
Random uniformRand = (Random) param.getGenerator();
stmt.setTime(i + 1, new Time(uniformRand.nextLong(timeMin, timeMax)));
break;
case "binomial":
case BINOMIAL:
Random binomialRandom = (Random) param.getGenerator();
Long lVal;
do {
Expand All @@ -265,11 +266,11 @@ public PreparedStatement getStatement(Connection conn, List<TemplatedValue> para

stmt.setTime(i + 1, new Time(lVal));
break;
case "zipf":
case ZIPFIAN:
ZipfianGenerator zipfGen = (ZipfianGenerator) param.getGenerator();
stmt.setTime(i + 1, new Time(zipfGen.nextLong()));
break;
case "scrambled":
case SCRAMBLED:
ScrambledZipfianGenerator scramGen = (ScrambledZipfianGenerator) param.getGenerator();
stmt.setTime(i + 1, new Time(scramGen.nextLong()));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import com.oltpbenchmark.distributions.ScrambledZipfianGenerator;
import com.oltpbenchmark.distributions.ZipfianGenerator;

/**
* This class is used to store information about the values
* used in templated benchmarks. It can hold static values but also
* generators for value distributions
*/
public class TemplatedValue {
String dist;
ValueGenerator distribution;
Long min;
Long max;
Long seed;
Expand All @@ -25,11 +30,11 @@ public class TemplatedValue {
* @param value Value that is used if no distribution is given
*/
public TemplatedValue(String dist, String min, String max, String seed, String value) {
this.dist = dist == null ? "" : dist;
this.min = min == null ? 0 : Long.parseLong(min);
this.max = max == null ? 1 : Long.parseLong(max);
this.seed = seed == null ? 0 : Long.parseLong(seed);
this.value = value;

this.generatorObject = createGenerator(dist, this.min, this.max, this.seed);

this.minS = min;
Expand All @@ -46,43 +51,51 @@ public TemplatedValue(String dist, String min, String max, String seed, String v
*/
private Object createGenerator(String distribution, Long min, Long max, Long seed) {

if (distribution == null || distribution.length() < 1)
if (distribution == null || distribution.equals("null") || distribution.length() < 1)
return null;

switch (distribution) {
switch (distribution.toLowerCase()) {
case "uniform":
this.distribution = ValueGenerator.UNIFORM;
return new Random(seed);
case "binomial":
case "normal":
this.distribution = ValueGenerator.BINOMIAL;
return new Random(seed);
case "zipf":
case "zipfian":
this.distribution = ValueGenerator.ZIPFIAN;
return new ZipfianGenerator(new Random(seed), min, max);
case "scrambled":
case "scramzipf":
this.distribution = ValueGenerator.SCRAMBLED;
return new ScrambledZipfianGenerator(min, max);
default:
throw new RuntimeException(
"The distribution: '" + distribution
+ "' is not supported. Currently supported are 'zipf' | 'scrambled' | 'normal' | 'uniform'");
+ "' is not supported. Currently supported are 'uniform' | 'binomial' | 'zipfian' | 'scrambled'");
}

}

public String getDist() {
return dist;
public ValueGenerator getDistribution() {
return this.distribution;
}

public Long getMin() {
return min;
return this.min;
}

public Long getMax() {
return max;
return this.max;
}

public Long getSeed() {
return seed;
return this.seed;
}

public String getValue() {
return value;
return this.value;
}

public String getMinString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.oltpbenchmark.benchmarks.templated.util;

public enum ValueGenerator {
UNIFORM,
BINOMIAL,
ZIPFIAN,
SCRAMBLED
}

0 comments on commit c12e60a

Please sign in to comment.