In this webinar, we will cover advanced concepts and some complex queries. We will give a demo of how to fetch data from BigQuery into tools like Excel, R and python so we can continue further analysis. Along With Hands-on exercise, we will demonstrate how to automate queries using Apps Script and Command Line tool.
9. Interacting with BigQuery
9
BigQuery
C#
Go
Java
Node.jsPHP
Python
Ruby
➢ Direct HTTP requests to the server
➢ Provide idiomatic, generated or
hand-written code in each language
➢ Handle all the low-level details of
communication with the server
➢ Cloud Client Libraries available in
multiple programming languages
REST API
10. OUTLINE
10
1 Interacting with BigQuery
2 Useful Concepts and Queries
3 Automating Queries
4 Exporting Data
5 Joining Online & Offline Data
11. Useful Concepts and Queries
11
Custom
Funnels
Page
Sequence
Analysis
Useful
Functions
Best
Practices
Custom
Funnels
Using
Flatten
12. Page Sequence Analysis
12
• Understand the sequence the users follow to reach a certain page
• The sequences can be modified to be before or after and to also include events
Landing
Page
Page
A
Page
B
Page
C
Contact
Page
13. Custom Funnels
13
• Get unsampled custom funnels with added
benefits
- No Backfilling
- Historical Information
- Apply filters
- Unlimited steps
• Both open and closed funnels
14. 14
Using Flatten
Sample Data Set
• BigQuery uses repeated (nested) fields to
store data
• While querying nested data, BigQuery
automatically flattens the table data
• However, when dealing with more than one
repeated field, we need to explicitly use
FLATTEN on the table
16. 16
Using Flatten
• However, running the query:
• It shows the error:
• Use FLATTEN as per shown in below query to fetch proper results:
17. 17
Useful Functions
• BigQuery functions are more or less similar in nature to that of regular SQL
• However, there are some functions which act differently to an extent
COUNT([DISTINCT] field [, n]) REGEXP_MATCH('str', 'reg_exp')
EXACT_COUNT_DISTINCT(field) REGEXP_REPLACE('orig_str', 'reg_exp', 'replace_str')
GROUP_CONCAT('str' [, separator]) DATEDIFF(<timestamp1>,<timestamp2>)
FIRST(expr), LAST(field) DAY/MONTH/HOUR/MINUTE(<timestamp>)
STRING(numeric_expr),
INTEGER(expr)
TABLE_DATE_RANGE(prefix, timestamp1, timestamp
2)
CONCAT('str1', 'str2', '...') ROW_NUMBER()
DATE(<timestamp>) RANK()
18. Best Practices
18
✓ Start by sketching the expected result
before writing your query
✓ Only select the relevant fields; The
more fields you select, the more data
it has to process and eventually
leading to more time and cost
✓ Avoid using functions as fields when
possible and prefer specific times and
dates, to allow caching
✓ Use intermediate tables for commonly
used subqueries
✓ Use caching whenever possible,
reduce execution time and costing
✓ Format and comment your queries, it
will be easier to read, understand and
debug
✓ Statements are not case-sensitive but
it’s a best practice to capitalize
19. OUTLINE
19
1 Interacting with BigQuery
2 Useful Concepts and Queries
3 Automating Queries
4 Exporting Data
5 Joining Online & Offline Data
21. Automating Queries
21
Using Apps Script
• Google Apps Script is a scripting language based on JavaScript
• Uses Google BigQuery API
Manage BigQuery projects
Upload new data
Execute queries
• https://developers.google.com/apps-script/advanced/bigquery
22. OUTLINE
22
1 Interacting with BigQuery
2 Useful Concepts and Queries
3 Automating Queries
4 Exporting Data
5 Joining Online & Offline Data
24. OUTLINE
24
1 Interacting with BigQuery
2 Useful Concepts and Queries
3 Automating Queries
4 Exporting Data
5 Joining Online & Offline Data
25. Joining Online & Offline Data
25
GA
360
CRM
Data
BigQuery
Using Command-Line Tool
1. Upload CRM data to BigQuery
2. Use join queries to create a Single View
3. Analyze end-to-end user journey
27. Title: How to Make the Best Use of Your Google Analytics 360
Data for eCommerce Businesses
Speakers: Bismayy Mohapatra and Anshul Bhatt
Date: December 14, 2017
Time: 8:30 PM IST
27
Upcoming Webinar