[CALCITE-2365] Upgrade avatica to 1.12
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/b36a1072 Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/b36a1072 Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/b36a1072 Branch: refs/heads/master Commit: b36a10725b2569d8583ea66aea9dcceb9e0341ac Parents: f258706 Author: Julian Hyde <[email protected]> Authored: Thu Jun 28 17:56:11 2018 -0700 Committer: Julian Hyde <[email protected]> Committed: Thu Jun 28 18:27:18 2018 -0700 ---------------------------------------------------------------------- .../calcite/jdbc/CalciteConnectionImpl.java | 14 ++- .../calcite/jdbc/CalciteJdbc41Factory.java | 3 +- .../apache/calcite/jdbc/CalciteMetaImpl.java | 12 +- .../calcite/jdbc/CalcitePreparedStatement.java | 2 +- .../apache/calcite/jdbc/CalciteResultSet.java | 6 +- .../org/apache/calcite/jdbc/MetadataSchema.java | 15 ++- .../rel/rules/AggregateStarTableRule.java | 16 ++- .../calcite/jdbc/CalciteRemoteDriverTest.java | 108 +++++++++-------- .../org/apache/calcite/test/CalciteAssert.java | 115 ++++++++----------- .../java/org/apache/calcite/test/JdbcTest.java | 3 +- core/src/test/resources/sql/misc.iq | 6 +- pom.xml | 2 +- 12 files changed, 168 insertions(+), 134 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java index 4e19554..ec5d610 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java @@ -447,7 +447,12 @@ abstract class CalciteConnectionImpl private SqlAdvisor getSqlAdvisor() { final CalciteConnectionImpl con = (CalciteConnectionImpl) queryProvider; - final String schemaName = con.getSchema(); + final String schemaName; + try { + schemaName = con.getSchema(); + } catch (SQLException e) { + throw new RuntimeException(e); + } final List<String> schemaPath = schemaName == null ? ImmutableList.<String>of() @@ -500,7 +505,12 @@ abstract class CalciteConnectionImpl } public List<String> getDefaultSchemaPath() { - final String schemaName = connection.getSchema(); + final String schemaName; + try { + schemaName = connection.getSchema(); + } catch (SQLException e) { + throw new RuntimeException(e); + } return schemaName == null ? ImmutableList.<String>of() : ImmutableList.of(schemaName); http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/main/java/org/apache/calcite/jdbc/CalciteJdbc41Factory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteJdbc41Factory.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteJdbc41Factory.java index 034563a..7aedae4 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteJdbc41Factory.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteJdbc41Factory.java @@ -92,7 +92,8 @@ public class CalciteJdbc41Factory extends CalciteFactory { } public CalciteResultSet newResultSet(AvaticaStatement statement, QueryState state, - Meta.Signature signature, TimeZone timeZone, Meta.Frame firstFrame) { + Meta.Signature signature, TimeZone timeZone, Meta.Frame firstFrame) + throws SQLException { final ResultSetMetaData metaData = newResultSetMetaData(statement, signature); final CalcitePrepare.CalciteSignature calciteSignature = http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java index 12d6296..837aece 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java @@ -372,8 +372,14 @@ public class CalciteMetaImpl extends MetaImpl { } Enumerable<MetaCatalog> catalogs() { + final String catalog; + try { + catalog = connection.getCatalog(); + } catch (SQLException e) { + throw new RuntimeException(e); + } return Linq4j.asEnumerable( - ImmutableList.of(new MetaCatalog(connection.getCatalog()))); + ImmutableList.of(new MetaCatalog(catalog))); } Enumerable<MetaTableType> tableTypes() { @@ -382,7 +388,7 @@ public class CalciteMetaImpl extends MetaImpl { new MetaTableType("TABLE"), new MetaTableType("VIEW"))); } - Enumerable<MetaSchema> schemas(String catalog) { + Enumerable<MetaSchema> schemas(final String catalog) { return Linq4j.asEnumerable( getConnection().rootSchema.getSubSchemaMap().values()) .select( @@ -390,7 +396,7 @@ public class CalciteMetaImpl extends MetaImpl { public MetaSchema apply(CalciteSchema calciteSchema) { return new CalciteMetaSchema( calciteSchema, - connection.getCatalog(), + catalog, calciteSchema.getName()); } }) http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/main/java/org/apache/calcite/jdbc/CalcitePreparedStatement.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalcitePreparedStatement.java b/core/src/main/java/org/apache/calcite/jdbc/CalcitePreparedStatement.java index dbbc351..50e4036 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalcitePreparedStatement.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalcitePreparedStatement.java @@ -48,7 +48,7 @@ abstract class CalcitePreparedStatement extends AvaticaPreparedStatement { resultSetHoldability); } - @Override public CalciteConnectionImpl getConnection() { + @Override public CalciteConnectionImpl getConnection() throws SQLException { return (CalciteConnectionImpl) super.getConnection(); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java index bf7957f..a8e2ecf 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java +++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteResultSet.java @@ -47,7 +47,7 @@ public class CalciteResultSet extends AvaticaResultSet { CalciteResultSet(AvaticaStatement statement, CalcitePrepare.CalciteSignature calciteSignature, ResultSetMetaData resultSetMetaData, TimeZone timeZone, - Meta.Frame firstFrame) { + Meta.Frame firstFrame) throws SQLException { super(statement, null, calciteSignature, resultSetMetaData, timeZone, firstFrame); } @@ -69,7 +69,7 @@ public class CalciteResultSet extends AvaticaResultSet { } @Override public ResultSet create(ColumnMetaData.AvaticaType elementType, - Iterable<Object> iterable) { + Iterable<Object> iterable) throws SQLException { final List<ColumnMetaData> columnMetaDataList; if (elementType instanceof ColumnMetaData.StructType) { columnMetaDataList = ((ColumnMetaData.StructType) elementType).columns; @@ -111,7 +111,7 @@ public class CalciteResultSet extends AvaticaResultSet { } // do not make public - CalciteConnectionImpl getCalciteConnection() { + CalciteConnectionImpl getCalciteConnection() throws SQLException { return (CalciteConnectionImpl) statement.getConnection(); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java b/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java index b896f18..5fb2e89 100644 --- a/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java +++ b/core/src/main/java/org/apache/calcite/jdbc/MetadataSchema.java @@ -25,6 +25,7 @@ import org.apache.calcite.schema.impl.AbstractSchema; import com.google.common.collect.ImmutableMap; +import java.sql.SQLException; import java.util.Map; import static org.apache.calcite.jdbc.CalciteMetaImpl.MetaColumn; @@ -38,7 +39,12 @@ class MetadataSchema extends AbstractSchema { new CalciteMetaImpl.MetadataTable<MetaColumn>(MetaColumn.class) { public Enumerator<MetaColumn> enumerator( final CalciteMetaImpl meta) { - final String catalog = meta.getConnection().getCatalog(); + final String catalog; + try { + catalog = meta.getConnection().getCatalog(); + } catch (SQLException e) { + throw new RuntimeException(e); + } return meta.tables(catalog).selectMany( new Function1<MetaTable, Enumerable<MetaColumn>>() { public Enumerable<MetaColumn> apply(MetaTable table) { @@ -50,7 +56,12 @@ class MetadataSchema extends AbstractSchema { "TABLES", new CalciteMetaImpl.MetadataTable<MetaTable>(MetaTable.class) { public Enumerator<MetaTable> enumerator(CalciteMetaImpl meta) { - final String catalog = meta.getConnection().getCatalog(); + final String catalog; + try { + catalog = meta.getConnection().getCatalog(); + } catch (SQLException e) { + throw new RuntimeException(e); + } return meta.tables(catalog).enumerator(); } }); http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java index 22ee628..f000d39 100644 --- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java +++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateStarTableRule.java @@ -16,11 +16,13 @@ */ package org.apache.calcite.rel.rules; +import org.apache.calcite.config.CalciteConnectionConfig; import org.apache.calcite.jdbc.CalciteSchema; import org.apache.calcite.materialize.Lattice; import org.apache.calcite.materialize.TileKey; import org.apache.calcite.plan.RelOptCluster; import org.apache.calcite.plan.RelOptLattice; +import org.apache.calcite.plan.RelOptPlanner; import org.apache.calcite.plan.RelOptRule; import org.apache.calcite.plan.RelOptRuleCall; import org.apache.calcite.plan.RelOptRuleOperand; @@ -113,14 +115,22 @@ public class AggregateStarTableRule extends RelOptRule { protected void apply(RelOptRuleCall call, Project postProject, final Aggregate aggregate, StarTable.StarTableScan scan) { + final RelOptPlanner planner = call.getPlanner(); + final CalciteConnectionConfig config = + planner.getContext().unwrap(CalciteConnectionConfig.class); + if (config == null || !config.createMaterializations()) { + // Disable this rule if we if materializations are disabled - in + // particular, if we are in a recursive statement that is being used to + // populate a materialization + return; + } final RelOptCluster cluster = scan.getCluster(); final RelOptTable table = scan.getTable(); - final RelOptLattice lattice = call.getPlanner().getLattice(table); + final RelOptLattice lattice = planner.getLattice(table); final List<Lattice.Measure> measures = lattice.lattice.toMeasures(aggregate.getAggCallList()); final Pair<CalciteSchema.TableEntry, TileKey> pair = - lattice.getAggregate( - call.getPlanner(), aggregate.getGroupSet(), measures); + lattice.getAggregate(planner, aggregate.getGroupSet(), measures); if (pair == null) { return; } http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java b/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java index 1c3ff40..801caa9 100644 --- a/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java +++ b/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java @@ -95,7 +95,7 @@ public class CalciteRemoteDriverTest { private static final CalciteAssert.ConnectionFactory REMOTE_CONNECTION_FACTORY = new CalciteAssert.ConnectionFactory() { public Connection createConnection() throws SQLException { - return remoteConnection; + return getRemoteConnection(); } }; @@ -151,7 +151,6 @@ public class CalciteRemoteDriverTest { }; private static Connection localConnection; - private static Connection remoteConnection; private static HttpServer start; @BeforeClass public static void beforeClass() throws Exception { @@ -163,8 +162,11 @@ public class CalciteRemoteDriverTest { return new AvaticaJsonHandler(service); } }); + } + + protected static Connection getRemoteConnection() throws SQLException { final int port = start.getPort(); - remoteConnection = DriverManager.getConnection( + return DriverManager.getConnection( "jdbc:avatica:remote:url=http://localhost:" + port); } @@ -293,14 +295,16 @@ public class CalciteRemoteDriverTest { /** Same query as {@link #testRemoteExecuteQuery()}, run without the test * infrastructure. */ @Test public void testRemoteExecuteQuery2() throws Exception { - final Statement statement = remoteConnection.createStatement(); - final ResultSet resultSet = - statement.executeQuery("values (1, 'a'), (cast(null as integer), 'b')"); - int n = 0; - while (resultSet.next()) { - ++n; + try (Connection remoteConnection = getRemoteConnection()) { + final Statement statement = remoteConnection.createStatement(); + final String sql = "values (1, 'a'), (cast(null as integer), 'b')"; + final ResultSet resultSet = statement.executeQuery(sql); + int n = 0; + while (resultSet.next()) { + ++n; + } + assertThat(n, equalTo(2)); } - assertThat(n, equalTo(2)); } /** For each (source, destination) type, make sure that we can convert bind @@ -450,70 +454,84 @@ public class CalciteRemoteDriverTest { * <a href="https://issues.apache.org/jira/browse/CALCITE-646">[CALCITE-646] * AvaticaStatement execute method broken over remote JDBC</a>. */ @Test public void testRemoteStatementExecute() throws Exception { - final Statement statement = remoteConnection.createStatement(); - final boolean status = statement.execute("values (1, 2), (3, 4), (5, 6)"); - assertThat(status, is(true)); - final ResultSet resultSet = statement.getResultSet(); - int n = 0; - while (resultSet.next()) { - ++n; + try (Connection remoteConnection = getRemoteConnection()) { + final Statement statement = remoteConnection.createStatement(); + final boolean status = statement.execute("values (1, 2), (3, 4), (5, 6)"); + assertThat(status, is(true)); + final ResultSet resultSet = statement.getResultSet(); + int n = 0; + while (resultSet.next()) { + ++n; + } + assertThat(n, equalTo(3)); } - assertThat(n, equalTo(3)); } @Test(expected = SQLException.class) public void testAvaticaConnectionException() throws Exception { - remoteConnection.isValid(-1); + try (Connection remoteConnection = getRemoteConnection()) { + remoteConnection.isValid(-1); + } } @Test(expected = SQLException.class) public void testAvaticaStatementException() throws Exception { - try (Statement statement = remoteConnection.createStatement()) { - statement.setCursorName("foo"); + try (Connection remoteConnection = getRemoteConnection()) { + try (Statement statement = remoteConnection.createStatement()) { + statement.setCursorName("foo"); + } } } @Test public void testAvaticaStatementGetMoreResults() throws Exception { - try (Statement statement = remoteConnection.createStatement()) { - assertThat(statement.getMoreResults(), is(false)); + try (Connection remoteConnection = getRemoteConnection()) { + try (Statement statement = remoteConnection.createStatement()) { + assertThat(statement.getMoreResults(), is(false)); + } } } @Test public void testRemoteExecute() throws Exception { - ResultSet resultSet = - remoteConnection.createStatement().executeQuery( - "select * from \"hr\".\"emps\""); - int count = 0; - while (resultSet.next()) { - ++count; + try (Connection remoteConnection = getRemoteConnection()) { + ResultSet resultSet = + remoteConnection.createStatement().executeQuery( + "select * from \"hr\".\"emps\""); + int count = 0; + while (resultSet.next()) { + ++count; + } + assertThat(count > 0, is(true)); } - assertThat(count > 0, is(true)); } @Test public void testRemoteExecuteMaxRow() throws Exception { - Statement statement = remoteConnection.createStatement(); - statement.setMaxRows(2); - ResultSet resultSet = statement.executeQuery( - "select * from \"hr\".\"emps\""); - int count = 0; - while (resultSet.next()) { - ++count; + try (Connection remoteConnection = getRemoteConnection()) { + Statement statement = remoteConnection.createStatement(); + statement.setMaxRows(2); + ResultSet resultSet = statement.executeQuery( + "select * from \"hr\".\"emps\""); + int count = 0; + while (resultSet.next()) { + ++count; + } + assertThat(count, equalTo(2)); } - assertThat(count, equalTo(2)); } /** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-661">[CALCITE-661] * Remote fetch in Calcite JDBC driver</a>. */ @Test public void testRemotePrepareExecute() throws Exception { - final PreparedStatement preparedStatement = - remoteConnection.prepareStatement("select * from \"hr\".\"emps\""); - ResultSet resultSet = preparedStatement.executeQuery(); - int count = 0; - while (resultSet.next()) { - ++count; + try (Connection remoteConnection = getRemoteConnection()) { + final PreparedStatement preparedStatement = + remoteConnection.prepareStatement("select * from \"hr\".\"emps\""); + ResultSet resultSet = preparedStatement.executeQuery(); + int count = 0; + while (resultSet.next()) { + ++count; + } + assertThat(count > 0, is(true)); } - assertThat(count > 0, is(true)); } public static Connection makeConnection() throws Exception { http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/test/java/org/apache/calcite/test/CalciteAssert.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java index 2a30093..7078f8d 100644 --- a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java +++ b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java @@ -50,20 +50,19 @@ import org.apache.calcite.util.JsonBuilder; import org.apache.calcite.util.Pair; import org.apache.calcite.util.Util; +import org.apache.commons.dbcp2.PoolableConnectionFactory; +import org.apache.commons.dbcp2.PoolingDataSource; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.pool2.impl.GenericObjectPool; import com.google.common.base.Function; import com.google.common.base.Functions; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultiset; import com.google.common.collect.Lists; -import com.google.common.util.concurrent.UncheckedExecutionException; import net.hydromatic.foodmart.data.hsqldb.FoodmartHsqldb; import net.hydromatic.scott.data.hsqldb.ScottHsqldb; @@ -95,9 +94,7 @@ import java.util.Objects; import java.util.Properties; import java.util.TimeZone; import java.util.TreeSet; -import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.sql.DataSource; @@ -544,18 +541,20 @@ public class CalciteAssert { "With materializationsEnabled=" + materializationsEnabled + ", limit=" + limit; try (final Closer closer = new Closer()) { - if (connection instanceof CalciteConnection) { - CalciteConnection calciteConnection = (CalciteConnection) connection; - calciteConnection.getProperties().setProperty( + if (connection.isWrapperFor(CalciteConnection.class)) { + final CalciteConnection calciteConnection = + connection.unwrap(CalciteConnection.class); + final Properties properties = calciteConnection.getProperties(); + properties.setProperty( CalciteConnectionProperty.MATERIALIZATIONS_ENABLED.camelName(), Boolean.toString(materializationsEnabled)); - calciteConnection.getProperties().setProperty( + properties.setProperty( CalciteConnectionProperty.CREATE_MATERIALIZATIONS.camelName(), Boolean.toString(materializationsEnabled)); - if (!calciteConnection.getProperties() + if (!properties .containsKey(CalciteConnectionProperty.TIME_ZONE.camelName())) { // Do not override id some test has already set this property. - calciteConnection.getProperties().setProperty( + properties.setProperty( CalciteConnectionProperty.TIME_ZONE.camelName(), DateTimeUtils.UTC_ZONE.getID()); } @@ -1031,8 +1030,7 @@ public class CalciteAssert { public AssertThat connectThrows( Function<Throwable, Void> exceptionChecker) { Throwable throwable; - try { - Connection x = connectionFactory.createConnection(); + try (Connection x = connectionFactory.createConnection()) { try { x.close(); } catch (SQLException e) { @@ -1060,16 +1058,13 @@ public class CalciteAssert { /** Creates a {@link DataContext} and executes a callback. */ public <T> AssertThat doWithDataContext(Function<DataContext, T> fn) throws Exception { - CalciteConnection connection = - (CalciteConnection) connectionFactory.createConnection(); - final DataContext dataContext = CalciteMetaImpl.createDataContext( - connection); - try { + try (CalciteConnection connection = + (CalciteConnection) connectionFactory.createConnection()) { + final DataContext dataContext = + CalciteMetaImpl.createDataContext(connection); T t = fn.apply(dataContext); Util.discard(t); return AssertThat.this; - } finally { - connection.close(); } } @@ -1181,31 +1176,18 @@ public class CalciteAssert { /** Connection factory that uses the same instance of connections. */ private static class PoolingConnectionFactory extends ConnectionFactory { - - /** Connection pool. */ - private static class Pool { - private static final LoadingCache<ConnectionFactory, Connection> POOL = - CacheBuilder.newBuilder().build( - new CacheLoader<ConnectionFactory, Connection>() { - public Connection load(@Nonnull ConnectionFactory key) throws Exception { - return key.createConnection(); - } - }); - } - - private final ConnectionFactory factory; + private final PoolingDataSource dataSource; PoolingConnectionFactory(final ConnectionFactory factory) { - this.factory = factory; + final PoolableConnectionFactory connectionFactory = + new PoolableConnectionFactory(factory::createConnection, null); + connectionFactory.setRollbackOnReturn(false); + this.dataSource = new PoolingDataSource<>( + new GenericObjectPool<>(connectionFactory)); } public Connection createConnection() throws SQLException { - try { - return Pool.POOL.get(factory); - } catch (UncheckedExecutionException | ExecutionException e) { - throw new SQLException( - "Unable to get pooled connection for " + factory, e.getCause()); - } + return dataSource.getConnection(); } } @@ -1334,8 +1316,8 @@ public class CalciteAssert { } public final AssertQuery updates(int count) { - try { - assertQuery(createConnection(), sql, limit, materializationsEnabled, + try (final Connection connection = createConnection()) { + assertQuery(connection, sql, limit, materializationsEnabled, hooks, null, checkUpdateCount(count), null); return this; } catch (Exception e) { @@ -1346,8 +1328,8 @@ public class CalciteAssert { protected AssertQuery returns(String sql, Function<ResultSet, Void> checker) { - try { - assertQuery(createConnection(), sql, limit, materializationsEnabled, + try (final Connection connection = createConnection()) { + assertQuery(connection, sql, limit, materializationsEnabled, hooks, checker, null, null); return this; } catch (Exception e) { @@ -1370,8 +1352,8 @@ public class CalciteAssert { } public AssertQuery throws_(String message) { - try { - assertQuery(createConnection(), sql, limit, materializationsEnabled, + try (final Connection connection = createConnection()) { + assertQuery(connection, sql, limit, materializationsEnabled, hooks, null, null, checkException(message)); return this; } catch (Exception e) { @@ -1387,14 +1369,13 @@ public class CalciteAssert { * @param optionalMessage An optional message to check for in the output stacktrace * */ public AssertQuery failsAtValidation(String optionalMessage) { - try { - assertQuery(createConnection(), sql, limit, materializationsEnabled, - hooks, null, null, - checkValidationException(optionalMessage)); + try (final Connection connection = createConnection()) { + assertQuery(connection, sql, limit, materializationsEnabled, + hooks, null, null, checkValidationException(optionalMessage)); return this; } catch (Exception e) { - throw new RuntimeException( - "exception while executing [" + sql + "]", e); + throw new RuntimeException("exception while executing [" + sql + "]", + e); } } @@ -1407,8 +1388,8 @@ public class CalciteAssert { } public AssertQuery runs() { - try { - assertQuery(createConnection(), sql, limit, materializationsEnabled, + try (final Connection connection = createConnection()) { + assertQuery(connection, sql, limit, materializationsEnabled, hooks, null, null, null); return this; } catch (Exception e) { @@ -1418,8 +1399,8 @@ public class CalciteAssert { } public AssertQuery typeIs(String expected) { - try { - assertQuery(createConnection(), sql, limit, false, + try (final Connection connection = createConnection()) { + assertQuery(connection, sql, limit, false, hooks, checkResultType(expected), null, null); return this; } catch (Exception e) { @@ -1436,8 +1417,8 @@ public class CalciteAssert { } public AssertQuery convertMatches(final Function<RelNode, Void> checker) { - try { - assertPrepare(createConnection(), sql, this.materializationsEnabled, + try (final Connection connection = createConnection()) { + assertPrepare(connection, sql, this.materializationsEnabled, checker, null); return this; } catch (Exception e) { @@ -1448,9 +1429,8 @@ public class CalciteAssert { public AssertQuery substitutionMatches( final Function<RelNode, Void> checker) { - try { - assertPrepare(createConnection(), sql, materializationsEnabled, - null, checker); + try (final Connection connection = createConnection()) { + assertPrepare(connection, sql, materializationsEnabled, null, checker); return this; } catch (Exception e) { throw new RuntimeException("exception while preparing [" + sql + "]", @@ -1512,8 +1492,8 @@ public class CalciteAssert { return null; } }); - try { - assertQuery(createConnection(), sql, limit, materializationsEnabled, + try (final Connection connection = createConnection()) { + assertQuery(connection, sql, limit, materializationsEnabled, hooks, null, checkUpdate, null); assertNotNull(plan); } catch (Exception e) { @@ -1535,8 +1515,8 @@ public class CalciteAssert { return null; } }); - try { - assertQuery(createConnection(), sql, limit, materializationsEnabled, + try (final Connection connection = createConnection()) { + assertQuery(connection, sql, limit, materializationsEnabled, hooks, null, null, null); predicate1.apply(list); return this; @@ -1617,8 +1597,7 @@ public class CalciteAssert { } public final AssertMetaData returns(Function<ResultSet, Void> checker) { - try { - Connection c = connectionFactory.createConnection(); + try (final Connection c = connectionFactory.createConnection()) { final ResultSet resultSet = function.apply(c); checker.apply(resultSet); resultSet.close(); http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/test/java/org/apache/calcite/test/JdbcTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java b/core/src/test/java/org/apache/calcite/test/JdbcTest.java index f013f3e..fcdc0a6 100644 --- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java +++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java @@ -655,8 +655,7 @@ public class JdbcTest { resultSet.next(); fail("resultSet.next() should throw SQLException when closed"); } catch (SQLException e) { - assertThat(e.getMessage(), - containsString("next() called on closed cursor")); + assertThat(e.getMessage(), containsString("ResultSet closed")); } assertEquals(0, closeCount[0]); assertEquals(0, statementCloseCount[0]); http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/core/src/test/resources/sql/misc.iq ---------------------------------------------------------------------- diff --git a/core/src/test/resources/sql/misc.iq b/core/src/test/resources/sql/misc.iq index e643b97..22d1422 100644 --- a/core/src/test/resources/sql/misc.iq +++ b/core/src/test/resources/sql/misc.iq @@ -170,9 +170,6 @@ select cast(c_timestamp as varchar(20)), cast(c_timestamp as date) from data whe | 1997-02-14 17:32:01 | 1997-02-14 | | 1997-02-15 17:32:01 | 1997-02-15 | | 1997-02-16 17:32:01 | 1997-02-16 | -| 0097-02-14 17:32:01 | 0097-02-14 | -| 0597-02-18 17:32:01 | 0597-02-18 | -| 1097-02-22 17:32:01 | 1097-02-22 | | 1697-02-16 17:32:01 | 1697-02-16 | | 1797-02-16 17:32:01 | 1797-02-16 | | 1897-02-16 17:32:01 | 1897-02-16 | @@ -181,6 +178,9 @@ select cast(c_timestamp as varchar(20)), cast(c_timestamp as date) from data whe | 1996-02-28 17:32:01 | 1996-02-28 | | 1996-02-29 17:32:01 | 1996-02-29 | | 1996-03-01 17:32:01 | 1996-03-01 | +| 0097-02-16 17:32:01 | 0097-02-16 | +| 0597-02-16 17:32:01 | 0597-02-16 | +| 1097-02-16 17:32:01 | 1097-02-16 | +---------------------+------------+ (22 rows) http://git-wip-us.apache.org/repos/asf/calcite/blob/b36a1072/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index a53a13e..8d4a4db 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ limitations under the License. <!-- This list is in alphabetical order. --> <airlift-tpch.version>0.1</airlift-tpch.version> - <avatica.version>1.11.0</avatica.version> + <avatica.version>1.12.0</avatica.version> <build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version> <cassandra-driver-core.version>3.4.0</cassandra-driver-core.version> <checksum-maven-plugin.version>1.2</checksum-maven-plugin.version>
