2015-07-07 5 views

risposta

14

O dalla GUI, è possibile utilizzare la tabella dei metadati __TABLES__ interno, ad esempio questo vi darà la dimensione in GB:

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

Solo un commento, Filtro DOVE può essere omesso e si otterrà l'intera dimensione del set di dati. – cepix

5

Ci sono un paio di modi per farlo, ma sappiate che la dimensione della tabella in byte non è disponibile per le tabelle che ricevono attivamente inserimenti di streaming.

A. Utilizzo dello strumento da riga di comando BQ e libreria di file JQ per analizzare JSON.

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

Questo outpus:

17290009238 

B. utilizzando l'API REST di fare una chiamata Tables:get

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

questo restituisce un JSON completo, che è possibile analizzare e ottenere il 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. Non ci sono metatables chiamati __TABLES__ e __TABLES_SUMMARY__

È possibile eseguire una query come:

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

La parte __TABLES__ di quella query può sembrare poco familiare. __TABLES_SUMMARY__ è una tabella che contiene informazioni sulle tabelle in un set di dati. Puoi usare questo meta-tavolo tu stesso. Ad esempio, la query SELECT * FROM publicdata:samples.__TABLES_SUMMARY__ restituirà i metadati relativi alle tabelle nel set di dati publicdata:samples. È anche possibile fare SELECT * FROM publicdata:samples.__TABLES__

campi disponibili:

I campi del __TABLES_SUMMARY__ meta-tavolo (che sono tutti disponibili nella query TABLE_QUERY) includono:

  • table_id: nome della tabella .
  • creation_time: tempo, in millisecondi dal 1/1/1970 UTC, che la tabella è stata creata. È lo stesso del campo creation_time sul tavolo.
  • type: che si tratti di una vista (2) o di una tabella normale (1).

I seguenti campi sono non disponibile in TABLE_QUERY() dal momento che sono membri di __TABLES__ ma non __TABLES_SUMMARY__. Sono tenuti qui per interesse storico e per documentare parzialmente il __TABLES__ metatabella:

  • last_modified_time: tempo in millisecondi dal 1/1/1970 UTC, che la tabella è stata aggiornata (sia metadati Tavolo contenuti). Notare che se si utilizza lo tabledata.insertAll() per trasmettere i record alla tabella, è possibile che alcuni minuti non siano aggiornati.
  • row_count: numero di righe nella tabella.
  • size_bytes: dimensione totale in byte della tabella.
+0

posso in grado di ottenere i byte totali utilizzando Tables.Get metodo. Attualmente sto avendo 4 tavoli (1 tavolo grande, 3 tavoli più piccoli). Quando ottengo i byte totali per la tabella più grande restituisce 18200091100 (16,95 GB), non ho calcolato tabelle più piccole al momento, ma la fatturazione di query di grandi dimensioni di Google dice '4.035 GB' di archiviazione BigQuery. Perché sto ottenendo queste differenze? –

+0

I prezzi di archiviazione sono ripartiti per MB al secondo. Quando si controllano i costi stimati riportati per il mese corrente, il numero viene ripartito al secondo (ad es. I giorni trascorsi fino a questo mese). Dovresti controllare i numeri per il mese scorso, lì hai i dati completi del mese. Ad ogni modo alla fine del mese vedrai numeri chiusi al tuo gibibyte. – Pentium10

+0

Ho creato il mio tavolo il 24 giugno 2015 (numero totale: 18200091100 [16,95 GB]), ma ricevo la fattura Google del mese di giugno come "4.035 GB" di archiviazione Big Query, ma non so perché gran parte della differenza (~ 12GB)? Anche la fattura della prima settimana di luglio mostra "4.035 GB" di archiviazione Big Query. –