logica icon indicating copy to clipboard operation
logica copied to clipboard

STRUCT columns

Open mhfrantz opened this issue 4 years ago • 2 comments

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.

mhfrantz avatar Apr 17 '21 16:04 mhfrantz

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

mhfrantz avatar Apr 17 '21 17:04 mhfrantz

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.

EvgSkv avatar Apr 18 '21 01:04 EvgSkv