Skip to content

Extend scan syntax to support project and filter #331

@julianhyde

Description

@julianhyde

We propose to extend the syntax of a scan (from expression or join) in a query so that you can easily project a subset of fields and/or apply equality filters. After this issue is fixed,

from e as {deptno = 10, empno, job, ...} from scott.emps;

will be equivalent to

from e in (
  from e in scott.emps
    where e.deptno = 10
    yield {e.empno, e.job});
> val it =
>   [{empno=7782,job="MANAGER"},{empno=7839,job="PRESIDENT"},
>    {empno=7934,job="CLERK"}] : {empno:int, job:string} bag

Note that the output contains fields empno and job because empno is shorthand for empno = empno, and therefore a new field empno is bound (and similarly job). deptno = 10 causes the input to be filtered, but deptno is not returned. sal is not mentioned and therefore it is not returned.

The pattern-matching syntax (field = value to filter, ... for fields we don't want) already works but the records have been unpacked. There is no e for the employee record. With the as syntax, e as {empno, job, ...}, the query step will have one named field e, which is more convenient.

Consider Standard ML:

val i as {j = 1, k = k, ...} = {j = 1, k = "a", l = true};
> val i = {j=1,k="a",l=true} : {j:int, k:string, l:bool}
> val k = "a" : string

This expression binds both i and k, and does not remove the fields j and l from the record. Our proposal is somewhat at odds with this.

There seems to be a bug relating to field ordering. For example, in

from e as {job = "CLERK", deptno, job, ...} in scott.emps;
> java.lang.ClassCastException: class java.lang.Float cannot be cast to
> class java.lang.Integer (java.lang.Float and java.lang.Integer are in
> module java.base of loader 'bootstrap')

I suspect that values from the sal field are being incorrectly assigned to the deptno field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions