DATASET( childstruct [, COUNT( count ) | LENGTH( size ) ] [, CHOOSEN( maxrecs ) ] )
This form is used as a value type inside a RECORD structure to define child dataset records in a non-normalized flat file. The form without COUNT or LENGTH is the simplest to use, and just means that the dataset the length and data are stored within myfield. The COUNT form limits the number of elements to the count expression. The LENGTH form specifies the size in another field instead of the count. This can only be used for dataset input.
The following alternative syntaxes are also supported:
childstruct fieldname [ SELF.count ]
DATASET newname := fieldname
DATASET fieldname (deprecated form -- will go away post-SR9)
Any operation may be performed on child datasets in hthor and the Rapid Data Delivery Engine (Roxie), but only the following operations are supported in the Data Refinery (Thor):
1) PROJECT, CHOOSEN, TABLE (non-grouped), and filters on child tables.
2) Aggregate operations are allowed on any of the above
3) Several aggregates can be calculated at once by using
summary := TABLE(x.children,{ f1 := COUNT(GROUP),
f2 := SUM(GROUP,x),
f3 := MAX(GROUP,y)});
summary.f1;
4) DATASET[n] is supported to index the child elements
5) SORT(dataset, a, b)[1] is also supported to retrieve the best match.
6) Concatenation of datasets is supported.
7) Temporary TABLEs can be used in conjunction.
8) Initialization of child datasets in temp TABLE definitions allows [ ] to be used to initialize 0 elements.
Note that,
TABLE(ds, { ds.id, ds.children(age != 10) });
is not supported, because a dataset in a record definition means "expand all the fields from the dataset in the output." However adding an identifier creates a form that is supported:
TABLE(ds, { ds.id, newChildren := ds.children(age != 10); });
Example:
ParentRec := {INTEGER1 NameID, STRING20 Name};
ParentTable := DATASET([{1,'Kevin'},{2,'Liz'},
{3,'Mr Nobody'},{4,'Anywhere'}], ParentRec);
ChildRec := {INTEGER1 NameID, STRING20 Addr};
ChildTable := DATASET([ {1,'10 Malt Lane'},{2,'10 Malt Lane'},
{2,'3 The cottages'},{4,'Here'},{4,'There'},
{4,'Near'},{4,'Far'}],ChildRec);
DenormedRec := RECORD
INTEGER1 NameID;
STRING20 Name;
UNSIGNED1 NumRows;
DATASET(ChildRec) Children;
// ChildRec Children; //alternative syntax
END;
DenormedRec ParentMove(ParentRec L) := TRANSFORM
SELF.NumRows := 0;
SELF.Children := [];
SELF := L;
END;
ParentOnly := PROJECT(ParentTable, ParentMove(LEFT));
DenormedRec ChildMove(DenormedRec L,ChildRec R,INTEGER C):=TRANSFORM
SELF.NumRows := C;
SELF.Children := L.Children + R;
SELF := L;
END;
DeNormedRecs := DENORMALIZE(ParentOnly, ChildTable,
LEFT.NameID = RIGHT.NameID,
ChildMove(LEFT,RIGHT,COUNTER));
OUTPUT(DeNormedRecs,,'RTTEMP::TestChildDatasets');
// Using inline DATASET in a TRANSFORM to initialize child records
AkaRec := {STRING20 forename,STRING20 surname};
outputRec := RECORD
UNSIGNED id;
DATASET(AkaRec) children;
END;
inputRec := RECORD
UNSIGNED id;
STRING20 forename;
STRING20 surname;
END;
inPeople := DATASET([
{1,'Kevin','Halliday'},{1,'Kevin','Hall'},{1,'Gawain',''},
{2,'Liz','Halliday'},{2,'Elizabeth','Halliday'},
{2,'Elizabeth','MaidenName'},{3,'Lorraine','Chapman'},
{4,'Richard','Chapman'},{4,'John','Doe'}], inputRec);
outputRec makeFatRecord(inputRec l) := TRANSFORM
SELF.id := l.id;
SELF.children := DATASET([{ l.forename, l.surname }], AkaRec);
END;
fatIn := PROJECT(inPeople, makeFatRecord(LEFT));
outputRec makeChildren(outputRec l, outputRec r) := TRANSFORM
SELF.id := l.id;
SELF.children := l.children + ROW({r.children[1].forename,
r.children[1].surname},
AkaRec);
END;
r := ROLLUP(fatIn, id, makeChildren(LEFT, RIGHT));