![](/img/trans.png)
[英]Write query results from a table to a partitioned - clustered table in BigQuery
[英]bigquery: create partitioned table from query results does NOT partition old timestamps
我正在嘗試從 BigQuery 中的公共數據集中對表進行分區。
這是所需 output 的standard SQL
查詢:
#standardSQL
CREATE OR REPLACE TABLE <TARGET_TABLE_REF>
PARTITION BY
DATE(trip_start_timestamp)
AS (
SELECT trip_start_timestamp, trip_seconds, fare, tips
FROM bigquery-public-data.chicago_taxi_trips.taxi_trips
WHERE
trip_start_timestamp >= '2022-01-01' AND
trip_start_timestamp < '2022-07-01'
);
我正在使用Python BigQuery Client
運行查詢,output 是一個僅過濾從 2022-06-15 到 2022-06-01 的時間戳的表。
預期的 output當然是一個分區表,其過濾日期范圍在限定過濾器(即 WHERE 子句)中指定。
正如其他帖子中所建議的那樣,我嘗試重新創建目標表,使用 TIMESTAMP 和 DATE 函數轉換時間戳,完全刪除 WHERE 子句等。分區表沒有選擇早於 2022 年 6 月或 2022 年 5 月的時間戳。
這是一個與問題相關的問題,實際上沒有答案,但有一些有用的評論。
我嘗試了什么?
CAST
子句中的時間戳轉換為TIMESTAMP
和/或DATE
PARSE_TIMESTAMP
是否有任何有見地的讀者可以對此重新審視並提供一些見解?
編輯:
由於下面的@Brad 回答無法解決問題,因此我提供了有關本地環境的更多上下文。 我已經用不同的數據集測試了相同的腳本,但仍然無法獲得舊日期的任何 output。 符合條件的過濾器只選擇從 2022 年 5 月到 2022 年 6 月的日期。在此之前的任何時間都不會在 output 表中報告。
OS:
VERSION="22.04.1 LTS (Jammy Jellyfish)"
Linux Kernel 5.15.0-46-generic
Runtime: Python 3.10.4 [GCC 11.2.0] on linux
Text Editor: VSC
Browser: FF
這是一個額外的屏幕截圖,顯示即使在控制台中,腳本也不會返回預期的結果:
如您所見,2022 年 5 月之前沒有日期
已更新以添加指向結果和可執行查詢的鏈接。
我在下面的代碼中重新創建了您的問題和示例查詢。 這些按預期運行,從而產生了此數據。
在此處在 Google Cloud 控制台上共享。
CREATE OR REPLACE TABLE
sandbox.data_mart_target
PARTITION BY
DATE(trip_start_timestamp) AS (
SELECT
trip_start_timestamp,
trip_seconds,
fare,
tips
FROM
bigquery-public-data.chicago_taxi_trips.taxi_trips
WHERE
trip_start_timestamp >= '2022-01-01'
AND trip_start_timestamp < '2022-06-30' );
SELECT
*
FROM
`sandbox.data_mart_target`
WHERE
trip_start_timestamp BETWEEN TIMESTAMP('2022-01-01 00:00:00')
AND TIMESTAMP('2022-01-30 23:59:59');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.