[ 
https://issues.apache.org/jira/browse/CALCITE-2283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16594144#comment-16594144
 ] 

Vladimir Sitnikov commented on CALCITE-2283:
--------------------------------------------

Attempt 1

{noformat}select count(distinct(deptno)), count(sal)
from "scott".emp
where 1 = 2;

!ok{noformat}

Output:
{noformat}
Error while executing command OkCommand [sql: select count(distinct(deptno)), 
count(sal)
from "scott".emp
where 1 = 2]
java.lang.RuntimeException: no connection
        at net.hydromatic.quidem.Quidem.checkResult(Quidem.java:308)
        at net.hydromatic.quidem.Quidem.access$2800(Quidem.java:54)
        at 
net.hydromatic.quidem.Quidem$ContextImpl.checkResult(Quidem.java:1747)
        at 
net.hydromatic.quidem.Quidem$CheckResultCommand.execute(Quidem.java:1078)
        at 
net.hydromatic.quidem.Quidem$CompositeCommand.execute(Quidem.java:1548)
        at net.hydromatic.quidem.Quidem.execute(Quidem.java:216)
        at org.apache.calcite.test.QuidemTest.checkRun(QuidemTest.java:175)
        at org.apache.calcite.test.QuidemTest.test(QuidemTest.java:212)
{noformat}


Ok, let's copy what "misc.iq" uses at the top:

{noformat}
!use post
!set outputformat mysql

select count(distinct(deptno)), count(sal)
from "scott".emp
where 1 = 2;

!ok{noformat}

Output 2:
{noformat}!use post
!set outputformat mysql

select count(distinct(deptno)), count(sal)
from "scott".emp
where 1 = 2;

java.sql.SQLException: Error while executing SQL "select 
count(distinct(deptno)), count(sal)
from "scott".emp
where 1 = 2": From line 2, column 6 to line 2, column 16: Object 'scott' not 
found
        at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
        at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
        at 
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:163)
        at 
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227)
        at net.hydromatic.quidem.Quidem.checkResult(Quidem.java:322)
        at net.hydromatic.quidem.Quidem.access$2800(Quidem.java:54)
        at 
net.hydromatic.quidem.Quidem$ContextImpl.checkResult(Quidem.java:1747)
        at 
net.hydromatic.quidem.Quidem$CheckResultCommand.execute(Quidem.java:1078)
        at 
net.hydromatic.quidem.Quidem$CompositeCommand.execute(Quidem.java:1548)
{noformat}

Apparently your original patch put the query to somewhere around line 1327, so 
it looks like there are some non-trivial commands in misc.iq in between lines 
1..1327 

At this point, I gave up and used a dedicated .java file.

Quidem is great for updating all the expected values at once, however it is 
hard to isolate/debug iq tests.
Re JUnit, I believe you did misunderstand me.
Consider the following:
1) Quidem parses iq file as usual (yet it does not execute it)
2) Quidem creates DynamicTests like
{code:java}DynamicTest.dynamicTest(
                        "misc.iq:346 plan for select...",
                        () -> {
                                // relevant code to 
                        }),{code}
3) Those tests should create "new iq file" behind the scenes somehow (e.g. by 
poking on suite start/suite end or something like that)
4) Profit

It is somehow similar to {{@Parameterized}} tests in JUnit4, however you get 
much more control with JUnit 5. That is it would more like "iq runner for 
JUnit" rather than "reimplementing all the tests in JUnit".

PS. Don't get me wrong. I've even submitted a talk that declares that 
"assertThat kind of tests should die in favour of quine-like tests" (that's a 
stretch, but you should get the idea)


> aggregate over empty set , throw java.lang.NullPointerException
> ---------------------------------------------------------------
>
>                 Key: CALCITE-2283
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2283
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.16.0
>            Reporter: foxes
>            Assignee: Julian Hyde
>            Priority: Major
>
> {code:java}
> //代码
> String sql = 
>         "select " +
>         "         count(distinct(bill_id)) as FULLY_REPAY_BILLS2_LST6 ," +
>         "         count(last_month) . as FULLY_REPAY_MONTHS_LST6 " +
>         "from  "  +
>         "         cardBill " +
>         "WHERE   " +
>         "         1=2 ";
> ResultSet result = st.executeQuery(sql.toUpperCase());
> result.next();// this  throw NullPointerException
> {code}
> {code:java}
>  
> Exception in thread "main" java.lang.NullPointerException
> at Baz$4$1.current(Unknown Source)
> at org.apache.calcite.linq4j.Linq4j$EnumeratorIterator.next(Linq4j.java:688)
> at org.apache.calcite.avatica.util.IteratorCursor.next(IteratorCursor.java:46)
> at org.apache.calcite.avatica.AvaticaResultSet.next(AvaticaResultSet.java:207)
> at 
> com.terry.netease.calcite.test.test.TestMemoryQuery.main(TestMemoryQuery.java:84)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147){code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to