1

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.

4

1 回答 1

1
  1. This error makes sense to me for that particular example in the question:

outside of subselect - protoPayload.requestId is not visible anymore - it is a matchingRequestId based on alias in protoPayload.requestId AS matchingRequestId

  1. Please note, after you fix outside (two) references to protoPayload.requestId, next error will be about protoPayload.line.logMessage
    It is also not visible to outer select because a) it is not part of subselect and b) reference to table from subselect

  2. it looks like you oversimplified your example as even if/after above fixed - it still makes no much sense to me - especisaaly because of WHERE matchingRequestId = matchingRequestId

于 2016-01-14T15:20:47.083 回答