project-m36
project-m36 copied to clipboard
Sorting attributes with constructed types
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?
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?
I'm not sure how the typeclass would work but let's say this is how it would work for these types for example:
Maybe a:Just avalues first, thenNothings. WhileJust as are sorted themselves byas. Howas are sorted should be determined by the typeclass foras.Either a b:Right bs first thenLeft as, whileRights andLefts are sorted based on their values.- Generally types would provide their own
comparefunction or a way to extract a value from the atom that implementsOrdtypeclass.
These are my initial thoughts on how it would work. Hope it makes sense.
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.