7.27 Degenerate Apply operation to Cartesian product
Associate two sequences by a certain field, calculate Cartesian product and generate a new table sequence.
Find name of every available teacher for each course according to Teachers table and Courses table.
Teachers:
Teacher | Branch | Courses |
---|---|---|
Petitti | Matematica | 28,33,30,35 |
Canales | Apesca | 11,16,12,17,13,18,14,19 |
Lucero | NavegacionI | 6,11,16,21,7,12,17,22,… |
Bergamaschi | TecPesc | 1,26,2,27,3,28,4,29,5,30 |
… | … | … |
Courses:
ID | Name |
---|---|
1 | lua |
2 | maa |
3 | mia |
4 | jua |
… | … |
The A.news() function is used to calculate Cartesian product between
SPL script:
A | |
---|---|
1 | =T(“Teachers.txt”).run(Courses=Courses.split@cp()) |
2 | =T(“Courses.txt”) |
3 | =A2.news(A1;ID,Name:Course,Teacher,Courses) |
4 | =A3.select(Courses.contain(ID)) |
5 | =A4.group(Course;~.(Teacher).concat@c():Teachers) |
A1 Import Teachers table and split each Courses value into a sequence by the comma.
A2 Import Courses table.
A3 Use A.news() function to calculate Cartesian product of Courses table and Teachers table.
A4 Get records where the current course ID is included in the corresponding sequence of courses.
A5 Group A4’s records by Course and concatenate the sequence of teacher names to form the Teachers value.
Execution result:
Course | Teachers |
---|---|
jua | Bergamaschi,Puebla,Jimenez |
jub | Lucero,Mazza,Puebla,Chiatti,Jimenez,Luceroo |
juc | Canales,Lucero,Mazza,Puebla,Chiatti,Luceroo |
… | … |
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL