Skip to content

Latest commit

 

History

History

GSP071_BigQuery-Qwik-Start-Command-Line

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

GSP071 —— BigQuery: Qwik Start - Command Line

Table of Contents (🔎 Click to expand/collapse)

Overview

Storing and querying massive datasets can be time consuming and expensive without the right hardware and infrastructure. BigQuery is an enterprise data warehouse that solves this problem by enabling super-fast SQL queries using the processing power of Google's infrastructure. Simply move your data into BigQuery and let us handle the hard work. You can control access to both the project and your data based on your business needs, such as giving others the ability to view or query your data.

You can access BigQuery in the Console, Web UI or a command-line tool using a variety of client libraries such as Java, .NET, or Python. There are also a variety of solution providers that you can use to interact with BigQuery.

Examine Table

We can use bq show command for examing the schema of the given table.

$ bq show <PROJECT>:<DATASET.TABLE>

Run Query

To run a query, run the command bq query "[SQL_STATEMENT]".

$ bq query --use_legacy_sql=false \
'SELECT
   word,
   SUM(word_count) AS count
 FROM
   `bigquery-public-data`.samples.shakespeare
 WHERE
   word LIKE "%raisin%"
 GROUP BY
   word'
  • Escape any quotation marks inside the [SQL_STATEMENT] with a \ mark.
  • Use a different quotation mark type than the surrounding marks ("versus").

Create New Table

Every table is stored inside a dataset. A dataset is a group of resources, such as tables and views.

# list any existing datasets in our project
$ bq ls

# create a new dataset with given name
$ bq mk <DATASET_NAME>

# create or update a table and load data
$ bq load <DATASET:TABLE> <FILE> <SCHEMA>

# check the schema of given table
$ bq show <DATASET:TABLE>

Clean Up

Run the bq rm command to remove the dataset with the -r flag to delete all tables in the dataset.

$ bq rm -r <DATASET>

References