sortby with Multiple Orderings

Is there a known problem sorting on more than one ordering expression? I can sort on any one expression just fine, but when I try to use two ordering expressions, the second one is ignored.

thanks for pointing me at that. I will test and
see if there is actually a bug and try to fix it
(which will delay the next quip release a bit…)

Sven Eric

I just checked some examlpes with my current
development version of Quip. It seem to work,
e.g.:

for $x in
(,,cc,bb )

sortby

(name(.)
,0 - string-length(./text())
,./text())

return ($x,“
”)


works just fine.
Can you please provide some example,
which does not work.

Sven Eric

I am building a repository of (anonymous) information about surgical procedures performed at a large research hospital over a period of several years. This data is used to support statistical studies of clinical questions.

In this simplified version of an actual search, I am trying to group by year for 1990 and 1991 those patients who had surgery for the first time (Pri90, Pri91) and those who had a repeat operation (Re90, Re91).


{
for $b in collection(“Demo500”)/PatientRecord,
$c in $b//Surgery
return
(
For $Pri90 in $c[substring(string-value(./@SurgeryDate),1,4)=‘1990’ and
substring(string-value(./HistoryOfCardiacOperations),1,2)=‘No’]
return

{
(
A-Elective Primary ,
{string-value($b/@PatientID)},
{string-value($Pri90/@SurgeryDate)}
)
}
,

For $Pri91 in $c[substring(string-value(./@SurgeryDate),1,4)=‘1991’ and
substring(string-value(./HistoryOfCardiacOperations),1,2)=‘No’]
return

{
(
A-Elective Primary ,
{string-value($b/@PatientID)},
{string-value($Pri91/@SurgeryDate)}
)
}
,


For $Re90 in $c[substring(string-value(./@SurgeryDate),1,4)=‘1990’ and
not(substring(string-value(./HistoryOfCardiacOperations),1,2)=‘No’)]
return

{
(
B-ReOp ,
{string-value($b/@PatientID)},
{string-value($Re90/@SurgeryDate)}
)
}
,

For $Re91 in $c[substring(string-value(./@SurgeryDate),1,4)=‘1991’ and
not(substring(string-value(./HistoryOfCardiacOperations),1,2)=‘No’)]
return

{
(
B-ReOp ,
{string-value($b/@PatientID)},
{string-value($Re91/@SurgeryDate)}
)
}


) sortby (Group, SDate)
}


I was expecting all A-Group items sorted by date followed by all B-Group items sorted by date.


sortby(Group, SDate) produces the following result (all A’s followed by all B’s, but no sort on date):

<?xml version="1.0"?>

<quip:result xmlns:quip=“http://namespaces.softwareag.com/tamino/quip/”>




A-Elective Primary
P-00016
1991-01-03



A-Elective Primary
P-00024
1990-01-02



A-Elective Primary
P-00026
1990-01-02



A-Elective Primary
P-00039
1991-01-03



A-Elective Primary
P-00339
1990-03-23



A-Elective Primary
P-00355
1990-02-20



A-Elective Primary
P-00356
1991-01-16



A-Elective Primary
P-00432
1990-01-04



A-Elective Primary
P-00443
1991-01-02



A-Elective Primary
P-00447
1991-01-02



B-ReOp
P-00163
1991-01-02



B-ReOp
P-00168
1990-01-02



B-ReOp
P-00256
1990-01-02



B-ReOp
P-00269
1990-01-03



B-ReOp
P-00298
1990-01-03



B-ReOp
P-00298
1990-01-04



B-ReOp
P-00446
1991-01-02




</quip:result>



sortby (SDate, Group) produces a correct sort by date, but no grouping of A’s and B’s (see 01-04-1990, 01-02-1991) ):

<?xml version="1.0"?>

<quip:result xmlns:quip=“http://namespaces.softwareag.com/tamino/quip/”>




A-Elective Primary
P-00024
1990-01-02



A-Elective Primary
P-00026
1990-01-02



B-ReOp
P-00168
1990-01-02



B-ReOp
P-00256
1990-01-02



B-ReOp
P-00269
1990-01-03



B-ReOp
P-00298
1990-01-03



B-ReOp
P-00298
1990-01-04



A-Elective Primary
P-00432
1990-01-04



A-Elective Primary
P-00355
1990-02-20



A-Elective Primary
P-00339
1990-03-23



B-ReOp
P-00163
1991-01-02



A-Elective Primary
P-00443
1991-01-02



B-ReOp
P-00446
1991-01-02



A-Elective Primary
P-00447
1991-01-02



A-Elective Primary
P-00016
1991-01-03



A-Elective Primary
P-00039
1991-01-03



A-Elective Primary
P-00356
1991-01-16




</quip:result>



Thanks for helping check this out.

While we’re discussing this query, I would appreciate your comments on another problem I am having. Since it is a different subject, I will post separately under the subject, “Multi-Document Statistics”


Bill

thanks for your bug repotr. It turned out that the
actual bug did not have anything to do with the
sotrby expression itself but some anomalies in
quips compare and equals method concerning text
nodes. As a matter of fact:

((bb
,ba
) sortby (./text(),./d/text()))

did not work, wheras

((bb
,ba
) sortby (string(.),./d/text()))

works fine. The former is comparing text-nodes
whereas the later compares simple types.

I hope to have this fixed with the next version
(quip 2.2.1.1) by the end of next week.

Sven Eric