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

Allow schema.table.column references in GROUP BY

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.5.0
    • Component/s: None
    • Labels:
      None

      Description

      This works fine:

      SELECT DISTINCT "SA"."product"."brand_name" FROM "SA"."product";
      

      But this raises an NPE:

      Connecting to jdbc:calcite:model=inline:{"version":1.0,"defaultSchema":"SA","schemas":[{"name":"SA","type":"jdbc","jdbcSchema":"SA","jdbcUrl":"jdbc:derby:jar:(/opt/src/glimpse/glimpse/GlimpseServe/scala/target/scala-2.11/classes/derby-foodmart.zip)foodmart"}]}
      Connected to: Calcite (version 1.5.0-incubating-SNAPSHOT)
      Driver: Calcite JDBC Driver (version 1.5.0-incubating-SNAPSHOT)
      Autocommit status: true
      Transaction isolation: TRANSACTION_READ_UNCOMMITTED
      sqlline version 1.0.1 by Marc Prud'hommeaux
      0: jdbc:calcite:model=inline:{"version":1.0,"> SELECT "SA"."product"."brand_name" FROM "SA"."product" GROUP BY "SA"."product"."brand_name";
      Error: error while executing SQL "SELECT "SA"."product"."brand_name" FROM "SA"."product" GROUP BY "SA"."product"."brand_name"": null (state=,code=0)
      java.sql.SQLException: error while executing SQL "SELECT "SA"."product"."brand_name" FROM "SA"."product" GROUP BY "SA"."product"."brand_name"": null
      	at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
      	at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:112)
      	at org.apache.calcite.avatica.AvaticaStatement.execute(AvaticaStatement.java:121)
      	at sqlline.SqlLine$Commands.execute(Unknown Source)
      	at sqlline.SqlLine$Commands.sql(Unknown Source)
      	at sqlline.SqlLine.dispatch(Unknown Source)
      	at sqlline.SqlLine.begin(Unknown Source)
      	at sqlline.SqlLine.mainWithInputRedirection(Unknown Source)
      	at sqlline.SqlLine.main(Unknown Source)
      Caused by: java.lang.NullPointerException
      	at org.apache.calcite.sql.validate.IdentifierNamespace.resolve(IdentifierNamespace.java:187)
      	at org.apache.calcite.sql.validate.IdentifierNamespace.getTable(IdentifierNamespace.java:195)
      	at org.apache.calcite.sql.validate.ListScope.findChild(ListScope.java:110)
      	at org.apache.calcite.sql.validate.ListScope.resolve(ListScope.java:164)
      	at org.apache.calcite.sql.validate.DelegatingScope.resolve(DelegatingScope.java:80)
      	at org.apache.calcite.sql.validate.DelegatingScope.fullyQualify(DelegatingScope.java:176)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl$Expander.visit(SqlValidatorImpl.java:4317)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl$Expander.visit(SqlValidatorImpl.java:4297)
      	at org.apache.calcite.sql.SqlIdentifier.accept(SqlIdentifier.java:271)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.expand(SqlValidatorImpl.java:4005)
      	at org.apache.calcite.sql.validate.SqlValidatorUtil.analyzeGroupExpr(SqlValidatorUtil.java:455)
      	at org.apache.calcite.sql.validate.SqlValidatorUtil.convertGroupSet(SqlValidatorUtil.java:426)
      	at org.apache.calcite.sql.validate.SqlValidatorUtil.analyzeGroupItem(SqlValidatorUtil.java:401)
      	at org.apache.calcite.sql.validate.AggregatingSelectScope.<init>(AggregatingSelectScope.java:94)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(SqlValidatorImpl.java:2166)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(SqlValidatorImpl.java:2088)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:802)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:518)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:564)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:223)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:189)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:700)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:586)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:556)
      	at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:207)
      	at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:563)
      	at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:477)
      	at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:110)
      	... 7 more
      

      FTR, the same statement runs fine when executed directly against Derby.

        Issue Links

          Activity

          Hide
          mprudhom Marc Prud'hommeaux added a comment -

          FTR, it looks like you can work around the NPE my aliasing the table to something else. E.g., this works fine:

          SELECT T1."brand_name" FROM "SA"."product" T1 GROUP BY "brand_name";
          
          Show
          mprudhom Marc Prud'hommeaux added a comment - FTR, it looks like you can work around the NPE my aliasing the table to something else. E.g., this works fine: SELECT T1."brand_name" FROM "SA"."product" T1 GROUP BY "brand_name";
          Hide
          julianhyde Julian Hyde added a comment -

          My guess is that it is nothing to do with Derby, and is due to the 3-part schema.table.column as an expression. That form is kind of unusual, as the two-part table_alias.column is always sufficient.

          Show
          julianhyde Julian Hyde added a comment - My guess is that it is nothing to do with Derby, and is due to the 3-part schema.table.column as an expression. That form is kind of unusual, as the two-part table_alias.column is always sufficient.
          Show
          julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/16512edc .
          Hide
          jcamachorodriguez Jesus Camacho Rodriguez added a comment -

          Resolved in release 1.5.0 (2015-11-10)

          Show
          jcamachorodriguez Jesus Camacho Rodriguez added a comment - Resolved in release 1.5.0 (2015-11-10)

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              mprudhom Marc Prud'hommeaux
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development