简体   繁体   中英

CSV upload into BigQuery partitioned table using a string field as partition

I need to upload csv file into bigquery table. My question is if "datestamp_column" is STRING how I can use it as partition field?

An example value from "datestamp_column": 2022-11-25T12:56:48.926500Z

def upload_to_bq():

client = bigquery.Client())

job_config = bigquery.LoadJobConfig(
    schema = client.schema_from_json("schemaa.json"),

    skip_leading_rows=1,
    time_partitioning=bigquery.TimePartitioning(
        type_=bigquery.TimePartitioningType.DAY,
        field="datestamp_column",
        expiration_ms=7776000000,  # 90 days.
    ),
)

This is failing as it is complaining datestamp_column is STRING and should be TIMESTAMP, DATE or DATETIME

To be able using the partition on the datestamp_column field, you have to use TIMESTAMP , DATE or DATETIME .

The format you indicated for this field corresponds to a timestamp: datestamp_column: 2022-11-25T12:56:48.926500Z

In your BigQuery schema, you have to change the column type from STRING to TIMESTAMP for datestamp_column field.

Then your ingestion should work correctly because the timestamp format 2022-11-25T12:56:48.926500Z should be ingested as TIMESTAMP in BigQuery .

input -> STRING with value 2022-11-25T12:56:48.926500Z
result column in BigQuery is TIMESTAMP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM