You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "JD Zheng (JIRA)" <ji...@apache.org> on 2017/05/22 19:02:04 UTC
[jira] [Updated] (CALCITE-1801) RelRunners connection
garbage-collected prematurely
[ https://issues.apache.org/jira/browse/CALCITE-1801?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
JD Zheng updated CALCITE-1801:
------------------------------
Attachment: RelBuilderTest.java
1. Added one helper class RelImplementer.
2. Added two tests (testRunWithRunnersInAWrapperClass() will fail, testRunWithRunnerInAWrapperClass will succeed):
/** Tests {@link org.apache.calcite.tools.RelRunners} for a table scan + filter
* query using a wrapper class */
@Test public void testRunWithRunnersInAWrapperClass() throws Exception {
// Equivalent SQL:
// SELECT * FROM EMP WHERE DEPTNO = 20
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("EMP")
.filter(
builder.equals(builder.field("DEPTNO"), builder.literal(20)))
.build();
// Note that because the table has been resolved in the RelNode tree
// we do not need to supply a "schema" as context to the runner.
try (final ResultSet resultset = RelImplementer.execute(root)) {
String s = CalciteAssert.toString(resultset);
final String result = ""
+ "EMPNO=7369; ENAME=SMITH; JOB=CLERK; MGR=7902; HIREDATE=1980-12-17; SAL=800.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7566; ENAME=JONES; JOB=MANAGER; MGR=7839; HIREDATE=1981-02-04; SAL=2975.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7788; ENAME=SCOTT; JOB=ANALYST; MGR=7566; HIREDATE=1987-04-19; SAL=3000.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7876; ENAME=ADAMS; JOB=CLERK; MGR=7788; HIREDATE=1987-05-23; SAL=1100.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7902; ENAME=FORD; JOB=ANALYST; MGR=7566; HIREDATE=1981-12-03; SAL=3000.00; COMM=null; DEPTNO=20\n";
assertThat(s, is(result));
}
}
/** Tests {@link org.apache.calcite.tools.RelRunner} for a table scan + filter
* query using a wrapper class */
@Test public void testRunWithRunnerInAWrapperClass() throws Exception {
// Equivalent SQL:
// SELECT * FROM EMP WHERE DEPTNO = 20
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root =
builder.scan("EMP")
.filter(
builder.equals(builder.field("DEPTNO"), builder.literal(20)))
.build();
// Note that because the table has been resolved in the RelNode tree
// we do not need to supply a "schema" as context to the runner.
try (final ResultSet resultset = RelImplementer.executeWithRelRunner(root)) {
String s = CalciteAssert.toString(resultset);
final String result = ""
+ "EMPNO=7369; ENAME=SMITH; JOB=CLERK; MGR=7902; HIREDATE=1980-12-17; SAL=800.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7566; ENAME=JONES; JOB=MANAGER; MGR=7839; HIREDATE=1981-02-04; SAL=2975.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7788; ENAME=SCOTT; JOB=ANALYST; MGR=7566; HIREDATE=1987-04-19; SAL=3000.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7876; ENAME=ADAMS; JOB=CLERK; MGR=7788; HIREDATE=1987-05-23; SAL=1100.00; COMM=null; DEPTNO=20\n"
+ "EMPNO=7902; ENAME=FORD; JOB=ANALYST; MGR=7566; HIREDATE=1981-12-03; SAL=3000.00; COMM=null; DEPTNO=20\n";
assertThat(s, is(result));
}
}
Test result:
Tests run: 83, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.26 sec <<< FAILURE! - in org.apache.calcite.test.RelBuilderTest
testRunWithRunnersInAWrapperClass(org.apache.calcite.test.RelBuilderTest) Time elapsed: 0.68 sec <<< ERROR!
java.sql.SQLException: next() called on closed cursor
at org.apache.calcite.test.RelBuilderTest.testRunWithRunnersInAWrapperClass(RelBuilderTest.java:1739)
Results :
Tests in error:
RelBuilderTest.testRunWithRunnersInAWrapperClass:1739 ยป SQL next() called on c...
Tests run: 83, Failures: 0, Errors: 1, Skipped: 0
> RelRunners connection garbage-collected prematurely
> ---------------------------------------------------
>
> Key: CALCITE-1801
> URL: https://issues.apache.org/jira/browse/CALCITE-1801
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.13.0
> Environment: osx 10.11.6, JavaSE-1.8, junit-4.12
> Reporter: JD Zheng
> Assignee: Julian Hyde
> Priority: Minor
> Attachments: RelBuilderTest.java
>
>
> I am using RelRunners to execute pre-built relnode tree. It works perfectly when I put the following code in the junit class:
> protected String execute(RelNode rel) {
> try (final PreparedStatement preparedStatement = RelRunners.run(rel)) {
> final ResultSet resultSet = preparedStatement.executeQuery();
> return printResult(resultSet, true);
> } catch (SQLException e) {
> throw new RuntimeException(e);
> }
> }
> However,if I put these code inside a src class, the returned resultSet is closed.
> More interestingly, if I expand the RelRunners.run() in the method like this:
> public static ResultSet execute(RelNode rel) {
> /*
> try (final PreparedStatement preparedStatement = RelRunners.run(rel)) {
> return preparedStatement.executeQuery();
> } catch (SQLException e) {
> throw new AQLExecuteErrorException(e);
> }
> */
> try (Connection connection = DriverManager.getConnection("jdbc:calcite:")) {
> final RelRunner runner = connection.unwrap(RelRunner.class);
> PreparedStatement preparedStatement = runner.prepare(rel);
> return preparedStatement.executeQuery();
> } catch (SQLException e) {
> throw new AQLExecuteErrorException(e);
> }
> }
> It works again.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)