google-cloud-platform - BigQuery 通过 SQL 导出到 CSV 文件
问题描述
我想创建一个包含查询结果的 CSV 文件。此 CSV 文件将保存在 Google Cloud Storage 中。(这个查询大约 15GB)我需要它是一个文件。有可能吗,如果可以的话怎么办?
CREATE OR REPLACE TABLE `your-project.your-dataset.chicago_taxitrips_mod` AS (
WITH
taxitrips AS (
SELECT
trip_start_timestamp,
trip_end_timestamp,
trip_seconds,
trip_miles,
pickup_census_tract,
dropoff_census_tract,
pickup_community_area,
dropoff_community_area,
fare,
tolls,
extras,
trip_total,
payment_type,
company,
pickup_longitude,
pickup_latitude,
dropoff_longitude,
dropoff_latitude,
IF((tips/fare >= 0.2),
1,
0) AS tip_bin
FROM
`bigquery-public-data.chicago_taxi_trips.taxi_trips`
WHERE
trip_miles > 0
AND fare > 0)
SELECT
trip_start_timestamp,
trip_end_timestamp,
trip_seconds,
trip_miles,
pickup_census_tract,
dropoff_census_tract,
pickup_community_area,
dropoff_community_area,
fare,
tolls,
extras,
trip_total,
payment_type,
company,
tip_bin,
ST_AsText(ST_SnapToGrid(ST_GeogPoint(pickup_longitude,
pickup_latitude), 0.1)) AS pickup_grid,
ST_AsText(ST_SnapToGrid(ST_GeogPoint(dropoff_longitude,
dropoff_latitude), 0.1)) AS dropoff_grid,
ST_Distance(ST_GeogPoint(pickup_longitude,
pickup_latitude),
ST_GeogPoint(dropoff_longitude,
dropoff_latitude)) AS euclidean,
CONCAT(ST_AsText(ST_SnapToGrid(ST_GeogPoint(pickup_longitude,
pickup_latitude), 0.1)), ST_AsText(ST_SnapToGrid(ST_GeogPoint(dropoff_longitude,
dropoff_latitude), 0.1))) AS loc_cross
FROM
taxitrips
LIMIT
100000000
)
解决方案
gsutil
如果 BigQuery 需要输出多个文件,您可以使用GCS 中的文件操作将它们连接成一个文件:
gsutil compose gs://bucket/obj1 [gs://bucket/obj2 ...] gs://bucket/composite
请注意,可以在单个操作中组合的组件数量有限制(当前为 32)。
推荐阅读
- react-native - React - 请求获取解析问题
- docker - 从 docker 容器运行 ansible playbook 并部署在主机上
- email - 我应该使用什么程序来创建可以发送动态电子邮件的桌面程序?
- javascript - 结构:哪里放导航栏组件(Vue/React)
- r - “字典”列表到 data.table 列
- inheritance - 来自不相关类的虚拟功能表条目
- r - 如何在 dplyr 中使用 lapply
- apache - 删除共享主机中的 cPanel 配置路径
- javascript - 为什么 innerHTML 不能通过 AJAX 处理响应文本中的 Html 元素?
- java - java.util.Random 使计算速度提高 100 倍?