-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathReadLocalFile.ecl
40 lines (36 loc) · 1.16 KB
/
ReadLocalFile.ecl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Hack for loading a file local to a Thor, Roxie or hThor node.
*
* @param fullPath The full path to the file; REQUIRED
* @param ipAddress The IP address of the system that hosts the file
* at fullPath; use '127.0.0.1' to specify the local
* system; OPTIONAL, defaults to '127.0.0.1'
*
* @return The contents of the file as a string
*
* Origin: https://github.com/hpccsystems-solutions-lab/Useful_ECL
*/
IMPORT Std;
EXPORT ReadLocalFile(STRING fullPath, STRING ipAddress = '127.0.0.1') := FUNCTION
// Pull in file as a recordset composed of separate text lines
fileLines := DATASET
(
DYNAMIC(Std.File.ExternalLogicalFileName(ipAddress, fullPath)),
{STRING s},
CSV(SEPARATOR('')),
OPT
);
// Combine lines into a single string
singleLine := ROLLUP
(
fileLines,
TRUE,
TRANSFORM
(
RECORDOF(LEFT),
SELF.s := LEFT.s + RIGHT.s
),
STABLE, ORDERED(TRUE)
);
RETURN singleLine[1].s;
END;