Segment’s BigQuery connector makes it easy to load web, mobile, and third-party source data like Salesforce, Zendesk, and Google AdWords into a BigQuery data warehouse. This guide will explain how to set up BigQuery and start loading data into it.
The Segment warehouse connector runs a periodic ETL (Extract - Transform - Load) process to pull raw events and objects and programmatically insert the structured data into your BigQuery cluster.
To do so, our connector first establishes an encrypted connection with the cluster over TLS. The connector then pulls the unstructured raw events from the S3 bucket and associated with the Segment source. The connector processes those raw events into a structured format, at which point a COPY command is executed to transfer the data from our bucket to your BigQuery cluster.
Using BigQuery through Segment means you’ll get a fully managed data pipeline loaded into one of the most powerful and cost-effective data warehouses today.
This document was last updated on April 11, 2018. If you notice any gaps, out-dated information or simply want to leave some feedback to help us improve our documentation, please let us know!
First, you’ll want to set up your BigQuery instance. Once you have an instance with the proper permissions, you’ll add your
projectId to Segment and we’ll begin the first sync. (Note: Project IDs must containt 6-63 lowercase letters, digits, or dashes. They must start with a letter and may not end with a dash.)
Create Project and Enable BigQuery
- Navigate to the Google Developers Console
- Configure Cloud Platform:
- If you don’t have a project already, create one.
- If you have an existing project, you will need to enable the BigQuery API. Once you’ve done so, you should see BigQuery in the “Resources” section of Cloud Platform.
- Note: make sure billing is enabled on your project, otherwise Segment will not be able to write into the cluster.
From the Navigation panel on the left, go to
IAM & admin>
firstname.lastname@example.org a BigQuery Admin
In Segment, go to Workspace > Add destination > Search for BigQuery
Project Idfrom the BigQuery Console
Connect. Your data will begin loading!
BigQuery datasets are broken down into tables and views. Tables contain duplicate data, views do not.
The Segment connector takes advantage of partitioned tables. Partitioned tables allow you to query a subset of data, thus increasing query performance and decreasing costs.
To query a full table, you can query like this:
select * from <project-id>.<source-name>.<collection-name>
To query a specific partitioned table, you can query like this:
select * from <project-id>.<source-name>.<collection-name>$20160809
A view is a virtual table defined by a SQL query. We use views in our de-duplication process to ensure that events that you are querying unique events, and the latest objects from third-party data. All our views are setup to show information from the last 60 days. Whenever possible, we recommend that you query from these views.
Views are appended with
_view , which you can query like this:
select * from <project-id>.<source-name>.<collection-name>_view
At this time, there are no known security requirements to use BigQuery with Segment.
BigQuery charges based on the amount of data scanned by your queries. Views are a derived view over your tables that we use for de-duplication of events. Therefore, we recommend you query a specific view whenever possible to avoid duplicate events and historical objects. It’s important to note that BigQuery views are not cached:
BigQuery’s views are logical views, not materialized views, which means that the query that defines the view is re-executed every time the view is queried. Queries are billed according to the total amount of data in all table fields referenced directly or indirectly by the top-level query.
To save more money, you can query the view and set a destination table, and then query the destination table.
If you typically start exploratory data analysis with
SELECT * consider specifying the fields to reduce costs.
See the section on partitioned tables for details on querying sub-sets of tables.
I need more than 60 days of data in my views. Can I change the view definition?
Absolutely! You will just need to modify one of the references to 60 in the view definition to the number of days of your choosing.
We chose 60 days as it suits the needs for most of our customers. However, you’re welcome to update the definition of the view as long as the name stays the same.
Here is the base query we use when first setting up your views. We are leaving in the placeholders (
%s.%s.%s) where you would want to include the project, dataset and table (in that order).
SELECT * EXCEPT (ROW_NUMBER) FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY id ORDER BY loaded_at DESC) ROW_NUMBER FROM ` + "`%s.%s.%s`" + ` WHERE _PARTITIONTIME BETWEEN TIMESTAMP_TRUNC(TIMESTAMP_MICROS(UNIX_MICROS(CURRENT_TIMESTAMP()) - 60 * 60 * 60 * 24 * 1000000), DAY, 'UTC') AND TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY, 'UTC') ) WHERE ROW_NUMBER = 1
How does BigQuery pricing work?
BigQuery offers both a scalable, pay-as-you-go pricing plan based on the amount of data scanned, or a flat-rate monthly cost. You can learn more about BigQuery pricing here.
BigQuery allows you to setup Cost Controls and Alerts to help control and monitor costs. If you want to learn more about what BigQuery will cost you, they’ve provided this calculator to estimate your costs.
How do I query my data in BigQuery?
You can connect to BigQuery using a BI tool like Mode or Looker, or query directly from the BigQuery console.
BigQuery now supports standard SQL, which you can enable via their query UI. This does not work with views, or with a query that utilizes table range functions.
Does Segment support streaming inserts?
Segment’s connector does not support streaming inserts at this time. If you have a need for streaming data into BigQuery, please contact us.
Can I customize my sync schedule?
Your data will be available in Warehouses within 24-48 hours after your first sync. Your warehouse will then be on a sync schedule based on your Warehouse Plan.
Segment allows you to schedule the time and frequency of loading data into your data warehouse.
You can schedule your warehouse syncs by going to
Warehouse > Settings > Sync Schedule. You can schedule up to the number of syncs allowed on your billing plan.
I’m seeing duplicates in my tables.
This behavior is expected. We only de-duplicate data in your views. See the section on views for more details.
If you have any questions, or see anywhere we can improve our documentation, please let us know!