Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-5657

FunctionCallExpr.toSql() and clone() ignore "IGNORE NULLS" case

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • Impala 2.8.0, Impala 2.9.0, Impala 2.10.0
    • Impala 2.10.0
    • Frontend

    Description

      @Override
        public String toSqlImpl() {
          if (label_ != null) return label_;
          // Merge agg fns should have an explicit label.
          Preconditions.checkState(!isMergeAggFn());
          StringBuilder sb = new StringBuilder();
          sb.append(fnName_).append("(");
          if (params_.isStar()) sb.append("*");
          if (params_.isDistinct()) sb.append("DISTINCT ");
          sb.append(Joiner.on(", ").join(childrenToSql())).append(")");
          return sb.toString();
        }
      
      protected FunctionCallExpr(FunctionCallExpr other) {
          super(other);
          fnName_ = other.fnName_;
          isAnalyticFnCall_ = other.isAnalyticFnCall_;
          isInternalFnCall_ = other.isInternalFnCall_;
          mergeAggInputFn_ = other.mergeAggInputFn_ == null ?
              null : (FunctionCallExpr)other.mergeAggInputFn_.clone();
          // Clone the params in a way that keeps the children_ and the params.exprs()
          // in sync. The children have already been cloned in the super c'tor.
          if (other.params_.isStar()) {
            Preconditions.checkState(children_.isEmpty());
            params_ = FunctionParams.createStarParam();
          } else {
            params_ = new FunctionParams(other.params_.isDistinct(), children_);  <------- other.params_.isIgnoreNulls() is ignored.
          }
          label_ = other.label_;
        }
      
      

      We don't include the "IGNORE NULLS" clause if present, causing it to break the cases which rely on it, for example an InlineViewRef. A sample repro.

      [localhost:21000] > create foo(a int, b int);
      [localhost:21000] > create view test_view as select * from (select last_value(b IGNORE NULLS) OVER (PARTITION BY a order by b) from test) x;
      [localhost:21000] > show create view test_view;
      Query: show create view test_view
      +------------------------------------------------------------------------------------------------+
      | result                                                                                         |
      +------------------------------------------------------------------------------------------------+
      | CREATE VIEW incrstat.test_view AS                                                              |
      | SELECT * FROM (SELECT last_value(b) OVER (PARTITION BY a ORDER BY b ASC) FROM incrstat.test) x |
      +------------------------------------------------------------------------------------------------+
      

      Attachments

        Activity

          People

            bharathv Bharath Vissapragada
            bharathv Bharath Vissapragada
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: