partiql / partiql-lang

The PartiQL language specification
https://partiql.org/partiql-lang
Other
10 stars 1 forks source link

Define comparability for container types #10

Open alancai98 opened 1 year ago

alancai98 commented 1 year ago

The spec mentions the total ordering behavior related to ORDER BY clauses. For example:

PartiQL> SELECT a FROM <<
   |   {'a': []},
   |   {'a': [1, 2, 3]},
   |   {'a': <<>>},
   |   {'a': <<1, 2, 3>>},
   |   {'a': {}},
   |   {'a': {'b': 'value within struct'}}
   | >>
   | ORDER BY a;
==='
[
  {
    'a': []
  },
  {
    'a': [
      1,
      2,
      3
    ]
  },
  {
    'a': {}
  },
  {
    'a': {
      'b': 'value within struct'
    }
  },
  {
    'a': <<>>
  },
  {
    'a': <<
      1,
      2,
      3
    >>
  }
]

The spec should clarify if container types can be compared outside of ORDER BY contexts (e.g. <, >, <=, >=, MAX, MIN, COLL_MAX, COLL_MIN).

The Kotlin implementation currently allows such comparisons but perhaps we should disallow (unless there's a good reason to allow it). There are some potential issues with allowing comparison of container types:

  1. If type system is not closed, the ordering may not be stable
  2. Exposes the natural ordering of the type system