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

Runtime error where warning needed for heterogeneous field/arrays

    XMLWordPrintable

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Morpheus, 7.0.3
    • Morpheus
    • analytics
    • Macbook Pro w/OSX (but it doesn't matter)
    • Untriaged
    • 1
    • Unknown

    Description

      We need to handle queries better where there is an array-valued field that also has a non-array value.  (E.g., a list of strings or an atomic string, e.g., the empty string being abused to represent missing data.)  We return a runtime error in this case if you do an existential condition on the array - we should probably warn instead. 

      Ex:

      WITH MixedData AS ([{"id":1,"words":["plural", "list"]}, {"id":2, "words":"singular"}])
      SELECT VALUE m FROM MixedData m
      WHERE (SOME w IN m.words SATISFIES w = "list" END);

      This query works happily in N1QL for Query but gets a runtime type error in N1QL for Analytics.  In the latter case it should probably warn and return the same result as the Query service!  This is annoying for users of both (or even just users of Analytics).

      Attachments

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

        Activity

          mike.carey Mike Carey added a comment -

          Here is a follow-up based on the modified query below:

          WITH MixedData AS ([{"id":1,"words":["plural", "list"]}, {"id":2, "words":"list"}])
          SELECT VALUE m FROM MixedData m
          WHERE (SOME w IN m.words SATISFIES w = "list" END);

          The Query service apparently does not equate an object-valued field with a singleton array-valued field.  Instead, it treats it as a type error and ignores it like the Query service likes to do.  We should do the same except warn in Analytics. (And someday the Query service needs to add the promised warnings too, perhaps.) 

          mike.carey Mike Carey added a comment - Here is a follow-up based on the modified query below: WITH MixedData AS ([{"id":1,"words": ["plural", "list"] }, {"id":2, "words":"list"}]) SELECT VALUE m FROM MixedData m WHERE (SOME w IN m.words SATISFIES w = "list" END); The Query service apparently does not equate an object-valued field with a singleton array-valued field.  Instead, it treats it as a type error and ignores it like the Query service likes to do.  We should do the same except warn in Analytics. (And someday the Query service needs to add the promised warnings too, perhaps.) 

          The error is raised by the internal scan-collection() function that iterates over the IN clause input. Currently it fails if the argument is a scalar value. We could fix it to report a warning instead and treat scalar input as an empty list. However, the problem is that this function is also used to iterate over items in a FROM clause. Therefore if we fix the function to report a warning and iterate over an empty list, then the same behavior would apply to the FROM clause.

          Currently the following query fails in Analytics:

          SELECT x FROM 'y' AS x
          

          -->

          "Type mismatch: expected value of type multiset or array, but got the value of type string (in line 1, at column 15)"
          

          After the scan-collection() fix the query will return an empty array instead (with a warning issued).

          However the Query Service allows iteration on a scalar value in a FROM clause:

          SELECT x FROM 'y' AS x
          

          --->

          [  { "x": "y" } ]
          

          I think this issue requires more discussion on the semantics of IN/FROM handling of scalar values.

          dmitry.lychagin Dmitry Lychagin (Inactive) added a comment - The error is raised by the internal scan-collection() function that iterates over the IN clause input. Currently it fails if the argument is a scalar value. We could fix it to report a warning instead and treat scalar input as an empty list. However, the problem is that this function is also used to iterate over items in a FROM clause. Therefore if we fix the function to report a warning and iterate over an empty list, then the same behavior would apply to the FROM clause. Currently the following query fails in Analytics: SELECT x FROM 'y' AS x --> "Type mismatch: expected value of type multiset or array, but got the value of type string (in line 1, at column 15)" After the scan-collection() fix the query will return an empty array instead (with a warning issued). However the Query Service allows iteration on a scalar value in a FROM clause: SELECT x FROM 'y' AS x ---> [ { "x": "y" } ] I think this issue requires more discussion on the semantics of IN/FROM handling of scalar values.
          mike.carey Mike Carey added a comment -

          Hmmm.  WWPD?  (What would PartiQL do, I wonder?)  I don't have a strong opinion on this - I wonder also WWDT (What would Don think?)  In the world of wild schemas, it seems like iteration with a scalar value in a FROM clause with a warning would be okay?

          mike.carey Mike Carey added a comment - Hmmm.  WWPD?  (What would PartiQL do, I wonder?)  I don't have a strong opinion on this - I wonder also WWDT (What would Don think?)  In the world of wild schemas, it seems like iteration with a scalar value in a FROM clause with a warning would be okay?

          People

            till Till Westmann
            mike.carey Mike Carey
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty