Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Mar 10, 2020
1 parent 923ed7e commit 5cf4f49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
Expand Up @@ -1215,7 +1215,7 @@ UnitOfWork getCurrentUnitOfWorkOrStartNewUnitOfWork() {
.build()),
AnalyzeMode.NONE);

// Execute query with an optimizer version and statistics package set on the connection.
// Execute query with an optimizer version set on the connection.
impl.setOptimizerVersion("2");
impl.executeQuery(Statement.of("SELECT FOO FROM BAR"));
verify(unitOfWork)
Expand All @@ -1226,8 +1226,8 @@ UnitOfWork getCurrentUnitOfWorkOrStartNewUnitOfWork() {
.build()),
AnalyzeMode.NONE);

// Execute query with an optimizer version and statistics package set on the connection and
// PrefetchChunks query option specified for the query.
// Execute query with an optimizer version set on the connection and PrefetchChunks query
// option specified for the query.
QueryOption prefetchOption = Options.prefetchChunks(100);
impl.setOptimizerVersion("3");
impl.executeQuery(Statement.of("SELECT FOO FROM BAR"), prefetchOption);
Expand All @@ -1240,9 +1240,8 @@ UnitOfWork getCurrentUnitOfWorkOrStartNewUnitOfWork() {
AnalyzeMode.NONE,
prefetchOption);

// Execute query with an optimizer version and statistics package set on the connection, and
// the same options also passed in to the query. The specific options passed in to the query
// should take precedence.
// Execute query with an optimizer version set on the connection, and the same options also
// passed in to the query. The specific options passed in to the query should take precedence.
impl.setOptimizerVersion("4");
impl.executeQuery(
Statement.newBuilder("SELECT FOO FROM BAR")
Expand Down
Expand Up @@ -48,11 +48,6 @@ public void testUseOptimizerVersionFromEnvironment() throws SQLException {
public String getOptimizerVersion() {
return "20";
}

@Override
public String getOptimizerStatisticsPackage() {
return "auto_20200127_20_24_19UTC";
}
});
try (Connection connection = createConnection()) {
// Do a query and verify that the version from the environment is used.
Expand Down
Expand Up @@ -40,11 +40,10 @@
* {@link QueryOptions} can be used with the JDBC driver on three different levels:
*
* <ol>
* <li>Specify {@link QueryOptions} in environment variables (TODO: Set environment variables
* runtime)
* <li>Specify {@link QueryOptions} in environment variables.
* <li>Specify {@link QueryOptions} in the connection URL or by setting these using <code>
* SET &lt;query_option&gt; = '&lt;value&gt;'</code> statements.
* <li>Specify {@link QueryOptions} in a query hint (TODO: Check SQL syntax)
* <li>Specify {@link QueryOptions} in a query hint.
* </ol>
*
* This class tests all three possibilities.
Expand Down Expand Up @@ -150,6 +149,25 @@ public void setInvalidOptimizerVersion() throws SQLException {
}
}

@Test
public void optimizerVersionInQueryHint() throws SQLException {
try (Connection connection = createConnection()) {
verifyOptimizerVersion(connection, "");
try (ResultSet rs =
connection.createStatement().executeQuery("{@optimizer_version=1} SELECT 1")) {
assertThat(rs.next()).isTrue();
assertThat(rs.getLong(1)).isEqualTo(1L);
assertThat(rs.next()).isFalse();
}
try (ResultSet rs =
connection.createStatement().executeQuery("{@optimizer_version=latest} SELECT 1")) {
assertThat(rs.next()).isTrue();
assertThat(rs.getLong(1)).isEqualTo(1L);
assertThat(rs.next()).isFalse();
}
}
}

@Test
public void optimizerVersionInEnvironment() throws SQLException {
try {
Expand All @@ -159,11 +177,6 @@ public void optimizerVersionInEnvironment() throws SQLException {
public String getOptimizerVersion() {
return "1";
}

@Override
public String getOptimizerStatisticsPackage() {
return "";
}
});
try (Connection connection = createConnection()) {
// Environment query options are not visible to the connection.
Expand All @@ -184,11 +197,6 @@ public String getOptimizerStatisticsPackage() {
public String getOptimizerVersion() {
return "9999999";
}

@Override
public String getOptimizerStatisticsPackage() {
return "";
}
});
try (Connection connection = createConnection()) {
try (ResultSet rs = connection.createStatement().executeQuery("SELECT 1")) {
Expand Down

0 comments on commit 5cf4f49

Please sign in to comment.