BigQueryloadandtransferjobsfileslimit
创始人
2024-12-12 16:01:24
0

BigQuery加载和传输作业文件限制。在使用BigQuery加载或传输作业时,文件大小和数量都有限制。要解决这个问题,可以分割文件或使用Cloud Storage作为中介。

代码示例:

使用Cloud Storage作为中介:

from google.cloud import bigquery

client = bigquery.Client()

# Set the configuration options.
job_config = bigquery.LoadJobConfig(
    source_format=bigquery.SourceFormat.NEWLINE_DELIMITED_JSON,
    write_disposition=bigquery.WriteDisposition.WRITE_TRUNCATE,
    create_disposition=bigquery.CreateDisposition.CREATE_IF_NEEDED,
)

# Set the destination table.
table_ref = client.dataset('my_dataset').table('my_table')

# Set the Cloud Storage URL.
uri = 'gs://my_bucket/my_file_*.json'

# Load the data from Cloud Storage.
load_job = client.load_table_from_uri(
    uri,
    table_ref,
    job_config=job_config,
)

# Wait for the job to complete.
load_job.result()

文件分割:

from google.cloud import bigquery

client = bigquery.Client()

# Set the configuration options.
job_config = bigquery.LoadJobConfig(
    source_format=bigquery.SourceFormat.NEWLINE_DELIMITED_JSON,
    write_disposition=bigquery.WriteDisposition.WRITE_TRUNCATE,
    create_disposition=bigquery.CreateDisposition.CREATE_IF_NEEDED,
)

# Set the destination table.
table_ref = client.dataset('my_dataset').table('my_table')

# Load the data from multiple files.
load_jobs = []
for i in range(10):
    filename = 'my_file_{0}.json'.format(i)
    with open(filename, 'rb') as source_file:
        load_job = client.load_table_from_file(
            source_file,
            table_ref,
            job_config=job_config,
        )
    load_jobs.append(load_job)

# Wait for the jobs to complete.
for load_job in load_jobs:
    load_job.result()

相关内容

热门资讯

Android Recycle... 要在Android RecyclerView中实现滑动卡片效果,可以按照以下步骤进行操作:首先,在项...
安装apache-beam==... 出现此错误可能是因为用户的Python版本太低,而apache-beam==2.34.0需要更高的P...
Android - 无法确定任... 这个错误通常发生在Android项目中,表示编译Debug版本的Java代码时出现了依赖关系问题。下...
Android - NDK 预... 在Android NDK的构建过程中,LOCAL_SRC_FILES只能包含一个项目。如果需要在ND...
Akka生成Actor问题 在Akka框架中,可以使用ActorSystem对象生成Actor。但是,当我们在Actor类中尝试...
Agora-RTC-React... 出现这个错误原因是因为在 React 组件中使用,import AgoraRTC from “ago...
Alertmanager在pr... 首先,在Prometheus配置文件中,确保Alertmanager URL已正确配置。例如:ale...
Aksnginxdomainb... 在AKS集群中,可以使用Nginx代理服务器实现根据域名进行路由。以下是具体步骤:部署Nginx i...
AddSingleton在.N... 在C#中创建Singleton对象通常是通过私有构造函数和静态属性来实现,例如:public cla...
Alertmanager中的基... Alertmanager中可以使用repeat_interval选项指定在一个告警重复发送前必须等待...