Column paths

Column paths

If a table has a link column then it can be used to access columns in the referenced table. This is done by specifying a column path which is a sequence of link columns where each next column starts from the table where previous column ends. The last column in a column path is a normal table column or attribute the data of which has to be processed. Syntactically, Prosto uses double colon to separate segments in a column path. For example, in order to access a street column from the Persons table we write the following column path: address::street. This column path starts from the Persons table and ends in the Addresses table.

Use of column paths

Column paths can be used where a computation needs to be done with some data in another table. For example, we might want to define a calculate column using data in a referenced table:

ctx.column_sql(
    "CALCULATE  Persons(position::salary) -> adjusted_salary",
    lambda x: x['position::salary'] * 1.1
)

Here the salary is stored in a table with all existing positions while Persons have a link to the position.

Link columns are used also in aggregate columns for grouping by assuming that all referencing one record means belonging to one group. For example, we could find mean age for each position as follows:

ctx.column_sql(
    "AGGREGATE  Persons (age) -> position -> Positions (mean_age)",
    lambda x: x.mean()
)