如何在 HPCC / ECL 中将 SET 转换为 DATASET?

How to convert SET to DATASET in HPCC / ECL?

我在 ECL 中有这个 SET

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

... 我想使用 APPLY 将其传递给函数。 APPLY 不接受 SET:

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

我该怎么做?

虽然在文档(https://hpccsystems.com/training/documentation/all - ECL Language Reference)中不是很清楚,但是可以使用DATASET声明将一个SET转换为DATASET,具体形式为:

[ 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

因此,对于您的示例,您可以使用:

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

最后,在您的申请中使用它:

APPLY(ds_inlineLayout, SomeFunctionPreviouslydefined);