How to convert SET to DATASET in HPCC / ECL?

590 views Asked by At

I have this SET in ECL

EXPORT TableNames := [
                        'tbl1',
                        'tbl2',
                        'tbl3',
                        'tbl4'
                     ];
APPLY(TableNames, SomeFunctionPreviouslydefined);

... and I want to pass it to a function using APPLY. APPLY does not accept SETs:

"3002: syntax error near \"tblList\" : expected RANGE, ROWSET, SELF, SUCCESS, datarow, dataset, dictionary, module-name, identifier, identifier, function-name, identifier, macro-name, '+', '^', '(', '['"

How can I do it?

1

There are 1 answers

2
David Sette On BEST ANSWER

Although it's not very clear in the documentation (https://hpccsystems.com/training/documentation/all - ECL Language Reference), you can use the DATASET declaration to convert a SET to a DATASET, specifically the form:

[ attr := ] DATASET( recordset [, recstruct ] );

attr The name of the DATASET for later use in other definitions

recordset A set of in-line data records. This can simply name a previously-defined set definition or explicitly use square brackets to indicate an in-line set definition. Within the square brackets records are separated by commas. The records are specified by either: 1) Using curly braces ({}) to surround the field values for each record. The field values within each record are comma-delimited. 2) A comma-delimited list of in-line transform functions that produce the data rows. All the transform functions in the list must produce records in the same result format.

recstruct Optional. The RECORD structure of the recordset. Omittable only if the recordset parameter is just one record or a list of in-line transform functions

So, for your example, you can use:

EXPORT Layout := RECORD
    STRING tableName;  
END;

EXPORT TableNames := [
                        'tbl1',
                        'tbl2',
                        'tbl3',
                        'tbl4'
                     ];

ds_inlineLayout := DATASET(TableNames, {STRING tableName}); // Define the layout inline
ds_explicitLayout := DATASET(TableNames, Layout); // Use a an explicitly defined layout

OUTPUT(ds_inlineLayout);
OUTPUT(ds_explicitLayout);

Finally, to use that in your APPLY:

APPLY(ds_inlineLayout, SomeFunctionPreviouslydefined);