Re: Some questions about file handling + some other things

Ralf Schlatterbeck <[email protected]>
Newsgroups gmane.comp.bug-tracking.roundup.user
Message-ID <[email protected]>
On Wed, Mar 24, 2021 at 09:31:42AM -0400, John P. Rouillard wrote:
> >Looks good (without having tested anything) but I'm not sure to_raw is
> >the correct method to use here in sorting.
> 
> I don't understand. sort_repr is the method I am using. to_raw is
> just a (poorly??) chosen variable name.

Ah. The hyperdb has "from_raw" methods, I thought there would be a
"to_raw", too and that you did reuse that.

> >It is also worth a regression test: If sorting of numbers and/or dates
> >works in SQL (for everything but Multilink properties) I'm quite sure
> >that it would break for anydbm which always sorts in python.
> 
> Yes, Probably needs more data in the db to actually test the ordering
> across multiple items. Anydbm I'll bet is currently broken since it
> would use a string sort order not an integer/number sort order in its
> sorting calls.

No, the regression-test tests that.
But it may be that sorting values that can contain NULL values will not
work.

> >From an implementation point of view, sorting null last requires a
> value to replace null/None so sort(key=...) doesn't throw an error
> trying to sort None against any other type. Without knowing something
> about the property's possible values I don't see how the code can
> choose a suitable value.

I'm doing this explicitly for Postgres (and probably other backends),
the generated SQL for filter calls looks like this:

...
order by (lower(_someclass._title) is not NULL),lower(_someclass._title)
...

So its perfectly fine to put NULL values first or last. And it doesn't
need many changes to make it work.

> Consider a multilink called surveys with a 'rating' property. We want
> to display the links in rating order. 'rating' has values [-5,5] where
> 0 is neutral. You want "no rating given"/unset to sort as 0. I am sure
> there are other examples. Note if 'rating' had values [0,10] then 'no
> rating' should be 5. If you wanted all 'no value given' to sort at the
> end, you choose 11 as the 'no rating given" value.

Hmm, in that case I would not allow NULL values. Should be set to 0 by
an auditor.

> Thoughts?

I'm reluctant to add an explicit property where you can sort NULL values
into the middle of everything else. Doesn't feel right :-)

Note that so far I was considering sorting by hyperdb.filter (and html
wrapper classes) and you were considering only the multilink sorting as
far as I understand.

Ralf
-- 
Dr. Ralf Schlatterbeck                  Tel:   +43/2243/26465-16
Open Source Consulting                  www:   www.runtux.com
Reichergasse 131, A-3411 Weidling       email: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.