Re: Some questions about file handling + some other things

"John P. Rouillard" <[email protected]>
Newsgroups gmane.comp.bug-tracking.roundup.user
Message-ID <[email protected]>
In message <[email protected]>,
Ralf Schlatterbeck writes:
>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.

Nope, I sort of figured that might be the confusion. Glad we got it
sorted.

>> >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.

Well at the very least the test testMultilinkOrdering: "all backends
should return the Multilink numeric-id-sorted" is commented out.

Also are you sure that the sort test is sorting values >= 10? Under
that string sort and integer sort of 1...9 is the same. Can you point
me to an applicable test?

>But it may be that sorting values that can contain NULL values will not
>work.

Ok.

>> >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.

Does that form the tuples like: (TRUE,"A real title"), (FALSE,None) So
you can sort FALSE first or last then subsort TRUE to get it ordered
by title?

>> 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.

Except no answer or N/A (not applicable) is a valid value represented
by None. You could use a -6 or +6 sentinal for N/A etc. But again you
can't sort first/last etc.

>> 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 :-)

Yeah but that may be where the use case wants/needs them.

>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.

I think you are correct. We could have two different methods for these
use cases. So nullfirst=True|False for the property setting in
hyperdb.filter and html wrapper classes.

Then for the case of None in the property of a mutilink item we could
set a value.

But I think that might be confusing.

--
				-- rouilj
John Rouillard
===========================================================================
My employers don't acknowledge my existence much less my opinions.
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.