Database Reference
In-Depth Information
If you run through the same steps of the Datastore snapshot and import the
results into a new table, you end up with a schema that is different from the
original table. Here is the schema of the resulting table:
$
bq show ch11.devices_multi_type
Table 317752944021:ch11.devices_multi_type
Last modified Schema Total
Rows Total Byt>
----------------- -----------------------------
------------ ---------->
12 Nov 00:56:18 |- added: integer
4 796
. . .
+- storage_gb: record
| |- float: float
| |- integer: integer
| |- provided: string
. . .
The difference is that the
storage_gb
field has been promoted from a
simple integer field to a record field. This is to allow the field to represent
both integer values and floating-point values. For entities that have an
integer value for
storage_gb
, the
integer
subfield will contain the value,
the
float
subfield will be
NULL
, and
provided
will contain the value
integer
. For entities that contain a floating point value for
storage_gb
,
it will be the other way around. In this fashion the strictly-typed schema
represents the flexibility of the NoSQL storage model. In this case it is
relatively simple to use the field in queries. Here is an example of how you
could query the field:
$
bq query \
'SELECT IF(storage_gb.float IS NULL
,
FLOAT(storage_gb.integer)
,
storage_gb.float) storage_gb
FROM ch11.devices_multi_type'
+------------+
| storage_gb |
+------------+