You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Axis (Jira)" <ji...@apache.org> on 2020/01/09 10:10:00 UTC

[jira] [Created] (CALCITE-3720) failed to validate the field in match_recognize phase

Axis created CALCITE-3720:
-----------------------------

             Summary: failed to validate the field in match_recognize phase
                 Key: CALCITE-3720
                 URL: https://issues.apache.org/jira/browse/CALCITE-3720
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.22.0
            Reporter: Axis
             Fix For: 1.22.0


hello, everyone

    the following case is failed when we run it:
{code:java}
@Test public void testMatchRecognize10() {
  final String sql = "select *\n"
      + "  from (select * from emp, unnest(multiset(select*from dept)) where empno > 10) match_recognize\n"
      + "  (\n"
      + "    partition by job, sal\n"
      + "    order by job asc, sal desc, empno\n"
      + "    pattern (strt down+ up+)\n"
      + "    define\n"
      + "      down as down.mgr < PREV(down.mgr),\n"
      + "      up as up.mgr > prev(up.mgr)) as mr";
  sql(sql).ok();
}
{code}
the error message is :

Cycle detected during type-checkingCycle detected during type-checkingjava.lang.AssertionError: Cycle detected during type-checking at org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:93) at org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1057) at org.apache.calcite.sql.validate.AbstractNamespace.getRowType(AbstractNamespace.java:115) at org.apache.calcite.sql.validate.MatchRecognizeNamespace.getRowType(MatchRecognizeNamespace.java:26) at org.apache.calcite.sql.validate.DelegatingScope.resolveInNamespace(DelegatingScope.java:101) at org.apache.calcite.sql.validate.ListScope.resolve(ListScope.java:191) at org.apache.calcite.sql.validate.DelegatingScope.resolve(DelegatingScope.java:89)

 

After checking the calcite code, we found that

when calcite check the field `empno` in condition `where empno > 10`, calcite will try to find all the definitions in scope chain(current scope and parent scopes). But if the empno is not find in current scope(Because of the `unnest`), calcite will try to use the parent scope(SelectScope) to resolve this field, but unluckily ParentScope can see the MatchRecognize scope, and triggle this error.

Now we use the `where emp.empno > 10` to avoid this error, but i still think it is the bug of calcite.

 
{code:java}
{code}
 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)