Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 通过SQL将BigQuery导出到CSV文件_Google Cloud Platform_Google Bigquery_Google Cloud Storage - Fatal编程技术网

Google cloud platform 通过SQL将BigQuery导出到CSV文件

Google cloud platform 通过SQL将BigQuery导出到CSV文件,google-cloud-platform,google-bigquery,google-cloud-storage,Google Cloud Platform,Google Bigquery,Google Cloud Storage,我想创建一个包含查询结果的CSV文件。 此CSV文件将保存在Google云存储中。(这个查询大约15GB)我需要它是一个文件。有可能吗?如果有,怎么可能 CREATE OR REPLACE TABLE `your-project.your-dataset.chicago_taxitrips_mod` AS ( WITH taxitrips AS ( SELECT trip_start_timestamp, trip_end_timestamp, trip_seco

我想创建一个包含查询结果的CSV文件。 此CSV文件将保存在Google云存储中。(这个查询大约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
  )

如果BigQuery需要输出多个文件,则可以通过对GCS中的文件执行
gsutil
操作,将它们连接成一个文件:

gsutil compose gs://bucket/obj1 [gs://bucket/obj2 ...] gs://bucket/composite
请注意,单个操作中可以组合的组件数量有限(目前为32个)


无法将15GB导出到单个CSV文件(可以导出到多个文件)。我尝试了相同的查询(处理的字节数为15.66 GB),然后尝试将其导出到GCS中的CSV文件,但由于此错误而失败

表gs://[my_bucket]/bq_export/test.csv太大,无法导出到单个文件。指定包含*到碎片导出的uri。请参阅中的“将数据导出到一个或多个文件”

仅允许将最多1 GB的表数据导出到单个文件。由于表超过1GB,因此必须使用通配符,如:

gs://your bucket name/csvfilename*.csv


不确定您为什么希望导出csv文件位于单个文件中,但我知道它太大,无法位于单个文件中。将其写入多个文件会快得多,因为BQ将使用其并行性来使用多个线程写入输出

除非您直接执行查询并读取数据(糟糕的设计),否则您无法控制BigQuery在写入云存储时将生成多少文件。BigQuery是为(擅长)并行而设计的,而不是单线程。15GB的查询比较大,注意成本。