logica
logica copied to clipboard
STRUCT columns
I have a table with a STRUCT column, e.g. STRUCT<x INT64, y INT64>. It looks like Logica variables can only be alphanumeric plus underscore. Is there a way to refer to the fields of a STRUCT? I tried using backticks for the variable name.
I found one way to do this by aliasing the fields of a STRUCT. For example, if Points is a table containing a point STRUCT with x and y fields:
Points(..r) :- `project.dataset.Points`(..r);
PointsWithX(x: r.point.x, ..r) :- Points(..r);
PointsByX(x:) += 1 :- PointsWithX(x:, point:);
That's right, you can access fields of the record with ., just as in Python, C++, etc.
But you don't have to do aliasing, given the table as you described, you can count points by X as follows.
PointsByX(x: point.x) += 1 :- `project.dataset.Points`(point:);
We do need to make sure this is all well documented.