Skip to content

Fix JDBC compliance of DatabricksStatement#setMaxRows(0) #901

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

Open
wants to merge 1 commit 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 @@ -157,15 +157,23 @@ public void setMaxRows(int max) throws SQLException {
LOGGER.debug(String.format("public void setMaxRows(int max = {%s})", max));
checkIfClosed();
ValidationUtil.checkIfNonNegative(max, "maxRows");
this.maxRows = max;
if (max == 0) {
this.maxRows = DEFAULT_RESULT_ROW_LIMIT;
} else {
this.maxRows = max;
}
}

@Override
public void setLargeMaxRows(long max) throws SQLException {
LOGGER.debug("public void setLargeMaxRows(long max = {})", max);
checkIfClosed();
ValidationUtil.checkIfNonNegative(max, "maxRows");
this.maxRows = max;
if (max == 0) {
this.maxRows = DEFAULT_RESULT_ROW_LIMIT;
} else {
this.maxRows = max;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.databricks.jdbc.api.impl;

import static com.databricks.jdbc.common.EnvironmentVariables.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -360,6 +361,19 @@ public void testGetExecutionResult_statementIdNull() throws Exception {
assertThrows(DatabricksSQLException.class, statement::getExecutionResult);
}

@Test
public void testGetAndSetMaxRows() throws Exception {
IDatabricksConnectionContext connectionContext =
DatabricksConnectionContext.parse(JDBC_URL, new Properties());
DatabricksConnection connection = new DatabricksConnection(connectionContext, client);
DatabricksStatement statement = new DatabricksStatement(connection);
statement.setMaxRows(Integer.MAX_VALUE);
assertEquals(Integer.MAX_VALUE, statement.getMaxRows());
// "no limit"
statement.setMaxRows(0);
assertEquals(DEFAULT_RESULT_ROW_LIMIT, statement.getMaxRows());
}

@Test
public void testGetAndSetLargeMaxRows() throws Exception {
IDatabricksConnectionContext connectionContext =
Expand All @@ -368,6 +382,9 @@ public void testGetAndSetLargeMaxRows() throws Exception {
DatabricksStatement statement = new DatabricksStatement(connection);
statement.setLargeMaxRows(Long.MAX_VALUE);
assertEquals(Long.MAX_VALUE, statement.getLargeMaxRows());
// "no limit"
statement.setLargeMaxRows(0);
assertEquals(DEFAULT_RESULT_ROW_LIMIT, statement.getLargeMaxRows());
}

@Test
Expand Down