2,490 questions
42
votes
7
answers
156k
views
How to Pivot table in BigQuery
I am using Google Big Query, and I am trying to get a pivoted result out from public sample data set.
A simple query to an existing table is:
SELECT *
FROM publicdata:samples.shakespeare
LIMIT 10;
...
1
vote
2
answers
17k
views
Unrecognized name: employees at [9:8]
This is giving me an unrecognized name error. Why?
SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
`strange-calling-...
79
votes
12
answers
158k
views
Delete duplicate rows from a BigQuery table
I have a table with >1M rows of data and 20+ columns.
Within my table (tableX) I have identified duplicate records (~80k) in one particular column (troubleColumn).
If possible I would like to retain ...
39
votes
6
answers
46k
views
How to convert a non-partitioned BigQuery table to partitioned?
In June the BQ team announced support for date-partitioned tables. But the guide is missing how to migrate old non-partitioned tables into the new style.
I am looking for a way to update several or ...
5
votes
1
answer
6k
views
How to get an export of firebase analytics full historic data?
I have setup Firebase analytics data to BigQuery. However I received my first export today and it contains all yesterdays user statistics. That is great but I need lifetime statistics history or at ...
11
votes
2
answers
5k
views
Writing different values to different BigQuery tables in Apache Beam
Suppose I have a PCollection<Foo> and I want to write it to multiple BigQuery tables, choosing a potentially different table for each Foo.
How can I do this using the Apache Beam BigQueryIO API?...
22
votes
1
answer
70k
views
Transpose rows into columns in BigQuery (Pivot implementation) [duplicate]
I want to generate a new table and place all key value pairs with keys as column names and values as their respective values using BigQuery.
Example:
**Key** **Value**
channel_title ...
46
votes
4
answers
51k
views
How can I undelete a BigQuery table?
I've accidentally deleted one of my BigQuery tables. Is it possible to get it back? The API doesn't seem to support undelete.
43
votes
8
answers
68k
views
Exporting data from Google Cloud Storage to Amazon S3
I would like to transfer data from a table in BigQuery, into another one in Redshift.
My planned data flow is as follows:
BigQuery -> Google Cloud Storage -> Amazon S3 -> Redshift
I know about ...
26
votes
2
answers
17k
views
How do I use the TABLE_QUERY() function in BigQuery?
A couple of questions about the TABLE_QUERY function:
The examples show using table_id in the query string, are there other fields available?
It seems difficult to debug. I'm getting "error evaluating ...
46
votes
4
answers
88k
views
Google BQ - how to upsert existing data in tables?
I'm using Python client library for loading data in BigQuery tables. I need to update some changed rows in those tables. But I couldn't figure out how to correctly update them? I want some similar ...
27
votes
6
answers
57k
views
Support UNION function in BigQuery SQL
BigQuery does not seem to have support for UNION yet:
https://developers.google.com/bigquery/docs/query-reference
(I don't mean unioning tables together for the source. It has that.)
Is it coming ...
25
votes
5
answers
7k
views
Unable to access BigQuery from local App Engine development server
This is specifically a question relating to server to server authorisation between a python Google AppEngine app and Google's BigQuery, but could be relevant for other cloud services.
tldr; Is it ...
13
votes
1
answer
24k
views
How to create dummy variable columns for thousands of categories in Google BigQuery?
I have a simple table with 2 columns: UserID and Category, and each UserID can repeat with a few categories, like so:
UserID Category
------ --------
1 A
1 B
2 C
3 ...
6
votes
1
answer
8k
views
How to scale Pivoting in BigQuery?
Let's say, I have music video play stats table mydataset.stats for a given day (3B rows, 1M users, 6K artists).
Simplified schema is:
UserGUID String, ArtistGUID String
I need pivot/transpose ...
3
votes
2
answers
7k
views
Partition by week/month//quarter/year to get over the partition limit?
I have 32 years of data that I want to put into a partitioned table. However BigQuery says that I'm going over the limit (4000 partitions).
For a query like:
CREATE TABLE `deleting.day_partition`
...
88
votes
16
answers
355k
views
Setting GOOGLE_APPLICATION_CREDENTIALS for BigQuery Python CLI
I'm trying to connect to Google BigQuery through the BigQuery API, using Python.
I'm following this page here:
https://cloud.google.com/bigquery/bigquery-api-quickstart
My code is as follows:
import ...
10
votes
2
answers
12k
views
"Encountered an error while globbing file pattern" error when using BigQuery API w/ Google Sheets
When trying the access a federated source (Google sheets) from BigQuery API, the following error is thrown:
[..]
"errorResult" : {
"location" : "/gdrive/id/<removed_file_id>",
"...
30
votes
2
answers
100k
views
BigQuery COUNT(DISTINCT value) vs COUNT(value)
I found a glitch/bug in bigquery.
We got a table based on Bank Statistic data under the
starschema.net:clouddb:bank.Banks_token
If i run the following query:
SELECT count(*) as totalrow,
count(...
27
votes
6
answers
44k
views
How to extract all the keys in a JSON object with BigQuery
BigQuery has facilities to parse JSON in real-time interactive queries: Just store the JSON encoded object as a string, and query in real time, with functions like JSON_EXTRACT_SCALAR.
However, I can'...
19
votes
3
answers
20k
views
Create a table from query results in Google BigQuery
We're using Google BigQuery via the Python API. How would I create a table (new one or overwrite old one) from query results? I reviewed the query documentation, but I didn't find it useful.
We want ...
17
votes
5
answers
52k
views
How to unpivot in BigQuery?
Not sure what functions to call, but transpose is the closest thing I can think of.
I have a table in BigQuery that is configured like this:
but I want to query a table that is configured like this:
...
16
votes
1
answer
17k
views
Trigger cloud function when new data in BigQuery
I would like to trigger a Cloud Function when new data has been imported into a BigQuery table. Ideally, I would like to extract all the rows (one column is ISIN) that have been inserted.
Would this ...
10
votes
6
answers
7k
views
Creating/Writing to Parititoned BigQuery table via Google Cloud Dataflow
I wanted to take advantage of the new BigQuery functionality of time partitioned tables, but am unsure this is currently possible in the 1.6 version of the Dataflow SDK.
Looking at the BigQuery JSON ...
6
votes
1
answer
6k
views
The new PIVOT function in BigQuery
Today BigQuery released a new cool function called PIVOT.
Se below how it works:
with Produce AS (
SELECT 'Kale' as product, 51 as sales, 'Q1' as quarter UNION ALL
SELECT 'Kale', 23, 'Q2' UNION ...
3
votes
2
answers
3k
views
Pivot Repeated fields in BigQuery
My Schema looks something like this:
userid:string
timestamp:integer
params:nested/repeated field with 2 fields
- name:string (possible values: "a", "b","c")
- value:string
I want my query to ...
94
votes
6
answers
117k
views
Random Sampling in Google BigQuery
I just discovered that the RAND() function, while undocumented, works in BigQuery. I was able to generate a (seemingly) random sample of 10 words from the Shakespeare dataset using:
SELECT word FROM
(...
34
votes
7
answers
159k
views
Row number in BigQuery?
Is there any way to get row number for each record in BigQuery? (From the specs, I haven't seen anything about it) There is a NTH() function, but that applies to repeated fields.
There are some ...
20
votes
9
answers
41k
views
How to choose the latest partition in BigQuery table?
I am trying to select data from the latest partition in a date-partitioned BigQuery table, but the query still reads data from the whole table.
I've tried (as far as I know, BigQuery does not support ...
17
votes
4
answers
32k
views
BigQuery SQL for 28-day sliding window aggregate (without writing 28 lines of SQL)
I'm trying to compute a 28 day moving sum in BigQuery using the LAG function.
The top answer to this question
Bigquery SQL for sliding window aggregate
from Felipe Hoffa indicates that that you can ...
17
votes
4
answers
17k
views
How to calculate Session and Session duration in Firebase Analytics raw data?
How to calculate Session Duration in Firebase analytics raw data which is linked to BigQuery?
I have used the following blog to calculate the users by using the flatten command for the events which ...
9
votes
3
answers
24k
views
Schedule query in BigQuery
I have a BigQuery query which unions two tables (daily Google Analytics exports). What I want is to save the query as a view or table but have that final view/table update automatically everyday as ...
3
votes
2
answers
8k
views
How to transpose rows to columns with large amount of the data in BigQuery/SQL?
I have a problem in transposing a large amount of data table in BigQuery (1.5 billion rows) from rows to columns. I could figure out how to do it with small amount of data when hardcoded, but with ...
0
votes
1
answer
1k
views
apache beam.io.BigQuerySource use_standard_sql not working when running as dataflow runner
I have a dataflow job where I will read from bigquery query first (in standard sql). It works perfectly in direct runner mode. However I tried to run this dataflow in dataflow runner mode and ...
80
votes
2
answers
108k
views
Update or Delete tables with streaming buffer in BigQuery?
I'm getting this following error when trying to delete records from a table created through GCP Console and updated with GCP BigQuery Node.js table insert function.
UPDATE or DELETE DML statements ...
52
votes
7
answers
219k
views
Google BigQuery Delete Rows?
Anyone know of any plans to add support for delete parts of data from a table in Google Bigquery? The issue we have right now is we are using it for analytics of data points we collect over time. We ...
21
votes
5
answers
42k
views
How to generate date series to occupy absent dates in google BiqQuery?
I am trying to get daily sum of sales from a google big-query table. I used following code for that.
select Day(InvoiceDate) date, Sum(InvoiceAmount) sales from test_gmail_com.sales
where year(...
21
votes
6
answers
24k
views
Bigquery add columns to table schema
I am trying to add new column to BigQuery existing table. I have tried bq command tool and API approach. I get following error when making call to Tables.update().
I have tried with providing full ...
19
votes
9
answers
27k
views
Is there a way to measure string similarity in Google BigQuery
I'm wondering if anyone knows of a way to measure string similarity in BigQuery.
Seems like would be a neat function to have.
My case is i need to compare the similarity of two urls as want to be ...
11
votes
4
answers
18k
views
Total Sessions in BigQuery vs Google Analytics Reports
I'm just learning BigQuery so this might be a dumb question, but we want to get some statistics there and one of those is the total sessions in a given day.
To do so, I've queried in BQ:
select sum(...
11
votes
3
answers
6k
views
How to improve performance of GeoIP query in BigQuery?
I have loaded my application logs in BigQuery and I need to calculate country based on IP address from those logs.
I have written a join query between my table and a GeoIP mapping table that I ...
9
votes
2
answers
8k
views
Dataflow/apache beam - how to access current filename when passing in pattern?
I have seen this question answered before on stack overflow (https://stackoverflow.com/questions/29983621/how-to-get-filename-when-using-file-pattern-match-in-google-cloud-dataflow), but not since ...
8
votes
10
answers
65k
views
Google Big Query Error: CSV table encountered too many errors, giving up. Row: 1 errors: 1
I am trying to run a query on a 12 GB csv file loaded in Google big query, I cant run any query on the dataset. I am not sure if the dataset is loaded correctly. It shows as a table in the pane, but ...
6
votes
4
answers
19k
views
Bigquery + PHP examples
Can somebody provide working example of using the Bigquery API with PHP. I see there are examples for python and java but could not find anything for PHP.
Here is the bigquery browser https://...
1
vote
2
answers
4k
views
Rolling 90 days active users in BigQuery, improving preformance (DAU/MAU/WAU)
I'm trying to get the number of unique events on a specific date, rolling 90/30/7 days back. I've got this working on a limited number of rows with the query bellow but for large data sets I get ...
59
votes
5
answers
132k
views
How to Auth to Google Cloud using Service Account in Python?
I'm trying to make a project that will upload Google Storage JSON file to BigQuery (just automate something that is done manually now), and I'd like to use a 'service account' for this as my script is ...
51
votes
4
answers
243k
views
STRING to DATE in BIGQUERY
I am struggling to try to do this with Google BigQuery:
I do have a column with dates in the following STRING format:
6/9/2017 (M/D/YYYY)
I am wondering how can I deal with this, trying to use the ...
38
votes
3
answers
22k
views
BigQuery Date-Partitioned Views
BigQuery allows you to create date-partitioned tables:
https://cloud.google.com/bigquery/docs/creating-partitioned-tables
I'd like to be able to create views on top of date-partitioned tables and ...
37
votes
3
answers
43k
views
What is Google's Dremel? How is it different from Mapreduce?
Google's Dremel is described here. What's the difference between Dremel and Mapreduce?
33
votes
5
answers
216k
views
BigQuery: SPLIT() returns only one value
I have a page URL column components of which are delimited by /. I tried to run the SPLIT() function in BigQuery but it only gives the first value. I want all values in specific columns.
I don't ...