Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-16521

N1QL: Avg on a field returns null as output when select of that field returns an empty set

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • bug-backlog
    • 4.1.0
    • query
    • Security Level: Public
    • Untriaged
    • No

    Description

      cbq> select AVG( DISTINCT decimal_field1 ) from simple_table where varchar_field1 LIKE 'aVIiIlSwoJ%';
      {
      "requestID": "6bcb6aae-6a49-4ab6-8344-d7eedb985b3c",
      "signature":

      { "$1": "number" }

      ,
      "results": [

      { "$1": null }

      ],
      "status": "success",
      "metrics":

      { "elapsedTime": "199.822094ms", "executionTime": "199.588874ms", "resultCount": 1, "resultSize": 34 }

      }

      while select for same:
      cbq> select DISTINCT (decimal_field1 ) from simple_table where varchar_field1 LIKE 'aVIiIlSwoJ%';
      {
      "requestID": "ccbed21e-a155-4af7-9511-f28c07c2116d",
      "signature":

      { "decimal_field1": "json" }

      ,
      "results": [
      ],
      "status": "success",
      "metrics":

      { "elapsedTime": "193.466108ms", "executionTime": "193.307897ms", "resultCount": 0, "resultSize": 0 }

      }

      Results in sql are also same:
      mysql> select AVG( DISTINCT decimal_field1 ) from simple_table where varchar_field1 LIKE 'aVIiIlSwoJ%' ;
      --------------------------------

      AVG( DISTINCT decimal_field1 )

      --------------------------------

      NULL

      --------------------------------
      1 row in set (0.01 sec)

      mysql> select DISTINCT (decimal_field1 ) from simple_table where varchar_field1 LIKE 'aVIiIlSwoJ%';
      Empty set (0.00 sec)

      But above statements with group by are treated differently in mysql and n1ql as explained below:
      mysql> select DISTINCT (decimal_field1 ) from simple_table where varchar_field1 LIKE 'aVIiIlSwoJ%' GROUP BY primary_key_id ;
      Empty set (0.00 sec)

      mysql> select AVG( DISTINCT decimal_field1 ) from simple_table where varchar_field1 LIKE 'aVIiIlSwoJ%' GROUP BY primary_key_id ;
      Empty set (0.00 sec)

      cbq> select AVG( DISTINCT decimal_field1 ) from simple_table where varchar_field1 LIKE 'aVIiIlSwoJ%' GROUP BY primary_key_id ;
      {
      "requestID": "d6bb4c01-12df-47af-a024-1f02919ecf09",
      "signature":

      { "$1": "number" }

      ,
      "results": [

      { "$1": null }

      ],
      "status": "success",
      "metrics":

      { "elapsedTime": "158.715687ms", "executionTime": "158.532489ms", "resultCount": 1, "resultSize": 34 }

      }

      Above query should return an empty set with group by similar to:

      cbq> select DISTINCT (decimal_field1 ) from simple_table where varchar_field1 LIKE 'aVIiIlSwoJ%' GROUP BY primary_key_id ;
      {
      "requestID": "778af305-c1ed-49d5-9f1b-4f9cedad03b5",
      "signature":

      { "decimal_field1": "json" }

      ,
      "results": [
      {}
      ],
      "status": "success",
      "metrics":

      { "elapsedTime": "159.574506ms", "executionTime": "159.414275ms", "resultCount": 1, "resultSize": 2 }

      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            isha Isha Kandaswamy (Inactive)
            Prerna.Manaktala Prerna Manaktala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty