Database Reference
In-Depth Information
it enables real-time analytics. You just have to be careful not to rely on this
behavior for the correctness of your application because it is not guaranteed.
Chapter 11 discusses patterns for working around this weaker guarantee.
Here you dive into the details of using this API.
Before you can insert a row into a table, you must first create the table with
a schema compatible with the rows you will be inserting. You can use the bq
tool to create the table and then insert a row into the table using curl :
$ bq mk -t ch06.streamed
ts:timestamp,label:string,count:integer
$ BASE_URL=https://www.googleapis.com/bigquery/v2
$ PROJECT_ID=317752944021
$ PROJECT_URL=${BASE_URL}/projects/${PROJECT_ID}
$ DATASET_URL=${PROJECT_URL}/datasets/ch06
$ table_url() {
> echo -n ${DATASET_URL}/tables/${1}
> }
$ curl -H "$(python auth.py)" \
> -H 'Content-Type: application/json' \
> --data-binary '{
> "rows": [
> {"json":
{"ts":1381186891,"label":"test","count":42}}
> ]
}' $(table_url streamed)/insertAll
{
"kind": "bigquery#tableDataInsertAllResponse"
}
$ bq head ch06.streamed
+---------------------+-------+-------+
| ts | label | count |
+---------------------+-------+-------+
| 2013-10-07 23:01:11 | test | 42 |
+---------------------+-------+-------+
It may take a minute or so for the row to appear when you list the table
or query it. This delay is only present the first time you insert a row into a
table. Once a streamed row appears in the table, additional rows inserted
Search WWH ::




Custom Search