-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #783 from zhicwu/enhance-jdbc
Prepare 0.3.2
- Loading branch information
Showing
67 changed files
with
3,030 additions
and
922 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 75 additions & 36 deletions
111
clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/Insertion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,106 @@ | ||
package com.clickhouse.benchmark.jdbc; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.Statement; | ||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.Enumeration; | ||
import java.util.Locale; | ||
import java.util.UUID; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
|
||
public class Insertion extends DriverBenchmark { | ||
private void checkResult(DriverState state, String batchId, int expectedRows, int actualResult) throws Exception { | ||
boolean isValid = actualResult == expectedRows; | ||
if (isValid) { | ||
try (Statement stmt = executeQuery(state, | ||
"select toInt32(count(1)) from system.test_insert where b=?", batchId)) { | ||
ResultSet rs = stmt.getResultSet(); | ||
isValid = rs.next() && (actualResult = rs.getInt(1)) == expectedRows; | ||
} | ||
} | ||
if (!isValid) { | ||
throw new IllegalStateException(String.format(Locale.ROOT, | ||
"Expected %d rows being inserted but we got %d", expectedRows, actualResult)); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public int insert10kUInt64Rows(DriverState state) throws Throwable { | ||
public void insertInt64(DriverState state) throws Throwable { | ||
final int range = state.getRandomNumber(); | ||
final int rows = state.getSampleSize() + range; | ||
final String batchId = UUID.randomUUID().toString(); | ||
SupplyValueFunction func = state.getSupplyFunction((p, v, l, i) -> p.setLong(i, (long) v)); | ||
int result = executeInsert(state, | ||
"insert into system.test_insert(b,i) -- select b,v from input('b String, v Int64')\nvalues(?,?)", func, | ||
new Enumeration<Object[]>() { | ||
int counter = 0; | ||
|
||
return executeInsert(state, "insert into system.test_insert(i) values(?)", new Enumeration<Object[]>() { | ||
int counter = 0; | ||
@Override | ||
public boolean hasMoreElements() { | ||
return counter < rows; | ||
} | ||
|
||
@Override | ||
public boolean hasMoreElements() { | ||
return counter < rows; | ||
} | ||
@Override | ||
public Object[] nextElement() { | ||
return new Object[] { batchId, (long) (range + (counter++)) }; | ||
} | ||
}); | ||
|
||
@Override | ||
public Object[] nextElement() { | ||
return new Object[] { range + (counter++) }; | ||
} | ||
}); | ||
checkResult(state, batchId, rows, result); | ||
} | ||
|
||
@Benchmark | ||
public int insert10kStringRows(DriverState state) throws Throwable { | ||
public void insertString(DriverState state) throws Throwable { | ||
final int range = state.getRandomNumber(); | ||
final int rows = state.getSampleSize() + range; | ||
final String batchId = UUID.randomUUID().toString(); | ||
SupplyValueFunction func = state.getSupplyFunction((p, v, l, i) -> p.setString(i, (String) v)); | ||
int result = executeInsert(state, | ||
"insert into system.test_insert(b, s) -- select b, v from input('b String, v String')\nvalues(?, ?)", | ||
func, new Enumeration<Object[]>() { | ||
int counter = 0; | ||
|
||
return executeInsert(state, "insert into system.test_insert(s) values(?)", new Enumeration<Object[]>() { | ||
int counter = 0; | ||
@Override | ||
public boolean hasMoreElements() { | ||
return counter < rows; | ||
} | ||
|
||
@Override | ||
public boolean hasMoreElements() { | ||
return counter < rows; | ||
} | ||
@Override | ||
public Object[] nextElement() { | ||
return new Object[] { batchId, String.valueOf(range + (counter++)) }; | ||
} | ||
}); | ||
|
||
@Override | ||
public Object[] nextElement() { | ||
return new Object[] { String.valueOf(range + (counter++)) }; | ||
} | ||
}); | ||
checkResult(state, batchId, rows, result); | ||
} | ||
|
||
@Benchmark | ||
public int insert10kTimestampRows(DriverState state) throws Throwable { | ||
public void insertTimestamp(DriverState state) throws Throwable { | ||
final int range = state.getRandomNumber(); | ||
final int rows = state.getSampleSize() + range; | ||
final String batchId = UUID.randomUUID().toString(); | ||
SupplyValueFunction func = state | ||
.getSupplyFunction((p, v, l, i) -> p.setTimestamp(i, Timestamp.valueOf((LocalDateTime) v))); | ||
int result = executeInsert(state, | ||
"insert into system.test_insert(b,t) -- select b,v from input('b String,v DateTime32')\nvalues(?,?)", | ||
func, new Enumeration<Object[]>() { | ||
int counter = 0; | ||
|
||
return executeInsert(state, "insert into system.test_insert(t) values(?)", new Enumeration<Object[]>() { | ||
int counter = 0; | ||
@Override | ||
public boolean hasMoreElements() { | ||
return counter < rows; | ||
} | ||
|
||
@Override | ||
public boolean hasMoreElements() { | ||
return counter < rows; | ||
} | ||
@Override | ||
public Object[] nextElement() { | ||
return new Object[] { batchId, | ||
LocalDateTime.ofEpochSecond((long) range + (counter++), 0, ZoneOffset.UTC) }; | ||
} | ||
}); | ||
|
||
@Override | ||
public Object[] nextElement() { | ||
return new Object[] { new Timestamp((long) range + (counter++)) }; | ||
} | ||
}); | ||
checkResult(state, batchId, rows, result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/SupplyValueFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.clickhouse.benchmark.jdbc; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
|
||
@FunctionalInterface | ||
public interface SupplyValueFunction { | ||
void set(PreparedStatement ps, Object value, int rowIndex, int columnIndex) throws SQLException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.