Skip to content

Commit

Permalink
Validate results in benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicwu committed Dec 8, 2021
1 parent e7b0e6a commit d2fa508
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 28 deletions.
Binary file removed .pom.xml.swp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

@FunctionalInterface
public interface ConsumeValueFunction {
void consume(Blackhole blackhole, ResultSet rs, int columnIndex) throws SQLException;
void consume(Blackhole blackhole, ResultSet rs, int rowIndex, int columnIndex) throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ public boolean usePreparedStatement() {

public ConsumeValueFunction getConsumeFunction(ConsumeValueFunction defaultFunc) {
if ("string".equals(type)) {
return (b, r, i) -> b.consume(r.getString(i));
return (b, r, l, i) -> b.consume(r.getString(i));
} else if ("object".equals(type)) {
return (b, r, i) -> b.consume(r.getObject(i));
return (b, r, l, i) -> b.consume(r.getObject(i));
} else if (defaultFunc == null) {
return (b, r, i) -> b.consume(i);
return (b, r, l, i) -> b.consume(i);
} else {
return defaultFunc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Locale;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.infra.Blackhole;

Expand All @@ -10,162 +12,210 @@ public class Query extends DriverBenchmark {
public void selectArrayOfUInt16(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getArray(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getArray(i)));
int l = 0;
try (Statement stmt = executeQuery(state,
"select range(100, number % 600) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectMapOfInt32(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getObject(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getObject(i)));
int l = 0;
try (Statement stmt = executeQuery(state,
"select cast((arrayMap(x->x+1000, range(1, number % 100)), arrayMap(x->x+10000, range(1, number %100))) as Map(Int32, Int32)) as v from numbers(?)",
rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectTupleOfInt16(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getObject(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getObject(i)));
int l = 0;
try (Statement stmt = executeQuery(state,
"select tuple(arrayMap(x -> cast(x as Int16), range(100, number % 600))) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectDateTime32(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getTimestamp(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getTimestamp(i)));
int l = 0;
try (Statement stmt = executeQuery(state,
"select toDateTime32(1613826920 + number) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectDateTime64(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getTimestamp(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getTimestamp(i)));
int l = 0;
try (Statement stmt = executeQuery(state,
"select toDateTime64(1613826920 + number / 1000000000, 9) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectInt8(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getByte(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getByte(i)));
int l = 0;
try (Statement stmt = executeQuery(state, "select toInt8(number % 256) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectUInt8(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getShort(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getShort(i)));
int l = 0;
try (Statement stmt = executeQuery(state, "select toUInt8(number % 256) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectUuid(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getString(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getString(i)));
int l = 0;
try (Statement stmt = executeQuery(state, "select generateUUIDv4() as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectInt32(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getInt(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getInt(i)));
int l = 0;
try (Statement stmt = executeQuery(state, "select toInt32(number) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectString(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getString(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getString(i)));
int l = 0;
try (Statement stmt = executeQuery(state, "select toString(number/3) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectUInt64(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getLong(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getLong(i)));
int l = 0;
try (Statement stmt = executeQuery(state, "select number as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}

@Benchmark
public void selectDecimal64(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getBigDecimal(i)));
ConsumeValueFunction func = state.getConsumeFunction((b, r, l, i) -> b.consume(r.getBigDecimal(i)));
int l = 0;
try (Statement stmt = executeQuery(state, "select toDecimal64(number + number / 10000, 4) as v from numbers(?)",
rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
func.consume(blackhole, rs, l++, 1);
}
}
if (l != rows) {
throw new IllegalStateException(String.format(Locale.ROOT, "Expected %d rows but got %d", rows, l));
}
}
}

0 comments on commit d2fa508

Please sign in to comment.