Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add take and skip relational operators #204

Closed
julianhyde opened this issue Nov 21, 2023 · 2 comments
Closed

Add take and skip relational operators #204

julianhyde opened this issue Nov 21, 2023 · 2 comments

Comments

@julianhyde
Copy link
Collaborator

julianhyde commented Nov 21, 2023

Add take and skip relational operators:

  • take m returns the first m elements (or the whole list if the list has fewer than m elements);
  • skip n skips the first n elements (or returns the empty list if it has n or fewer elements).

For example,

from e in emps
  order e.hiredate
  skip 2 take 3

returns the 3rd, 4th and 5th employees hired.

The argument to take and skip are int expressions that are evaluated in the same environment as the from. They can, of course, be literals. But they may not reference variables from the pipeline. For example:

(*) Valid
fun topNEmployeesBySalary n =
  from e in emps
    order by sal desc take n;

(*) Invalid
from e in emps
  take e.deptno

take and skip are equivalent to LIMIT and OFFSET keywords in SQL. It is equivalent to the Postgres SQL

SELECT *
FROM Emp AS e
ORDER BY e.hiredate LIMIT 3 OFFSET 2;

or standard SQL

SELECT *
FROM Emp AS e
ORDER BY e.hiredate OFFSET 2 ROWS FETCH NEXT 3 ROWS ONLY;
@julianhyde
Copy link
Collaborator Author

@julianhyde
Copy link
Collaborator Author

Note that tag https://github.com/julianhyde/morel/tree/204-skip-take.0 has some code to work with suchthat that is not present in the current dev branch. We may need to revive it before merging #202.

julianhyde added a commit to julianhyde/morel that referenced this issue Jan 4, 2024
Now that `take` is a keyword, quote uses of `List.take` function
in standard basis library.

Push skip and take to Calcite.

Fix pushing yield into Calcite (it only worked if it was the last step).

Remove call to RelJson constructor deprecated in Calcite 1.36

Fixes hydromatic#204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant