You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用BigQuery Ruby库创建临时表?文档无对应选项是否可行?

使用BigQuery Ruby库创建临时表

当然可以通过BigQuery Ruby库创建临时表,主要有两种实用方式:

1. 会话级临时表

这种临时表仅在当前BigQuery会话存续期间有效,会话结束后会自动销毁,命名必须以#开头。直接调用create_table方法即可创建:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "你的数据集ID"

# 创建会话临时表
temp_table = dataset.create_table "#my_temp_table" do |table|
  table.schema = [
    { name: "id", type: "INTEGER" },
    { name: "name", type: "STRING" }
  ]
end

2. 带过期时间的临时表

如果需要临时表在一段时间内(比如几小时)可用,可通过expires参数指定过期时间,到期后BigQuery会自动删除该表:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "你的数据集ID"

# 设置1小时后过期
expiration_time = Time.now + 3600

temp_table = dataset.create_table "my_temp_table" do |table|
  table.schema = [
    { name: "id", type: "INTEGER" },
    { name: "name", type: "STRING" }
  ]
  table.expires = expiration_time
end

补充说明:会话级临时表无需绑定特定数据集(也可直接通过bigquery.create_table创建),而带过期时间的临时表必须归属到指定数据集下。

内容的提问来源于stack exchange,提问作者Florent2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 01:25:14