Type Decimal identity crisis

This forum is to report technical problems with Rel.
Post Reply
steved
Posts: 49
Joined: Sun Sep 01, 2013 10:53 pm

Type Decimal identity crisis

Post by steved »

Code: Select all

VAR TESTD PRIVATE INIT(     
   REL{TUP{ID 1,D Decimal(5.5,2)},
     TUP{ID 2,D Decimal(7.0,0)},
     TUP{ID 3,D Decimal(7.0,0)},
     TUP{ID 4,D Decimal(7.0,0)},
     TUP{ID 5,D Decimal(14.5,2)},
     TUP{ID 6,D Decimal(23.5,2)},
     TUP{ID 7,D Decimal(23.5,2)},
     TUP{ID 8,D Decimal(35.5,2)},
     TUP{ID 9,D Decimal(42.5,2)}}
		       )KEY{ID};
//SAME D RECOGNIZED AS UNIQUE.
WRITELN TESTD{D};
/*
RELATION {D Decimal} {
     TUPLE {D Decimal(5.5, 2)},
     TUPLE {D Decimal(7.0, 0)},
     TUPLE {D Decimal(7.0, 0)},
     TUPLE {D Decimal(7.0, 0)},
     TUPLE {D Decimal(14.5, 2)},
     TUPLE {D Decimal(23.5, 2)},
     TUPLE {D Decimal(23.5, 2)},
     TUPLE {D Decimal(35.5, 2)},
     TUPLE {D Decimal(42.5, 2)}}
*/
//SAME D RECOGNIZED AS UNIQUE.
WRITELN TESTD GROUP{ID} AS GRP EXTEND {CNT:=COUNT(GRP)}  ORDER(ASC D);
/*
ARRAY {D Decimal, GRP RELATION {ID INTEGER}, CNT INTEGER} {
     TUPLE {D Decimal(5.5, 2), GRP RELATION {ID INTEGER} {
     TUPLE {ID 1}
}, CNT 1},
     TUPLE {D Decimal(7.0, 0), GRP RELATION {ID INTEGER} {
     TUPLE {ID 2}
}, CNT 1},
     TUPLE {D Decimal(7.0, 0), GRP RELATION {ID INTEGER} {
     TUPLE {ID 4}
}, CNT 1},
     TUPLE {D Decimal(7.0, 0), GRP RELATION {ID INTEGER} {
     TUPLE {ID 3}
}, CNT 1},
     TUPLE {D Decimal(14.5, 2), GRP RELATION {ID INTEGER} {
     TUPLE {ID 5}
}, CNT 1},
     TUPLE {D Decimal(23.5, 2), GRP RELATION {ID INTEGER} {
     TUPLE {ID 7}
}, CNT 1},
     TUPLE {D Decimal(23.5, 2), GRP RELATION {ID INTEGER} {
     TUPLE {ID 6}
}, CNT 1},
     TUPLE {D Decimal(35.5, 2), GRP RELATION {ID INTEGER} {
     TUPLE {ID 8}
}, CNT 1},
     TUPLE {D Decimal(42.5, 2), GRP RELATION {ID INTEGER} {
     TUPLE {ID 9}
}, CNT 1}}
*/
//D RECOGNIZED AS BOTH IDENTITICAL AND UNIQUE.
WRITELN TESTD{D} RANK(ASC D AS R) ;
/*
RELATION {D Decimal, R INTEGER} {
     TUPLE {D Decimal(5.5, 2), R 1},
     TUPLE {D Decimal(7.0, 0), R 2},
     TUPLE {D Decimal(7.0, 0), R 2},
     TUPLE {D Decimal(7.0, 0), R 2},
     TUPLE {D Decimal(14.5, 2), R 3},
     TUPLE {D Decimal(23.5, 2), R 4},
     TUPLE {D Decimal(23.5, 2), R 4},
     TUPLE {D Decimal(35.5, 2), R 5},
     TUPLE {D Decimal(42.5, 2), R 6}}
*/
//D VALUES NOT RECOGNIZED, NO VALUES.
WRITELN SUMMARIZE TESTD BY{D}:{CNT:=COUNT()};
/*
RELATION {D Decimal, CNT INTEGER} {
     TUPLE {D Decimal(5.5, 2), CNT 1},
     TUPLE {D Decimal(7.0, 0), CNT 0},
     TUPLE {D Decimal(7.0, 0), CNT 0},
     TUPLE {D Decimal(7.0, 0), CNT 0},
     TUPLE {D Decimal(14.5, 2), CNT 0},
     TUPLE {D Decimal(23.5, 2), CNT 0},
     TUPLE {D Decimal(23.5, 2), CNT 0},
     TUPLE {D Decimal(35.5, 2), CNT 0},
     TUPLE {D Decimal(42.5, 2), CNT 0}}
//NO D VALUES.
WRITELN SUMMARIZE TESTD BY{D}:{MAXID:=MAX(ID)};
/*
RELATION {D Decimal, MAXID INTEGER} {
     TUPLE {D Decimal(5.5, 2), MAXID 1}ERROR: RS0263: Result of MAX on no values is undefined.
*/
Dave
Site Admin
Posts: 368
Joined: Sun Nov 27, 2005 7:19 pm

Re: Type Decimal identity crisis

Post by Dave »

This is correct behaviour. To perform MAX on DECIMAL values, you need to provide appropriate user-defined aggregate operators. See https://reldb.org/c/index.php/read/user ... operators/
steved
Posts: 49
Joined: Sun Sep 01, 2013 10:53 pm

Re: Type Decimal identity crisis

Post by steved »

I understand the need for a aggregate max operator but what I was really trying to get at
was that duplicate values are not being recognized and eliminated.

Code: Select all

WRITELN 
REL{TUP{D Decimal(7.42,2)},
     TUP{D Decimal(7.42,2)},
     TUP{D Decimal(7.42,2)}} ;
RESULT:

Code: Select all

RELATION {D Decimal} {
     TUPLE {D Decimal(7.42, 2)},
     TUPLE {D Decimal(7.42, 2)},
     TUPLE {D Decimal(7.42, 2)}
}
Or am I really missing something obvious?
Dave
Site Admin
Posts: 368
Joined: Sun Nov 27, 2005 7:19 pm

Re: Type Decimal identity crisis

Post by Dave »

Ah, I see! It looks like there's a bug in the definition of the Decimal type, which is one of the provided Java-based user-defined type examples. At a quick glance, it looks like it's missing some Java method definitions that at one time weren't required, but are now required.

I'll have a look at it later.
Post Reply