Database Reference
In-Depth Information
ETags and the If-None-Match Header
One of these advanced HTTP features that can come in handy with BigQuery
is the combination of ETags and the If-None-Match HTTP header.
Sometimes, you want to know if a resource or list of resources has changed
since the last time you read it. ETags are a convenient mechanism to do this;
they are fingerprint values that are returned in the API call. If you read the
same object twice and it has the same ETag, it has not changed. Here is an
example of the ETag returned from a BigQuery Tables.get() call:
$ curl -H "$(python auth.py)" \
"${TABLE_URL}?fields=etag,lastModifiedTime"
{
"etag": "\"yBc8hy8wJ370nDaoIj0ElxNcWUg/
gS3ul2baST3PwOoDSGXgugy2uws\"",
"lastModifiedTime": "1374677458335"
}
You may ask, what is the use of an ETag when you could just match the
results yourself? Although sometimes it can be more convenient to use
the ETag than computing your own hash, the principal value can be in
saving network traffic when you combine it with a request that specifies
the If-None-Match HTTP header. For the ETag previously returned, this
would look like:
$ ETAG=\"yBc8hy8wJ370nDaoIj0ElxNcWUg/
gS3ul2baST3PwOoDSGXgugy2uws\"
$ curl -H "$(python auth.py)" \
- H "If-None-Match: ${ETAG}" \
- w "%{http_code}\\n" \
"${TABLE_URL}?fields=etag,lastModifiedTime"
This uses the -w option to curl to return the HTTP status code. It returns
the HTTP status code 304 Not Modified with an empty response. If you
run a job to update the table, the ETag changes, and the same command
returns a value again:
$ echo foo,1,1.0 >foo.csv
$ bq load --replace scratch.table1 foo.csv \
"f1:string,f2:integer,f3:float"
Search WWH ::




Custom Search