Skip to content
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

Disable Object Reuse By Default #1382

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,18 @@ public SelfT session(String sessionId, Boolean check, Integer timeout) {
return (SelfT) this;
}

/**
* Enable object reuse during result collection, resulting in better memmory efficiency.
* WARNING: If you plan to pass the underlying {@link com.clickhouse.data.ClickHouseRecord} back without
* intermediate extraction, this object will potentially be overwritten with the last seen value of the stream.
* @return the request with object reuse enabled
*/
@SuppressWarnings("unchecked")
public SelfT reuseObjects() {
option(ClickHouseClientOption.REUSE_VALUE_WRAPPER, "true");
return (SelfT) this;
}

/**
* Sets a setting. See
* https://clickhouse.tech/docs/en/operations/settings/settings/ for more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,45 @@ public void testOpenCloseClient() throws ClickHouseException {
}
}

@Test(groups = { "integration" })
public void testWithObjectReuse() throws ClickHouseException {
int numbers = 10;
ClickHouseNode server = getServer();
try (ClickHouseClient client = getClient();
ClickHouseResponse response = newRequest(client, server).query("select * from numbers(10)")
.reuseObjects()
.executeAndWait()) {
List<ClickHouseRecord> records = new ArrayList<>(10);
response.stream().forEach(records::add);
Assert.assertEquals(records.size(), 10);
// Verify that all records are the same (object reuse)
for (int i = 0; i < numbers; i++) {
// All values will be 9 (last seen record)
Assert.assertEquals(records.get(i).getValue(0).asInteger(), 9);
}
}
}


@Test(groups = { "integration" })
public void testWithoutObjectReuse() throws ClickHouseException {
int numbers = 10;
ClickHouseNode server = getServer();
try (ClickHouseClient client = getClient();
ClickHouseResponse response = newRequest(client, server).query("select * from numbers(10)")
.executeAndWait()) {
List<ClickHouseRecord> records = new ArrayList<>(10);
response.stream().forEach(records::add);
Assert.assertEquals(records.size(), 10);
// Verify all records are unique (different number)
for (int i = 0; i < numbers; i++) {
// Numbers will increment correctly, as object reuse is disabled by default
Assert.assertEquals(records.get(i).getValue(0).asInteger(), i);
}

}
}

@Test(dataProvider = "compressionMatrix", groups = { "integration" })
public void testCompression(ClickHouseFormat format, ClickHouseBufferingMode bufferingMode, boolean compressRequest,
boolean compressResponse) throws ClickHouseException {
Expand Down Expand Up @@ -850,7 +889,7 @@ public void testQuery() {
* while (response.hasError()) { int index = 0; for (ClickHouseColumn c :
* columns) { // RawValue v = response.getRawValue(index++); // String v =
* response.getValue(index++, String.class) }
*
*
* } byte[] bytes = in.readAllBytes(); String str = new String(bytes);
*/
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public boolean isWidenUnsignedTypes() {

static final ClickHouseFormat DEFAULT_FORMAT = ClickHouseFormat.TabSeparated;

static final boolean DEFAULT_REUSE_VALUE_WRAPPER = true;
static final boolean DEFAULT_REUSE_VALUE_WRAPPER = false;
static final boolean DEFAULT_USE_BINARY_STRING = false;
static final boolean DEFAULT_USE_BLOCKING_QUEUE = false;
static final boolean DEFAULT_USE_COMPILATION = false;
Expand Down