You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Laptop huawei <jd...@gmail.com> on 2017/05/19 18:24:23 UTC

RelRunners weird behavior

Hi, 

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. 

Has anyone seen this behavior before or has any insights? Thanks,

-JD

Re: RelRunners weird behavior

Posted by Julian Hyde <jh...@apache.org>.
Thanks! Now, if someone on the list has time to look into it, it would be appreciated…


> On May 22, 2017, at 12:03 PM, Laptop huawei <jd...@gmail.com> wrote:
> 
> I’ve created the jira: https://issues.apache.org/jira/browse/CALCITE-1801
> and attached the test case in RelBuilderTest as suggested.  
> 
> Thanks,
> 
> -JD
> 
>> On May 19, 2017, at 8:12 PM, Julian Hyde <jh...@apache.org> wrote:
>> 
>> You can create a bug by clicking the “create” button on Apache JIRA: https://issues.apache.org/jira/browse/CALCITE.
>> 
>> A test case would be a piece of code that anyone could run to reproduce the problem. Maybe you could add a method to RelBuilderTest similar to testRun().
>> 
>> Julian
>> 
>>> On May 19, 2017, at 2:40 PM, JD Zheng <jd...@gmail.com> wrote:
>>> 
>>> Hi, Julian,
>>> 
>>> Thank you for reply. I am new to the open source community. What do you
>>> mean by "log a bug, with a test case"?
>>> 
>>> -JD
>>> 
>>> On May 19, 2017, at 11:52 AM, Julian Hyde <jh...@apache.org> wrote:
>>> 
>>> Please log a bug, with a test case.
>>> 
>>> Maybe we use some callback to create a connection. And maybe if you are
>>> using an anonymous class it causes the connection to be garbage-collected
>>> sooner.
>>> 
>>> Julian
>>> 
>>> 
>>> On May 19, 2017, at 1:24 PM, Laptop huawei <jd...@gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> 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.
>>> 
>>> Has anyone seen this behavior before or has any insights? Thanks,
>>> 
>>> -JD
>> 
> 


Re: RelRunners weird behavior

Posted by Laptop huawei <jd...@gmail.com>.
I’ve created the jira: https://issues.apache.org/jira/browse/CALCITE-1801
and attached the test case in RelBuilderTest as suggested.  

Thanks,

-JD

> On May 19, 2017, at 8:12 PM, Julian Hyde <jh...@apache.org> wrote:
> 
> You can create a bug by clicking the “create” button on Apache JIRA: https://issues.apache.org/jira/browse/CALCITE.
> 
> A test case would be a piece of code that anyone could run to reproduce the problem. Maybe you could add a method to RelBuilderTest similar to testRun().
> 
> Julian
> 
>> On May 19, 2017, at 2:40 PM, JD Zheng <jd...@gmail.com> wrote:
>> 
>> Hi, Julian,
>> 
>> Thank you for reply. I am new to the open source community. What do you
>> mean by "log a bug, with a test case"?
>> 
>> -JD
>> 
>> On May 19, 2017, at 11:52 AM, Julian Hyde <jh...@apache.org> wrote:
>> 
>> Please log a bug, with a test case.
>> 
>> Maybe we use some callback to create a connection. And maybe if you are
>> using an anonymous class it causes the connection to be garbage-collected
>> sooner.
>> 
>> Julian
>> 
>> 
>> On May 19, 2017, at 1:24 PM, Laptop huawei <jd...@gmail.com> wrote:
>> 
>> Hi,
>> 
>> 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.
>> 
>> Has anyone seen this behavior before or has any insights? Thanks,
>> 
>> -JD
> 


Re: RelRunners weird behavior

Posted by Julian Hyde <jh...@apache.org>.
You can create a bug by clicking the “create” button on Apache JIRA: https://issues.apache.org/jira/browse/CALCITE.

A test case would be a piece of code that anyone could run to reproduce the problem. Maybe you could add a method to RelBuilderTest similar to testRun().

Julian

> On May 19, 2017, at 2:40 PM, JD Zheng <jd...@gmail.com> wrote:
> 
> Hi, Julian,
> 
> Thank you for reply. I am new to the open source community. What do you
> mean by "log a bug, with a test case"?
> 
> -JD
> 
> On May 19, 2017, at 11:52 AM, Julian Hyde <jh...@apache.org> wrote:
> 
> Please log a bug, with a test case.
> 
> Maybe we use some callback to create a connection. And maybe if you are
> using an anonymous class it causes the connection to be garbage-collected
> sooner.
> 
> Julian
> 
> 
> On May 19, 2017, at 1:24 PM, Laptop huawei <jd...@gmail.com> wrote:
> 
> Hi,
> 
> 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.
> 
> Has anyone seen this behavior before or has any insights? Thanks,
> 
> -JD


Re: RelRunners weird behavior

Posted by JD Zheng <jd...@gmail.com>.
Hi, Julian,

Thank you for reply. I am new to the open source community. What do you
mean by "log a bug, with a test case"?

-JD

On May 19, 2017, at 11:52 AM, Julian Hyde <jh...@apache.org> wrote:

Please log a bug, with a test case.

Maybe we use some callback to create a connection. And maybe if you are
using an anonymous class it causes the connection to be garbage-collected
sooner.

Julian


On May 19, 2017, at 1:24 PM, Laptop huawei <jd...@gmail.com> wrote:

Hi,

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.

Has anyone seen this behavior before or has any insights? Thanks,

-JD

Re: RelRunners weird behavior

Posted by Julian Hyde <jh...@apache.org>.
Please log a bug, with a test case.

Maybe we use some callback to create a connection. And maybe if you are using an anonymous class it causes the connection to be garbage-collected sooner.

Julian


> On May 19, 2017, at 1:24 PM, Laptop huawei <jd...@gmail.com> wrote:
> 
> Hi, 
> 
> 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. 
> 
> Has anyone seen this behavior before or has any insights? Thanks,
> 
> -JD