Skip to content

Commit 33c7925

Browse files
ETHenzlerebpkroth
andauthored
Feat: Support for "Update" type queries in Templated Benchmarks (#386)
Feature adds a check for UPDATE style queries and handles the execution in templated benchmarks --------- Co-authored-by: Brian Kroth <[email protected]>
1 parent 458a598 commit 33c7925

File tree

7 files changed

+107
-9
lines changed

7 files changed

+107
-9
lines changed

config/mariadb/sample_templated_config.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<work>
2525
<time>10</time>
2626
<rate>100</rate>
27-
<weights>30,20,10,30,10</weights>
27+
<weights>20,20,10,10,10,10,10,10</weights>
2828
</work>
2929
</works>
3030

@@ -45,5 +45,14 @@
4545
<transactiontype>
4646
<name>GetItemByPrice</name>
4747
</transactiontype>
48+
<transactiontype>
49+
<name>UpdateItemPrice</name>
50+
</transactiontype>
51+
<transactiontype>
52+
<name>DeleteItem</name>
53+
</transactiontype>
54+
<transactiontype>
55+
<name>InsertItem</name>
56+
</transactiontype>
4857
</transactiontypes>
4958
</parameters>

config/mysql/sample_templated_config.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<work>
2525
<time>10</time>
2626
<rate>100</rate>
27-
<weights>30,20,10,30,10</weights>
27+
<weights>20,20,10,10,10,10,10,10</weights>
2828
</work>
2929
</works>
3030

@@ -45,5 +45,14 @@
4545
<transactiontype>
4646
<name>GetItemByPrice</name>
4747
</transactiontype>
48+
<transactiontype>
49+
<name>UpdateItemPrice</name>
50+
</transactiontype>
51+
<transactiontype>
52+
<name>DeleteItem</name>
53+
</transactiontype>
54+
<transactiontype>
55+
<name>InsertItem</name>
56+
</transactiontype>
4857
</transactiontypes>
4958
</parameters>

config/postgres/sample_templated_config.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<work>
2525
<time>10</time>
2626
<rate>100</rate>
27-
<weights>30,20,10,30,10</weights>
27+
<weights>20,20,10,10,10,10,10,10</weights>
2828
</work>
2929
</works>
3030

@@ -45,5 +45,14 @@
4545
<transactiontype>
4646
<name>GetItemByPrice</name>
4747
</transactiontype>
48+
<transactiontype>
49+
<name>UpdateItemPrice</name>
50+
</transactiontype>
51+
<transactiontype>
52+
<name>DeleteItem</name>
53+
</transactiontype>
54+
<transactiontype>
55+
<name>InsertItem</name>
56+
</transactiontype>
4857
</transactiontypes>
4958
</parameters>

config/sqlite/sample_templated_config.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<work>
2323
<time>10</time>
2424
<rate>100</rate>
25-
<weights>30,20,10,30,10</weights>
25+
<weights>20,20,10,10,10,10,10,10</weights>
2626
</work>
2727
</works>
2828

@@ -43,5 +43,14 @@
4343
<transactiontype>
4444
<name>GetItemByPrice</name>
4545
</transactiontype>
46+
<transactiontype>
47+
<name>UpdateItemPrice</name>
48+
</transactiontype>
49+
<transactiontype>
50+
<name>DeleteItem</name>
51+
</transactiontype>
52+
<transactiontype>
53+
<name>InsertItem</name>
54+
</transactiontype>
4655
</transactiontypes>
4756
</parameters>

config/sqlserver/sample_templated_config.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<work>
2525
<time>10</time>
2626
<rate>100</rate>
27-
<weights>30,20,10,30,10</weights>
27+
<weights>20,20,10,10,10,10,10,10</weights>
2828
</work>
2929
</works>
3030

@@ -45,5 +45,14 @@
4545
<transactiontype>
4646
<name>GetItemByPrice</name>
4747
</transactiontype>
48+
<transactiontype>
49+
<name>UpdateItemPrice</name>
50+
</transactiontype>
51+
<transactiontype>
52+
<name>DeleteItem</name>
53+
</transactiontype>
54+
<transactiontype>
55+
<name>InsertItem</name>
56+
</transactiontype>
4857
</transactiontypes>
4958
</parameters>

data/templated/example.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,39 @@
6161
<value>11</value>
6262
</values>
6363
</template>
64+
<template name="UpdateItemPrice">
65+
<query><![CDATA[UPDATE item SET i_price = i_price + 1 WHERE i_price < ?]]></query>
66+
<types>
67+
<type>FLOAT</type>
68+
</types>
69+
<values>
70+
<value>2.1</value>
71+
</values>
72+
</template>
73+
<template name="DeleteItem">
74+
<query><![CDATA[DELETE FROM item WHERE i_price > ?]]></query>
75+
<types>
76+
<type>FLOAT</type>
77+
</types>
78+
<values>
79+
<value>255.0</value>
80+
</values>
81+
</template>
82+
<template name="InsertItem">
83+
<query><![CDATA[INSERT INTO item VALUES(?,?,?,?,?)]]></query>
84+
<types>
85+
<type>INTEGER</type>
86+
<type>VARCHAR</type>
87+
<type>FLOAT</type>
88+
<type>VARCHAR</type>
89+
<type>INTEGER</type>
90+
</types>
91+
<values>
92+
<value>100001</value>
93+
<value>Testname</value>
94+
<value>255.1</value>
95+
<value>Testdata</value>
96+
<value>1</value>
97+
</values>
98+
</template>
6499
</templates>

src/main/java/com/oltpbenchmark/benchmarks/templated/procedures/GenericQuery.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,29 @@ public abstract class GenericQuery extends Procedure {
3636

3737
/** Execution method with parameters. */
3838
public void run(Connection conn, List<Object> params) throws SQLException {
39-
try (PreparedStatement stmt = getStatement(conn, params); ResultSet rs = stmt.executeQuery()) {
40-
while (rs.next()) {
41-
//do nothing
42-
}
39+
40+
try (PreparedStatement stmt = getStatement(conn, params)) {
41+
boolean hasResultSet = stmt.execute();
42+
if (hasResultSet) {
43+
do {
44+
try (ResultSet rs = stmt.getResultSet()) {
45+
while (rs.next()) {
46+
// do nothing
47+
}
48+
} catch (Exception resultException){
49+
resultException.printStackTrace();
50+
throw new RuntimeException("Could not retrieve ResultSet");
51+
}
52+
} while(stmt.getMoreResults());
53+
} else {
54+
// Case for UPDATE, INSERT, DELETE queries
55+
// do nothing
56+
}
57+
} catch (Exception e) {
58+
e.printStackTrace();
59+
throw new RuntimeException("Error when trying to execute statement");
4360
}
61+
4462
conn.commit();
4563
}
4664

0 commit comments

Comments
 (0)