它看起來不錯。正如另一種可能適合你,你也可以在每個新的決議,作爲一個單獨的STRUCT
(記錄)存儲內的ARRAY
(重複場),像這樣:
WITH data AS(
select 'APPL' as symbol, ARRAY<STRUCT<date string, time string, resolution INT64, open FLOAT64, high FLOAT64, low FLOAT64, close FLOAT64>> [STRUCT('2017-06-19' as date, '9:30' as time, 5 as resolution, 99.12 as open, 102.52 as high, 94.22 as low, 98.32 as close), STRUCT('2017-06-19' as date, '9:30' as time, 1 as resolution, 99.12 as open, 100.11 as high, 99.01 as low, 100.34 as close)] stock union all
select 'IBM' as symbol, ARRAY<STRUCT<date string, time string, resolution INT64, open FLOAT64, high FLOAT64, low FLOAT64, close FLOAT64>> [STRUCT('2017-06-19' as date, '9:30' as time, 5 as resolution, 40.15 as open, 45.78 as high, 39.18 as low, 44.22 as close)]
)
SELECT * FROM data
導致:
請注意,當您存儲新的分辨率值時,它會爲每個股票定義的ARRAY添加另一行。
您也可以聚集在陣列上的日期水平,像這樣:
WITH data AS(
select 'APPL' as symbol, STRUCT<date string, time string, hit ARRAY<STRUCT<resolution INT64, open FLOAT64, high FLOAT64, low FLOAT64, close FLOAT64>>> ('2017-06-19', '9:30', [STRUCT(1 as resolution, 99.12 as open, 102.52 as high, 94.22 as low, 98.32 as close), STRUCT(5 as resolution, 99.12 as open, 100.11 as high, 99.01 as low, 100.34 as close)]) stock union all
select 'IBM' as symbol, STRUCT<date string, time string, hit ARRAY<STRUCT<resolution INT64, open FLOAT64, high FLOAT64, low FLOAT64, close FLOAT64>>> ('2017-06-19', '9:30', [STRUCT(1 as resolution, 40.15 as open, 45.78 as high, 39.18 as low, 44.22 as close)])
)
SELECT * FROM data
導致:
這種類型的模式可能會給你一定的優勢取決於有多少您正在處理的數據,例如更便宜,更有效的存儲以及更快的查詢(您可能會發現返回Resources Exceeded
錯誤的查詢與其工作之間的差異是明智的使用STRUCTS and ARRAYS)。