I'm trying to run a query in BigQuery but I receive “Resources exceeded during query execution”.
Actually, I have two tables :
Table user:
Id | User | Latitude | Longitude
1 | 1 | 50.83 | 4.01
2 | 1 | 50.84 | 4.03
3 | 2 | 48.78 | 2.87
4 | 3 | 47.42 | 8.53
…
Table point_of_interest:
Id | Latitude | Longitude | Range | Tag
1 | 50.81 | 3.98 | 0.05 | a;b;c;d
2 | 50.85 | 4.03 | 0.025 | a;c;e;f
3 | 40.80 | 3.87 | 0.04 | a;d;g
4 | 47.42 | 8.57 | 0.08 | b
…
The purpose is to join the tables to tag all user with the Latitude, Longitude and Range.
For that, I used that query :
SELECT
u.User AS id,
GROUP_CONCAT(poi.Tag) AS tag
FROM (
SELECT
u.User,
poi.Tag,
FROM
[user] u
CROSS JOIN
[point_of_interest] poi
WHERE
u.Latitude BETWEEN poi.Latitude – poi.Range AND poi.Latitude + poi.Range
AND
u.Longitude BETWEEN poi.Longitude – poi.Range AND poi.Longitude + poi.Range )
GROUP BY
id
The user table is currently 520 MB and the point_of_interest table is only 565 KB, but will probably grow in the time.
I want to know if there is a better way to fulfill this goal, and the best architecture for that.
EDIT:
I also tried using a range LEFT JOIN EACH
however BigQuery only support equality statements after the ON
keyword.