Skip to content

Feat: Support for Distributions in Templated Workloads #385

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

Merged
merged 36 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
760ede7
Added Random distributions
ETHenzlere Oct 26, 2023
9acfc19
Added Binomial Distribution
ETHenzlere Oct 26, 2023
36174c0
Min/Max for all Distributions
ETHenzlere Oct 30, 2023
b28f7ee
Added Timestamps, Time,Date
ETHenzlere Nov 7, 2023
d42d950
HashMap Solution with type casting
ETHenzlere Nov 10, 2023
572ca57
Multi random support
ETHenzlere Nov 14, 2023
6f287d9
Architecture change | Uniform distribution implemented
ETHenzlere Nov 17, 2023
33bef1e
Switched Dist and Type, changed subarray calculation
ETHenzlere Nov 20, 2023
bab1086
Merge branch 'main' into feature/templated-distributions
ETHenzlere Nov 29, 2023
573967c
Renamings and Documentation
ETHenzlere Nov 29, 2023
c12e60a
Enum, More Documentation
ETHenzlere Nov 30, 2023
3d3c9b2
Merge branch 'main' into feature/templated-distributions
bpkroth Dec 1, 2023
51f0f1d
Renamed autogenerated methods, readme format
ETHenzlere Dec 4, 2023
c97d35e
Resolved merge conflicts
ETHenzlere Dec 7, 2023
38747ae
Testing increased, size reduction of massive switch statement
ETHenzlere Dec 7, 2023
dafb90a
Test functionality after merge
ETHenzlere Jan 5, 2024
961d5c4
Lightweight constructor added
ETHenzlere Jan 17, 2024
5454f52
Insert statment modification
ETHenzlere Jan 23, 2024
3f59530
Merged with main
ETHenzlere Jan 24, 2024
06d3f39
Min-Max check
ETHenzlere Jan 24, 2024
949c93d
Changed distributions due to FK contraints
ETHenzlere Jan 24, 2024
19fad84
Typo
ETHenzlere Jan 24, 2024
c9dc450
Typo 2, build checked
ETHenzlere Jan 24, 2024
36318bd
Merge branch 'main' into feature/templated-distributions
bpkroth Jan 24, 2024
ce028cb
Merge branch 'main' into feature/templated-distributions
bpkroth Jan 24, 2024
ee8f4c1
Enums, removal of aliases, nits
ETHenzlere Jan 25, 2024
0235de7
Adapted description
ETHenzlere Jan 25, 2024
180b592
Merge branch 'main' into feature/templated-distributions
ETHenzlere Mar 13, 2024
9bb153f
Merge branch 'main' into feature/templated-distributions
bpkroth Mar 14, 2024
7154f6e
Merge branch 'main' into feature/templated-distributions
ETHenzlere Mar 20, 2024
ad94565
Templated Values with type information
ETHenzlere Mar 20, 2024
556ff15
README cleanup + Assert pattern
ETHenzlere Mar 21, 2024
c039d92
README update for access pattern
ETHenzlere Mar 25, 2024
1b25aa1
Merge branch 'main' into feature/templated-distributions
ETHenzlere Mar 25, 2024
5de5361
README adjustment showing a possible solution for value weighting
ETHenzlere Mar 25, 2024
1054ac9
Merge branch 'main' into feature/templated-distributions
bpkroth Mar 25, 2024
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
4 changes: 2 additions & 2 deletions data/templated/example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<template name="GetCust">
<query><![CDATA[SELECT C_DISCOUNT, C_LAST, C_CREDIT FROM customer WHERE C_W_ID = ?]]></query>
<types>
<type>INTEGER</type>
<type>DISTRIBUTION</type>
</types>
<values>
<value>8</value>
<value>uniform,0,100</value>
</values>
</template>
<template name="GetCustNull">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,26 @@
package com.oltpbenchmark.benchmarks.templated.procedures;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Random;

import org.immutables.value.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.oltpbenchmark.api.Procedure;
import com.oltpbenchmark.api.SQLStmt;
import com.oltpbenchmark.distributions.ScrambledZipfianGenerator;
import com.oltpbenchmark.distributions.ZipfianGenerator;
import com.oltpbenchmark.util.TextGenerator;

