I was trying to optimize a BigQuery query that I use to search through my AppEngine application logs (exported to BigQuery automatically through Google Cloud Logging) but I got an error that I don't understand.
SELECT
protoPayload.requestId,
protoPayload.line.logMessage
FROM (
SELECT
protoPayload.requestId AS matchingRequestId
FROM
TABLE_DATE_RANGE(MyProject_Logs.appengine_googleapis_com_request_log_, DATE_ADD(CURRENT_TIMESTAMP(), -1, 'HOUR'), CURRENT_TIMESTAMP())
WHERE
protoPayload.resource CONTAINS '/url'
AND protoPayload.line.logMessage CONTAINS 'criteria'
LIMIT 50)
WHERE
protoPayload.requestId = matchingRequestId
results in
Query Failed
Error: Field 'protoPayload.requestId' not found.
Job ID: myProject:job_DZpCc0u52LBFh8DFL0nDCsizo8o
This error does not make sense to me because when I try to execute just the sub-query that also use the protoPayload.requestId
field, it works fine.
Just as a side note, this SO answers better what I am trying to achieve but I am still curious what cause the error in my query.