Skip to content

Commit

Permalink
max_result_rows should never be applied to metadata queries
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicwu committed Jul 15, 2022
1 parent db0bd80 commit 81168a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.clickhouse.client.ClickHouseChecker;
import com.clickhouse.client.ClickHouseColumn;
import com.clickhouse.client.ClickHouseDataType;
import com.clickhouse.client.ClickHouseFormat;
import com.clickhouse.client.ClickHouseParameterizedQuery;
import com.clickhouse.client.ClickHouseUtils;
import com.clickhouse.client.ClickHouseValues;
Expand Down Expand Up @@ -66,9 +67,11 @@ protected ResultSet query(String sql, ClickHouseRecordTransformer func, boolean
SQLException error = null;
try {
ClickHouseStatement stmt = connection.createStatement();
stmt.setLargeMaxRows(0L);
return new ClickHouseResultSet("", "", stmt,
// load everything into memory
ClickHouseSimpleResponse.of(stmt.getRequest()
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
.option(ClickHouseClientOption.RENAME_RESPONSE_COLUMN, ClickHouseRenameMethod.NONE)
.query(sql).execute().get(), func));
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,10 @@ public void setLargeMaxRows(long max) throws SQLException {

if (this.maxRows != max) {
if (max == 0L || !connection.allowCustomSetting()) {
request.removeSetting("max_result_rows");
request.removeSetting(ClickHouseClientOption.MAX_RESULT_ROWS.getKey());
request.removeSetting("result_overflow_mode");
} else {
request.set("max_result_rows", max);
request.set(ClickHouseClientOption.MAX_RESULT_ROWS.getKey(), max);
request.set("result_overflow_mode", "break");
}
this.maxRows = max;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ public void testGetColumns(String columnType, Integer columnSize, Integer decima
}
}

@Test(groups = "integration")
public void testMaxRows() throws SQLException {
Properties props = new Properties();
props.setProperty(ClickHouseClientOption.MAX_RESULT_ROWS.getKey(), "1");
int count = 0;
try (ClickHouseConnection conn = newConnection(props)) {
try (ResultSet rs = conn.getMetaData().getColumns(conn.getCatalog(), conn.getSchema(), "%", "%")) {
while (rs.next()) {
count++;
}
}
}
Assert.assertTrue(count > 1, "Should have more than one row returned");
}

@Test(groups = "integration")
public void testTableComment() throws SQLException {
String tableName = "test_table_comment";
Expand Down

0 comments on commit 81168a2

Please sign in to comment.