Skip to content

EXCLUDE in the Presence of Schema #91

Open
@alancai98

Description

@alancai98

Context

The current EXCLUDE RFC draft describes EXCLUDE semantics during evaluation time without schema. EXCLUDE’s behavior in the presence of schema is left in the “Unresolved questions” section — https://github.com/partiql/partiql-docs/blob/exclude-rfc/RFCs/0051-exclude-operator.adoc#unresolved-questions.

The reference implementation, partiql-lang-kotlin, does not currently give an error if we EXCLUDE on a tuple attribute that does not exist during compilation and evaluation. Given a closed schema (i.e. no structs or binding tuples are open), it has been confusing in some cases when an EXCLUDE path does not actually exclude any attributes.

SELECT t.*
EXCLUDE t.this_column_dont_exists
FROM t

^ currently no compile-time error

Cases to consider

Assuming closed schema, the following are some examples to correspond to each of the EXCLUDE RFCs unspecified cases w/ schema,

1. EXCLUDE on a tuple attribute that does not exist

SELECT *
EXCLUDE t.flds.does_not_exist
FROM <<
  {
    'foo': 'bar',
    'flds': {
      'a': {
        'field_x': 1,
        'field_y': 'one'
      },
      'b': {
        'field_x': 2,
        'field_y': 'two'
      },
      'c': {
        'field_x': 3,
        'field_y': 'three'
      }
    }
  }
>> AS t

2. EXCLUDE tuple step on a collection or collection step on a tuple

E.g. w/ invalid collection wildcard step when flds just has structs

SELECT *
EXCLUDE t.flds[*].a
FROM <<
  {
    'foo': 'bar',
    'flds': {
      'a': {
        'field_x': 1,
        'field_y': 'one'
      },
      'b': {
        'field_x': 2,
        'field_y': 'two'
      },
      'c': {
        'field_x': 3,
        'field_y': 'three'
      }
    }
  }
>> AS t

3. EXCLUDE on a collection index out of bounds

SELECT * 
EXCLUDE t.a[42].field_x -- out of bounds
FROM <<
    {
        'a': [
            { 'field_x': 1, 'field_y': 'one' },
            { 'field_x': 2, 'field_y': 'two' },
            { 'field_x': 3, 'field_y': 'three' }
        ]
    }
>> AS t

4. EXCLUDE collection index on a bag

SELECT * 
EXCLUDE t.a[1].field_x
FROM <<
    {
        'a': <<       -- bag here rather than an array
            { 'field_x': 1, 'field_y': 'one' },
            { 'field_x': 2, 'field_y': 'two' },
            { 'field_x': 3, 'field_y': 'three' }
        >>
    }
>> AS t

5. EXCLUDE on a tuple attribute with duplicates

SELECT *
EXCLUDE t.foo
FROM <<
  {
    'foo': 'bar1',
    'foo': 'bar2'
  }
>> AS t

6. EXCLUDE with redundant steps

SELECT *
EXCLUDE 
    t.flds,
    t.flds.a -- t.flds.a is already excluded by `t.flds`
FROM <<
  {
    'foo': 'bar',
    'flds': {
      'a': {
        'field_x': 1,
        'field_y': 'one'
      },
      'b': {
        'field_x': 2,
        'field_y': 'two'
      },
      'c': {
        'field_x': 3,
        'field_y': 'three'
      }
    }
  }
>> AS t

Expected outcomes

  1. Decide on the behavior for above cases in presence of closed schema
  2. Decide on the behavior for above cases for no schema and partial schema
  3. Update the behavior in the implementation(s) and/or conformance tests

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions