Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-3051

Babel parser should parse special table expressions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.19.0
    • None
    • babel

    Description

      PostgreSQL query

      SELECT * FROM "
      (
          (
            (S.C c INNER JOIN S.N n ON n.id = c.id)
            INNER JOIN S.A a ON (NOT a.isactive)
          ) INNER JOIN S.T t ON t.id = a.id
      )
      

      Reproduction code

      import static org.apache.calcite.sql.parser.SqlParser.configBuilder;
      
      import org.apache.calcite.sql.parser.SqlParseException;
      import org.apache.calcite.sql.parser.SqlParser.Config;
      import org.apache.calcite.sql.parser.babel.SqlBabelParserImpl;
      import org.apache.calcite.sql.validate.SqlConformanceEnum;
      import org.apache.calcite.tools.FrameworkConfig;
      import org.apache.calcite.tools.Frameworks;
      import org.apache.calcite.tools.Planner;
      
      public class Test {
          public static void main(String[] args) throws SqlParseException {
              Config parserConfig = configBuilder().setConformance(SqlConformanceEnum.BABEL).setParserFactory(SqlBabelParserImpl.FACTORY).build();
      
              FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder().parserConfig(parserConfig).build();
      
              Planner planner = Frameworks.getPlanner(frameworkConfig);
              planner.parse("SELECT * FROM (((S.C c INNER JOIN S.N n ON n.id = c.id) INNER JOIN S.A a ON (NOT a.isactive)) INNER JOIN S.T t ON t.id = a.id)");
          }
      }
      

      Returned exception

      Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: Non-query expression encountered in illegal context
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.convertException(SqlBabelParserImpl.java:355)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.normalizeException(SqlBabelParserImpl.java:143)
      	at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:156)
      	at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:181)
      	at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:174)
      	at org.apache.calcite.tools.Planner.parse(Planner.java:50)
      	at com.lab.calcite.Test.main(Test.java:20)
      Caused by: org.apache.calcite.runtime.CalciteException: Non-query expression encountered in illegal context
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      	at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
      	at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:572)
      	at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:787)
      	at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:772)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.checkNonQueryExpression(SqlBabelParserImpl.java:299)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression3(SqlBabelParserImpl.java:3387)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression2b(SqlBabelParserImpl.java:3117)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression2(SqlBabelParserImpl.java:3158)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression(SqlBabelParserImpl.java:3095)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.LeafQueryOrExpr(SqlBabelParserImpl.java:3077)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.QueryOrExpr(SqlBabelParserImpl.java:2999)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.OrderedQueryOrExpr(SqlBabelParserImpl.java:471)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.ParenthesizedQueryOrCommaList(SqlBabelParserImpl.java:638)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression3(SqlBabelParserImpl.java:3411)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression2b(SqlBabelParserImpl.java:3117)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression2(SqlBabelParserImpl.java:3158)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression(SqlBabelParserImpl.java:3095)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.LeafQueryOrExpr(SqlBabelParserImpl.java:3077)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.QueryOrExpr(SqlBabelParserImpl.java:2999)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.OrderedQueryOrExpr(SqlBabelParserImpl.java:471)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.ParenthesizedQueryOrCommaList(SqlBabelParserImpl.java:638)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression3(SqlBabelParserImpl.java:3411)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression2b(SqlBabelParserImpl.java:3117)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression2(SqlBabelParserImpl.java:3158)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.Expression(SqlBabelParserImpl.java:3095)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.LeafQueryOrExpr(SqlBabelParserImpl.java:3077)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.QueryOrExpr(SqlBabelParserImpl.java:2999)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.OrderedQueryOrExpr(SqlBabelParserImpl.java:471)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.ParenthesizedExpression(SqlBabelParserImpl.java:591)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.TableRef2(SqlBabelParserImpl.java:1847)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.TableRef(SqlBabelParserImpl.java:1773)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.FromClause(SqlBabelParserImpl.java:1674)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.SqlSelect(SqlBabelParserImpl.java:933)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.LeafQuery(SqlBabelParserImpl.java:560)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.LeafQueryOrExpr(SqlBabelParserImpl.java:3080)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.QueryOrExpr(SqlBabelParserImpl.java:2999)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.OrderedQueryOrExpr(SqlBabelParserImpl.java:471)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.SqlStmt(SqlBabelParserImpl.java:849)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.SqlStmtEof(SqlBabelParserImpl.java:877)
      	at org.apache.calcite.sql.parser.babel.SqlBabelParserImpl.parseSqlStmtEof(SqlBabelParserImpl.java:199)
      	at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:148)
      	... 4 more
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mgelbana Mohamed Mohsen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: