BigQuery: Export to GCS option disappeared from BigQuery UI - google-bigquery

The option to export to a GCS bucket has disappeared from the BigQuery UI and was replaced with "Export to Google Drive". It's a feature I used a lot for large results and using the export to Drive is not useful at all. It takes very long and I can't work the same way with the file in Drive than I would in GCS. Is there any way I can still export to GCS from BigQuery UI?

The "workaround" for BigQuery UI is to save result as a table (or just have destination table set for query) and after result is available in the table - just use "Export to GCS" option which is "still" available in both Classic and New BQ UI

Related

Importing from bigquery to google sheets limits to 10k rows

I'm trying to import a table from google bigquery to google sheets.
DATA > DATA CONNECTORS > BIG QUERY
but when I import it it says LIMITED to 10,000 rows.
Is there any way to pass that limit?
At the moment, according to the documentation, the BigQuery Sheets connector has a limit of 10,000 rows. Although, there is a work around for this limit, in case you want to overcome it.
You can use Google Cloud Storage (GCS) as a staging ground. So, you can export your data to GCS as a .csv file, then import it in Google Sheets. Below the steps are described:
Exporting data from BigQuery to a .csv on Google Cloud Storage (GCS)
You can export your table to GCS manually using the console, using gcloud command or one of the available API's, here.
I must point that you need to have the required permissions to export data to GCS. Also, pay attention to the limitations: you can export up to 1GB to a single data file, also the destination of the export has to be Cloud Storage.
Google Cloud Storage to Google Sheets using Google Cloud Functions
In order to import your .csv file to Google Sheets, you can create a Cloud Function which every time a new .csv file is uploaded to GCS, it is also exported to Google Sheets.
These following tutorials do exactly what I mentioned above, you can simply follow one of them, link 1 and link 2.
Doing so,you will be able to query all your data using Google Sheets and overcome the limitation of 10,000 rows with the BigQuery Sheets connector.

Is there anyway to load exisiting data/historical from firestore to bigquery?

I used exporting collections to bigquery extension to export collections from firestore. But no data is shown. only if we add new data, new data are displayed. Is there any way to load existing data which is in firestore database? new data added after choosing path for collection works but old data are not retrieved.
According to Firestore export to Bigquery documentation lines:
This extension only sends the content of documents that have been
changed -- it does not export your full dataset of existing documents
into BigQuery.
Given said this and regards to the Bigquery extension guidelines, you can concern two options with aim having all collection documents being exported to Bigquery:
Run fs-bq-import-collection script, reading all the documents
within a collection and forcing inserts to Bigquery sink as explained
here;
Adjust Firestore managed export service, exporting collection
documents and storing them to GCS, assuming that these data files can
be further loaded to Bigquery as well.
Let me know whether you have any further doubts.

Export Google Cloud Datastore and import to BigQuery programmatically

I'm looking for a method to export my Cloud Datastore and import it into BigQuery daily. The manual way is described at google page. I do not find a clean way to automate it.
There isn't a simple way to do this, but you can separate out the two parts: creating appengine backups and loading them into bigquery.
You can use scheduled backups to create datastore backups periodically (https://cloud.google.com/appengine/articles/scheduled_backups).
You can then use Apps Script to automate the BigQuery portion (https://developers.google.com/apps-script/advanced/bigquery#load_csv_data) or use an AppEngine cron to do the same thing.
As of last week there's a proper way to automate this. The most important part is gcloud beta datastore export.
I created a script around it: https://github.com/chees/datastore2bigquery
You could run this in a cron job.
See here for a demo of how it works: https://www.youtube.com/watch?v=dGyQCE3bWkU
Building on #Jordan's answer above, the steps to do this would be:
1) Make a storage bucket
2) Export datastore entities to this bucket
3) Open Big Query Web UI, and load using the Google Cloud file path.
Full tutorial with images is available at this post.
It is possible using the following code. It basically uses App Engine Cron jobs and BigQuery API.
https://github.com/wenzhe/appengine_datastore_bigquery

upload multiple csv from google cloud to bigquery

I need to upload multiple CSV files from my google bucket. Tried pointing to the bucket when creating the dataset, but i received an error. also tried
gsutil load <projectID:dataset.table> gs://mybucket
it didn't work.
I need to upload multiple files at a time as my total data is 2-3 TB and there is a large number of files
You're close. Google Cloud Storage uses gsutil, but BigQuery's command-line utility is "bq". The command you're looking for is bq load <table> gs://mybucket/file.csv.
bq's documentation is over here: https://developers.google.com/bigquery/bq-command-line-tool

How to download all data in a Google BigQuery dataset?

Is there an easy way to directly download all the data contained in a certain dataset on Google BigQuery? I'm actually downloading "as csv", making one query after another, but it doesn't allow me to get more than 15k rows, and rows i need to download are over 5M.
Thank you
You can run BigQuery extraction jobs using the Web UI, the command line tool, or the BigQuery API. The data can be extracted
For example, using the command line tool:
First install and auth using these instructions:
https://developers.google.com/bigquery/bq-command-line-tool-quickstart
Then make sure you have an available Google Cloud Storage bucket (see Google Cloud Console for this purpose).
Then, run the following command:
bq extract my_dataset.my_table gs://mybucket/myfilename.csv
More on extracting data via API here:
https://developers.google.com/bigquery/exporting-data-from-bigquery
Detailed step-by-step to download large query output
enable billing
You have to give your credit card number to Google to export the output, and you might have to pay.
But the free quota (1TB of processed data) should suffice for many hobby projects.
create a project
associate billing to a project
do your query
create a new dataset
click "Show options" and enable "Allow Large Results" if the output is very large
export the query result to a table in the dataset
create a bucket on Cloud Storage.
export the table to the created bucked on Cloud Storage.
make sure to click GZIP compression
use a name like <bucket>/prefix.gz.
If the output is very large, the file name must have an asterisk * and the output will be split into multiple files.
download the table from cloud storage to your computer.
Does not seem possible to download multiple files from the web interface if the large file got split up, but you could install gsutil and run:
gsutil -m cp -r 'gs://<bucket>/prefix_*' .
See also: Download files and folders from Google Storage bucket to a local folder
There is a gsutil in Ubuntu 16.04 but it is an unrelated package.
You must install and setup as documented at: https://cloud.google.com/storage/docs/gsutil
unzip locally:
for f in *.gz; do gunzip "$f"; done
Here is a sample project I needed this for which motivated this answer.
For python you can use following code,it will download data as a dataframe.
from google.cloud import bigquery
def read_from_bqtable(bq_projectname, bq_query):
client = bigquery.Client(bq_projectname)
bq_data = client.query(bq_query).to_dataframe()
return bq_data #return dataframe
bigQueryTableData_df = read_from_bqtable('gcp-project-id', 'SELECT * FROM `gcp-project-id.dataset-name.table-name` ')
yes steps suggested by Michael Manoochehri are correct and easy way to export data from Google Bigquery.
I have written a bash script so that you do not required to do these steps every time , just use my bash script .
below are the github url :
https://github.com/rajnish4dba/GoogleBigQuery_Scripts
scope :
1. export data based on your Big Query SQL.
2. export data based on your table name.
3. transfer your export file to SFtp server.
try it and let me know your feedback.
to help use ExportDataFromBigQuery.sh -h