agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
876 stars 47 forks source link

Sorting attributes with constructed types #316

Open farzadbekran opened 2 years ago

farzadbekran commented 2 years ago

Currently attempting to sort a relation by an attribute that has a constructed type throws an AttributeNotSortableError. This is really limiting, since even a simple Maybe type becomes unsortable as well.

I think we need a solution that behaves like sortBy which takes an AtomFunction or maybe something like a ValueExtractionExpr (which behaves like a RelationalExpr) and provides the value on which the sort should be done.

Any Ideas on this?

agentm commented 2 years ago

I can see how that would be annoying indeed. Thus far, I've been avoiding implementing typeclass support at the Atom level, but it might be required. It doesn't make sense (to me, at least) that all Atoms must be sortable.

We'll need to implement some basic typeclass support. Are there other typeclasses that would make sense to have as built-ins?

farzadbekran commented 2 years ago

I'm not sure how the typeclass would work but let's say this is how it would work for these types for example:

These are my initial thoughts on how it would work. Hope it makes sense.

farzadbekran commented 2 years ago

As the user, maybe I could extend the relation and put a sortable atom inside an attribute using an atom function, sort on it and remove it later. But a db level solution would be preferred.