bigquery-standard-sql

BigQuery - equivalent of GROUP EACH in standard SQL

折月煮酒 提交于 2019-12-13 03:39:26
问题 Is there an equivalent of GROUP EACH / JOIN EACH in standard SQL ? I'm exceeding my resources. 回答1: Nope. :o( There is no such equivalent in Standard SQL. ... EACH was a hint for BQ Engine (Legacy SQL) to more optimally process respective command - which is already covered in Standard SQL w/o any hint'ing Your option is to tune/optimize your query 来源: https://stackoverflow.com/questions/50769877/bigquery-equivalent-of-group-each-in-standard-sql

Google Bigquery multiple updates based on WHERE - need a solution

空扰寡人 提交于 2019-12-11 16:04:40
问题 is there a way to do multiple updates based on other field value WHERE, not CASE idea is below thanks #standardSQL UPDATE dataset.people SET CBSA_CODE = '54620' where substr(zip,1,5) = '99047', SET CBSA_CODE = '31793' where substr(zip,1,5) = '45700' 回答1: A CASE expression is in fact the typical way you would handle this logic: UPDATE dataset.people SET CBSA_CODE = CASE SUBSTR(zip, 1, 5) WHEN '99047' THEN '54620' WHEN '45700' THEN '31793' END WHERE SUBSTR(zip, 1, 5) IN ('99047', '45700'); The

Decode maximum number in rows for sql

核能气质少年 提交于 2019-12-11 11:48:02
问题 I am using the #standardsql in bigquery and trying to code the maksimum ranking of each customer_id as 1 , and the rest of it are 0 This is the query result so far The query for ranking is this ROW_NUMBER() OVER(PARTITION BY customer_id ORDER BY booking_date Asc) as ranking What i need is to create another column like this where it decode the maximum ranking of each customerid as 1, and the number below it as 0 just like the below table Thanks 回答1: Based on your sample data, your ranking is

bigquery standard sql error, invalid timestamp

一笑奈何 提交于 2019-12-11 08:53:35
问题 I'm playing with some tables in bigquery and I receive this error: Cannot return an invalid timestamp value of -62169990264000000 microseconds relative to the Unix epoch. The range of valid timestamp values is [0001-01-1 00:00:00, 9999-12-31 23:59:59.999999] Doing the query in legacysql and sorting ascendent it is displays as 0001-11-29 22:15:36 UTC How does it get transformed in microseconds? This is the query: #standardSQL SELECT birthdate FROM X WHERE birthdate IS NOT NULL ORDER BY

Cosine similarity between pair of arrays in Bigquery

↘锁芯ラ 提交于 2019-12-11 08:14:46
问题 I have created a table that has a pair of IDs and coordinate fro each of them so that I can calculate pairwise cosine similarity between them. The table looks like this The number of dimension for the coords are currently 128, but it can vary. But the number dimensions for a pair of ID are always same in the same table. coord1 and coord2 are repeated field (array) with floating point values. Is there a way to calculate cosine similarity between them? My expected output would have three

Calculating pairwise cosine similarity between quite a large number of vectors in Bigquery

安稳与你 提交于 2019-12-11 05:58:26
问题 I have a table id_vectors that contains id and their corresponding coordinates . Each of the coordinates is a repeated fields with 512 elements inside it. I am looking for pairwise cosine similarity between all those vectors, e.g. If I have three ids 1,2 and 3 then I am looking for a table where I have cosine similarity between them (based on the calculation using 512 coordinates) like below: id1 id2 similarity 1 2 0.5 1 3 0.1 2 3 0.99 Now in my table I have 424,970 unique ID and their

Sessions-per-User Distribution-table in Firebase

这一生的挚爱 提交于 2019-12-11 05:38:06
问题 This is a second post (a follow-up from my first post) on looking at distributions within Firebase Analytics Data. This time around, I want to create a user distribution table in BigQuery based on Firebase Session Data. The output should look like this: I managed to create the following script to count on app_instance_id's: #standardSQL SELECT COUNT(DISTINCT(CASE WHEN sess_id = 0 THEN app_instance_id END)) AS sess_count_0, COUNT(DISTINCT(CASE WHEN sess_id = 1 THEN app_instance_id END)) AS

How can I pass a row from my table to a UDF without specifying the complete type?

泪湿孤枕 提交于 2019-12-08 04:28:10
问题 Let's say that I want to do some processing on a table (such as the sample Github commits) that has a nested structure using a JavaScript UDF. I may want to change the fields that I look at in the UDF as I iterate on its implementation, so I decide just to pass entire rows from the table to it. My UDF ends up looking something like this: #standardSQL CREATE TEMP FUNCTION GetCommitStats( input STRUCT<commit STRING, tree STRING, parent ARRAY<STRING>, author STRUCT<name STRING, email STRING, ...

BigQuery: Union two different tables which are based on federated Google Spreadsheet

家住魔仙堡 提交于 2019-12-06 13:35:54
I have two different Google Spreadsheet: One with 4 columns +------+------+------+------+ | Col1 | Col2 | Col5 | Col6 | +------+------+------+------+ | ID1 | A | B | C | | ID2 | D | E | F | +------+------+------+------+ One with the 4 columns of the previous file, and 2 more columns +------+------+------+------+------+------+ | Col1 | Col2 | Col3 | Col4 | Col5 | Col6 | +------+------+------+------+------+------+ | ID3 | G | H | J | K | L | | ID4 | M | N | O | P | Q | +------+------+------+------+------+------+ I configured them as Federated source in Google BigQuery, now I need to create a

Query hits and custom dimensions in the BigQuery?

假如想象 提交于 2019-12-06 12:11:56
问题 I am working with the GoogleAnalytics data in the BigQuery. I want to output 2 columns: specific event actions (hits) and custom dimension (session based). All that, using Standard SQL. I cannot figure out how to do it correctly. Documentation does not help either. Please help me. This is what I am trying: SELECT (SELECT MAX(IF(index=80, value, NULL)) FROM UNNEST(customDimensions)) AS is_app, (SELECT hits.eventInfo.eventAction) AS ea FROM `table-big-query.105229861.ga_sessions_201711*`,