public abstract class GenericQuery extends Procedure {

Expand All @@ -38,7 +46,7 @@ public abstract class GenericQuery extends Procedure {
public void run(Connection conn, List<Object> params) throws SQLException {
try (PreparedStatement stmt = getStatement(conn, params); ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
//do nothing
// do nothing
}
}
conn.commit();
Expand All @@ -48,33 +56,98 @@ public void run(Connection conn, List<Object> params) throws SQLException {
public void run(Connection conn) throws SQLException {
QueryTemplateInfo queryTemplateInfo = this.getQueryTemplateInfo();

try (PreparedStatement stmt = this.getPreparedStatement(conn, queryTemplateInfo.getQuery()); ResultSet rs = stmt.executeQuery()) {
try (PreparedStatement stmt = this.getPreparedStatement(conn, queryTemplateInfo.getQuery());
ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
//do nothing
// do nothing
}
}
conn.commit();
}

public PreparedStatement getStatement(Connection conn, List<Object> params) throws SQLException {
QueryTemplateInfo queryTemplateInfo = this.getQueryTemplateInfo();
Random rng = new Random();

PreparedStatement stmt = this.getPreparedStatement(conn, queryTemplateInfo.getQuery());
String[] paramsTypes = queryTemplateInfo.getParamsTypes();
for (int i = 0; i < paramsTypes.length; i++) {
if (paramsTypes[i].equalsIgnoreCase("NULL")) {
stmt.setNull(i + 1, Types.NULL);
// ENTER RIGHT HERE WITH THE DISTRIBUTION
} else if (paramsTypes[i].equalsIgnoreCase("DISTRIBUTION")) {
String distType = params.get(i).toString();
String min, max;
int minI, maxI;
int val;
switch (distType) {
case "zipf":
min = params.get(i + 1).toString();
max = params.get(i + 2).toString();
ZipfianGenerator zipf = new ZipfianGenerator(rng, Integer.parseInt(min),
Integer.parseInt(max));
stmt.setInt(i + 1, zipf.nextInt());
break;
case "uniform":
minI = Integer.parseInt(params.get(i + 1).toString());
maxI = Integer.parseInt(params.get(i + 2).toString());
val = rng.nextInt(maxI - minI) + minI;
stmt.setInt(i + 1, val);
break;
case "binomial":
minI = Integer.parseInt(params.get(i + 1).toString());
maxI = Integer.parseInt(params.get(i + 2).toString());
do {
val = (int) (minI + Math.abs(rng.nextGaussian()) * maxI);
} while (val > maxI || val < minI);

stmt.setInt(i + 1, val);
break;
case "scrambled":
minI = Integer.parseInt(params.get(i + 1).toString());
maxI = Integer.parseInt(params.get(i + 2).toString());
ScrambledZipfianGenerator scramZipf = new ScrambledZipfianGenerator(minI,
maxI);
stmt.setInt(i + 1, scramZipf.nextInt());
break;
case "string":
maxI = Integer.parseInt(params.get(i + 1).toString());
String randText = TextGenerator.randomStr(rng, maxI);
stmt.setString(i + 1, randText);
break;
case "datetime":
case "timestamp":
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
stmt.setTimestamp(i + 1, timestamp);
break;
case "date":
Date date = new Date(System.currentTimeMillis());
stmt.setDate(i + 1, date);
break;
case "time":
Time time = new Time(System.currentTimeMillis());
stmt.setTime(i + 1, time);
break;
default:
throw new RuntimeException(
"No suitable distribution found. Currently supported are 'zipf' | 'scrambled' | 'normal' | 'uniform' | 'string' ");
}
System.out.println(stmt.toString());

} else {
try {
// TODO: add support for nullable other types
// For instance, can we provide a <value /> tag in the XML file to represent a NULL value?
// For instance, can we provide a <value /> tag in the XML file to represent a
// NULL value?
// Or does it need a special marker like "$null" to signify a NULL value?
Object param = params.get(i);
stmt.setObject(i + 1, param, Integer.parseInt(Types.class.getDeclaredField(paramsTypes[i]).get(null).toString()));
stmt.setObject(i + 1, param,
Integer.parseInt(Types.class.getDeclaredField(paramsTypes[i]).get(null).toString()));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(
"Error when setting parameters. Parameter type: " + paramsTypes[i] + ", parameter value: " + params.get(i));
"Error when setting parameters. Parameter type: " + paramsTypes[i] + ", parameter value: "
+ params.get(i));
}
}
}
Expand Down