2015-07-07 15 views

Trả lời

14

Hoặc từ GUI, bạn có thể sử dụng siêu dữ liệu __TABLES__ bảng nội bộ, ví dụ này sẽ cung cấp cho bạn các kích thước trong GB:

select 
    sum(size_bytes)/pow(10,9) as size 
from 
    <your_dataset>.__TABLES__ 
where 
    table_id = '<your_table>' 
+2

Chỉ cần một bình luận, bộ lọc WHERE có thể được ommited và bạn sẽ nhận được kích thước tập dữ liệu toàn bộ. – cepix

5

Có một số cách để thực hiện việc này, nhưng lưu ý rằng kích thước của bảng tính bằng byte không khả dụng đối với các bảng đang tích cực nhận chèn trực tuyến.

A. Sử dụng công cụ dòng lệnh BQ và thư viện linux JQ để phân tích cú pháp JSON.

bq --format=json show publicdata:samples.gsod | jq '.numBytes | tonumber' 

outpus này:

17290009238 

B. Sử dụng api REST để làm một cuộc gọi Tables:get

GET https://www.googleapis.com/bigquery/v2/projects/projectId/datasets/datasetId/tables/tableId 

này trả về một JSON đầy đủ, bạn có thể phân tích và nhận được numBytes.

{ 
    "kind": "bigquery#table", 
    "description": "This dataset contains weather information collected by NOAA, such a…", 
    "creationTime": "1335916040125", 
    "tableReference": { 
     "projectId": "publicdata", 
     "tableId": "gsod", 
     "datasetId": "samples" 
    }, 
    "numRows": "114420316", 
    "numBytes": "17290009238", 
    "etag": "\"Gn3Hpo5WaKnpFuT457VBDNMgZBw/MTQxMzkzNzk4Nzg0Ng\"", 
    "location": "US", 
    "lastModifiedTime": "1413937987846", 
    "type": "TABLE", 
    "id": "publicdata:samples.gsod", 
    "selfLink": "https://www.googleapis.com/bigquery/v2/projects/publicdata/datasets…", 
    "schema": { 
     "fields": [ 
      { 
       "description": "The World Meteorological Organization (WMO)/DATSAV3 station numbe…", 
       "type": "INTEGER", 
       "name": "station_number", 
       "mode": "REQUIRED" 
      }, 
      { 
       "description": "The Weather-Bureau-Army-Navy (WBAN) station number where the data w…", 
       "type": "INTEGER", 
       "name": "wban_number", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The year the data was collected in", 
       "type": "INTEGER", 
       "name": "year", 
       "mode": "REQUIRED" 
      }, 
      { 
       "description": "The month the data was collected in", 
       "type": "INTEGER", 
       "name": "month", 
       "mode": "REQUIRED" 
      }, 
      { 
       "description": "The day the data was collected in.", 
       "type": "INTEGER", 
       "name": "day", 
       "mode": "REQUIRED" 
      }, 
      { 
       "description": "The mean temperature of the day in degrees Fahrenheit, accurate to …", 
       "type": "FLOAT", 
       "name": "mean_temp", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The number of observations used to calculate mean_temp.", 
       "type": "INTEGER", 
       "name": "num_mean_temp_samples", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The mean dew point of the day in degrees Fahrenheit, accurate to on…", 
       "type": "FLOAT", 
       "name": "mean_dew_point", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The number of observations used to calculate mean_dew_point.", 
       "type": "INTEGER", 
       "name": "num_mean_dew_point_samples", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The mean sea level pressure of the day in millibars, accurate to on…", 
       "type": "FLOAT", 
       "name": "mean_sealevel_pressure", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The number of observations used to calculate mean_sealevel_pressure…", 
       "type": "INTEGER", 
       "name": "num_mean_sealevel_pressure_samples", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The mean station pressure of the day in millibars, accurate to one …", 
       "type": "FLOAT", 
       "name": "mean_station_pressure", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The number of observations used to calculate mean_station_pressure.…", 
       "type": "INTEGER", 
       "name": "num_mean_station_pressure_samples", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The mean visibility of the day in miles, accurate to one tenth of a…", 
       "type": "FLOAT", 
       "name": "mean_visibility", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The number of observations used to calculate mean_visibility.", 
       "type": "INTEGER", 
       "name": "num_mean_visibility_samples", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The mean wind speed of the day in knots, accurate to one tenth of a…", 
       "type": "FLOAT", 
       "name": "mean_wind_speed", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The number of observations used to calculate mean_wind_speed.", 
       "type": "INTEGER", 
       "name": "num_mean_wind_speed_samples", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The maximum sustained wind speed reported on the day in knots, accu…", 
       "type": "FLOAT", 
       "name": "max_sustained_wind_speed", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The maximum wind gust speed reported on the day in knots, accurate …", 
       "type": "FLOAT", 
       "name": "max_gust_wind_speed", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The maximum temperature of the day in degrees Fahrenheit, accurate …", 
       "type": "FLOAT", 
       "name": "max_temperature", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "Indicates the source of max_temperature.", 
       "type": "BOOLEAN", 
       "name": "max_temperature_explicit", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The minimum temperature of the day in degrees Fahrenheit, accurate …", 
       "type": "FLOAT", 
       "name": "min_temperature", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "Indicates the source of min_temperature.", 
       "type": "BOOLEAN", 
       "name": "min_temperature_explicit", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The total precipitation of the day in inches, accurate to one hundr…", 
       "type": "FLOAT", 
       "name": "total_precipitation", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "The snow depth of the day in inches, accurate to one tenth of an in…", 
       "type": "FLOAT", 
       "name": "snow_depth", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "Indicates if fog was reported on this day.", 
       "type": "BOOLEAN", 
       "name": "fog", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "Indicates if rain was reported on this day.", 
       "type": "BOOLEAN", 
       "name": "rain", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "Indicates if snow was reported on this day.", 
       "type": "BOOLEAN", 
       "name": "snow", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "Indicates if hail was reported on this day.", 
       "type": "BOOLEAN", 
       "name": "hail", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "Indicates if thunder was reported on this day.", 
       "type": "BOOLEAN", 
       "name": "thunder", 
       "mode": "NULLABLE" 
      }, 
      { 
       "description": "Indicates if a tornado was reported on this day.", 
       "type": "BOOLEAN", 
       "name": "tornado", 
       "mode": "NULLABLE" 
      } 
     ] 
    } 
} 

