In this post, we'll go over how to seamlessly export your SQL to Google Colab, or to a .ipynb format.
If you're a data scientist, or just work with python in general, Jupyter Notebooks likely represent the hub where most of your work gets done.
Google Colab is a free cloud service that provides a Jupyter notebook environment, and it requires no setup to use! Perfect for developing deep learning applications, ML education, or just to brush up on your Python skills.
With this trick, you will go from working on your query in superQuery to exploring it further in Colab with zero copying and pasting.
The initial process of setting up your connection to Google Colab goes as follows:
Step 1: Click on "Jupyter Notebook" under your Export Options
Step 2: Add the Google Drive scope
Because Colab works off of your Google Drive, superQuery requires your permission to access your Drive.
Step 3: Choose your account to give permissions for.
Step 4: Review the permissions superQuery is requesting and click on "Allow"
Step 5: Open the SQL in Colab
Step 6: Take action
You have two options here:
- Open the SQL directly in Colab and start exploring.
- Download the query in .ipynb format and explore it in your preferred tool.
Step 7 (optional): Explore in Colab
When you click "Open with Google Colaboratory" from the previous step, Colab will open with five pre-filled cells containing:
1. Code that installs the superQuery module to connect to our python library, superPy. There is also a module for pivot table view of your results.
2. Code that imports the modules.
3a. Authentication of your unique superQuery credentials.
3b. Your query, as it appeared in superQuery**
** If you had any variables inserted, they will be converted back to their literal values here.
4. A pivot display of your query results.
5. Statistics on your query such as cost, data scanned, or whether you received all or partial results from cache.
When running a query for the first time in Colab, you will be prompted to click a link and get a verification code.
Finally, you can explore the results in a pivot table and get various query statistics.