Skip to content
Closed
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 @@ -66,7 +66,7 @@ public abstract class AvaticaStatement
final int resultSetType;
final int resultSetConcurrency;
final int resultSetHoldability;
private int fetchSize = DEFAULT_FETCH_SIZE;
private int fetchSizeRows;
private int fetchDirection;
protected long maxRowCount = 0;

Expand Down Expand Up @@ -108,6 +108,7 @@ protected AvaticaStatement(AvaticaConnection connection,
this.resultSetType = resultSetType;
this.resultSetConcurrency = resultSetConcurrency;
this.resultSetHoldability = resultSetHoldability;
this.fetchSizeRows = connection.config().fetchSizeRows(); // Default to connection config value
this.signature = signature;
this.closed = false;
if (h == null) {
Expand Down Expand Up @@ -407,12 +408,12 @@ public int getFetchDirection() throws SQLException {

public void setFetchSize(int rows) throws SQLException {
checkOpen();
this.fetchSize = rows;
this.fetchSizeRows = rows;
}

public int getFetchSize() throws SQLException {
checkOpen();
return fetchSize;
return fetchSizeRows;
}

public int getResultSetConcurrency() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public enum BuiltInConnectionProperty implements ConnectionProperty {
KEY_PASSWORD("key_password", Type.STRING, "", false),

HOSTNAME_VERIFICATION("hostname_verification", Type.ENUM, HostnameVerification.STRICT,
HostnameVerification.class, false);
HostnameVerification.class, false),

/** The number of rows to fetch per call, default is 100 rows. */
FETCH_SIZE_ROWS("fetch_size_rows", Type.NUMBER, AvaticaStatement.DEFAULT_FETCH_SIZE, false);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playing Devil's Advocate: if Avatica is focused as a JDBC abstraction layer, should we just call the client configuration property fetch_size instead of fetch_size_rows? I think the javadoc here and in ConnectionConfig appropriately explains what fetchSize means.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. The property should be called fetch_size. JDK has a method 'ResultSet.setFetchSize(int rows)' and so 'fetch size' is unambiguously a row count.


private final String camelName;
private final Type type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public interface ConnectionConfig {
String keyPassword();
/** @see BuiltInConnectionProperty#HOSTNAME_VERIFICATION */
HostnameVerification hostnameVerification();
/** @see BuiltInConnectionProperty#FETCH_SIZE_ROWS */
int fetchSizeRows();
}

// End ConnectionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public HostnameVerification hostnameVerification() {
.getEnum(HostnameVerification.class);
}

public int fetchSizeRows() {
return BuiltInConnectionProperty.FETCH_SIZE_ROWS.wrap(properties).getInt();
}

/** Converts a {@link Properties} object containing (name, value)
* pairs into a map whose keys are
* {@link org.apache.calcite.avatica.InternalProperty} objects.
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/org/apache/calcite/avatica/MetaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1543,13 +1543,21 @@ public Iterator<Object> iterator() {
private class FetchIterator implements Iterator<Object> {
private final AvaticaStatement stmt;
private final QueryState state;
private final int fetchRowCount;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be fetchSizeRows as per the property or there is a reason that the naming is different?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for using the same terminology

private Frame frame;
private Iterator<Object> rows;
private long currentOffset = 0;

private FetchIterator(AvaticaStatement stmt, QueryState state, Frame firstFrame) {
this.stmt = stmt;
this.state = state;
int fetchRowCount;
try {
fetchRowCount = stmt.getFetchSize();
} catch (SQLException e) {
fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE;
}
this.fetchRowCount = fetchRowCount;
if (firstFrame == null) {
frame = Frame.MORE;
rows = EmptyIterator.INSTANCE;
Expand Down Expand Up @@ -1589,7 +1597,7 @@ private void moveNext() {
}
try {
// currentOffset updated after element is read from `rows` iterator
frame = fetch(stmt.handle, currentOffset, AvaticaStatement.DEFAULT_FETCH_SIZE);
frame = fetch(stmt.handle, currentOffset, fetchRowCount);
} catch (NoSuchStatementException e) {
resetStatement();
// re-fetch the batch where we left off
Expand Down
10 changes: 10 additions & 0 deletions site/_docs/client_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,13 @@ on-hover images for the permalink, but oh well.
: _Default_: `null`.

: _Required_: Only if `truststore` was provided.

<strong><a name="fetch_size_rows" href="#fetch_size_rows">fetch_size_rows</a></strong>

: _Description_: The number of rows to fetch. If
<a href="https://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html#setFetchSize-int-">
Statement:setFetchSize</a> is set, that value overrides fetch_size_rows.

: _Default_: `100`.

: _Required_: No.