C. Có metatables gọi __TABLES____TABLES_SUMMARY__

Bạn có thể chạy một truy vấn như:

SELECT size_bytes FROM <dataset>.__TABLES__ WHERE table_id='mytablename' 

Phần __TABLES__ của truy vấn đó có thể trông không quen thuộc. __TABLES_SUMMARY__ là một bảng meta chứa thông tin về các bảng trong tập dữ liệu. Bạn có thể tự mình sử dụng bảng meta này. Ví dụ: truy vấn SELECT * FROM publicdata:samples.__TABLES_SUMMARY__ sẽ trả về siêu dữ liệu về các bảng trong bộ dữ liệu publicdata:samples. Bạn cũng có thể làm SELECT * FROM publicdata:samples.__TABLES__

Fields sẵn:

Các trường của __TABLES_SUMMARY__ meta-bảng (tức là tất cả có sẵn trong truy vấn TABLE_QUERY) bao gồm:

  • table_id: tên của bảng .
  • creation_time: thời gian, tính bằng mili giây kể từ 1/1/1970 UTC, rằng bảng đã được tạo. Điều này giống với trường creation_time trên bảng.
  • type: cho dù đó là chế độ xem (2) hay bảng thông thường (1).

Các trường sau đây là không sẵn trong TABLE_QUERY() kể từ khi họ là thành viên của __TABLES__ nhưng không __TABLES_SUMMARY__. Họ đang giữ ở đây đã quan tâm đến lịch sử và tài liệu một phần các __TABLES__ metatable:

  • last_modified_time: thời gian, trong mili giây kể từ 1970/01/01 UTC, rằng bảng đã được cập nhật (hoặc siêu dữ liệu hoặc bảng nội dung). Lưu ý rằng nếu bạn sử dụng tabledata.insertAll() để truyền các bản ghi tới bảng của mình, điều này có thể là một vài phút lỗi thời.
  • row_count: số hàng trong bảng.
  • size_bytes: tổng kích thước tính theo byte của bảng.
+0

tôi có thể có thể nhận được các Tổng Bytes sử dụng Tables.Get phương pháp. Hiện tại tôi đang có 4 bảng (1 bảng lớn, 3 bảng nhỏ hơn). Khi tôi nhận được tổng số byte cho bảng lớn hơn, nó trả về 18200091100 (16,95 GB), tôi không tính bảng nhỏ hơn bây giờ, nhưng thanh toán truy vấn lớn của Google cho biết '4.035 GB' của bộ nhớ BigQuery. Tại sao tôi nhận được những khác biệt đó? –

+0

Giá lưu trữ được chia theo tỷ lệ cho mỗi MB, mỗi giây. Khi bạn kiểm tra chi phí ước tính được báo cáo cho tháng hiện tại, số được tính theo tỷ lệ mỗi giây (ví dụ: số ngày đã trôi qua cho đến tháng này). Bạn nên kiểm tra các con số cho tháng trước, ở đó bạn có dữ liệu đầy đủ tháng. Dù sao vào cuối tháng bạn sẽ thấy các con số đóng lại với gibibyte của bạn. – Pentium10

+0

Tôi đã tạo bảng của mình vào ngày 24 tháng 6 năm 2015 (tổng số byte: 18200091100 [16.95 GB]), nhưng tôi nhận được hóa đơn Google tháng sáu là '4.035 GB' dung lượng Big Query, Nhưng tôi không biết tại sao lại có nhiều sự khác biệt (~ 12GB)? Ngay cả hóa đơn 1 tuần tháng 7 cũng hiển thị '4.035 GB' bộ nhớ Big Query. –

Các vấn đề liên quan