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

Validation fails for positional aggregate with current_date in 'case' expression

    XMLWordPrintableJSON

Details

    Description

      Steps to reproduce: 
      Add test to SqlValidatorTest.java

        @Test void testPositionalAggregateWithExpandedCurrentDateFunction() {
          SqlConformance defaultPlusOrdinalGroupBy =
              new SqlDelegatingConformance(SqlConformanceEnum.DEFAULT) {
                @Override public boolean isGroupByOrdinal() {
                  return true;
                }
              };
          sql("SELECT HIREDATE >= CURRENT_DATE, COUNT(*) "
              + "FROM EMP GROUP BY 1")
              .withConformance(defaultPlusOrdinalGroupBy)
              .ok();
        }
      

      Expected result
      Validation passed successfully.

      Actual result

      org.apache.calcite.sql.validate.SqlValidatorException: Expression 'EMP.HIREDATE' is not being grouped
      	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:467)
      	at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:560)
      	at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:883)
      	at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:868)
      	at org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:5003)
      	at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:113)
      	at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:40)
      	at org.apache.calcite.sql.SqlIdentifier.accept(SqlIdentifier.java:321)
      	at org.apache.calcite.sql.util.SqlBasicVisitor$ArgHandlerImpl.visitChild(SqlBasicVisitor.java:123)
      	at org.apache.calcite.sql.SqlOperator.acceptCall(SqlOperator.java:879)
      	at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:212)
      	at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:40)
      	at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:139)
      	at org.apache.calcite.sql.util.SqlBasicVisitor.visit(SqlBasicVisitor.java:52)
      	at org.apache.calcite.sql.SqlNodeList.accept(SqlNodeList.java:145)
      	at org.apache.calcite.sql.util.SqlBasicVisitor$ArgHandlerImpl.visitChild(SqlBasicVisitor.java:123)
      	at org.apache.calcite.sql.SqlOperator.acceptCall(SqlOperator.java:879)
      	at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:212)
      	at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:40)
      	at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:139)
      	at org.apache.calcite.sql.util.SqlBasicVisitor$ArgHandlerImpl.visitChild(SqlBasicVisitor.java:123)
      	at org.apache.calcite.sql.SqlAsOperator.acceptCall(SqlAsOperator.java:121)
      	at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:212)
      	at org.apache.calcite.sql.validate.AggChecker.visit(AggChecker.java:40)
      	at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:139)
      	at org.apache.calcite.sql.validate.AggregatingSelectScope.checkAggregateExpr(AggregatingSelectScope.java:212)
      	
      

      Attachments

        Issue Links

          Activity

            People

              ihuzenko Igor Guzenko
              ihuzenko Igor Guzenko
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h
                  2h