google-bigquery

BigQuery Integer Partitions - can I use the results of another query to get a list of the partitions to access?

梦想的初衷 提交于 2020-04-12 06:38:02
问题 I have a large table using integer partitions (~1TB). I need to regularly make several small subsets of this table. This was costing a lot, but using integer partitions I can decrease the cost by like 95%. It looks something like this. tbl_a : partition_index IN (1, 2, 5, 6, 7, 10, 11, 15, 104, 106, 111) tbl_b : partition_index IN (3, 4, 5, 20, 21, 25, 16, 84, 201, 301, 302, 303) and so on an so forth, with different subtables using different subsets of the index. Its ugly as all hell, but it

BigQuery Integer Partitions - can I use the results of another query to get a list of the partitions to access?

自古美人都是妖i 提交于 2020-04-12 06:37:02
问题 I have a large table using integer partitions (~1TB). I need to regularly make several small subsets of this table. This was costing a lot, but using integer partitions I can decrease the cost by like 95%. It looks something like this. tbl_a : partition_index IN (1, 2, 5, 6, 7, 10, 11, 15, 104, 106, 111) tbl_b : partition_index IN (3, 4, 5, 20, 21, 25, 16, 84, 201, 301, 302, 303) and so on an so forth, with different subtables using different subsets of the index. Its ugly as all hell, but it

Latitude and Longitude - find city & state using bigquery

梦想与她 提交于 2020-04-11 13:17:16
问题 I have latitude and longitude information in my table. I want to find the nearest city and state name using lat and long info using bigquery. 回答1: Hope below quick example will give you good direction to start with SELECT yourLon, yourLat, ROUND(distance) AS distance, city, state FROM ( SELECT yourLon, yourLat, distance, city, state, ROW_NUMBER() OVER (PARTITION BY yourLon, yourLat ORDER BY distance) AS win FROM JS(( // input table SELECT points.yourLon AS yourLon, points.yourLat AS yourLat,

Latitude and Longitude - find city & state using bigquery

烈酒焚心 提交于 2020-04-11 13:16:41
问题 I have latitude and longitude information in my table. I want to find the nearest city and state name using lat and long info using bigquery. 回答1: Hope below quick example will give you good direction to start with SELECT yourLon, yourLat, ROUND(distance) AS distance, city, state FROM ( SELECT yourLon, yourLat, distance, city, state, ROW_NUMBER() OVER (PARTITION BY yourLon, yourLat ORDER BY distance) AS win FROM JS(( // input table SELECT points.yourLon AS yourLon, points.yourLat AS yourLat,

How do you declare `DAY`, `WEEK`, `MONTH`, `QUARTER`, `YEAR` etc. as a variable in BigQuery? [duplicate]

假装没事ソ 提交于 2020-03-26 03:03:28
问题 This question already has an answer here : How to generate with scripting INTERVAL 1 <day|week|month>? (1 answer) Closed last month . I'd like to configure the interval used by my query, but cannot figure out how to declare DAY , WEEK , MONTH , QUARTER , YEAR etc. as a variable. DECLARE interval ???; -- What datatype is `DAY`, `MONTH` etc? SET interval = MONTH; If relevant, my query does something like this: WITH dates AS ( SELECT * FROM UNNEST( GENERATE_DATE_ARRAY( DATE_TRUNC('2019-12-11',

Can I use `TextEncoder` in Bigquery JS UDF?

被刻印的时光 ゝ 提交于 2020-03-25 19:25:10
问题 I am trying to use some Rust wasm code in Bigquery as UDF, and in order to pass on Java String to Rust code the TextEncoder and TextDecoder would be needed to conveniently doing that. As it mentioned here Passing a JavaScript string to a Rust function compiled to WebAssembly But when I try out some of my code on BigQuery, I encountered an error saying TextEncoder is not defined. You can try it out as well with a query like this: https://github.com/liufuyang/rb62-wasm/blob/master/try-3-old.sql

Convert XML data from one table in Google BigQuery to JSON data in another column in the same table

不问归期 提交于 2020-03-25 19:19:29
问题 I have the following table in Google BigQuery (only a few lines are shown here): id loaded_date data 1 2019-10-25 <collection><row><field name="Item Key" type="text" value="Haircolour - Avstemming kunder - OMT" /><field name="Created" type="datetime" value="2019-10-25 17:35:17Z" /><field name="Type" type="text" value="Session Provisioning Failure" /></row></collection> 2 2019-10-25 <collection><row><field name="Item Key" type="text" value="Haircolour - Avstemming kunder - OMT" /><field name=

GCP BigQuery how to set expiration date to table by python api

╄→尐↘猪︶ㄣ 提交于 2020-03-25 18:52:46
问题 I am using BigQuery Python API to create table, and would like to set an expiration date to the table, so the table would be automatically dropped after certain days. Here is my code: client = bq.Client() job_config = bq.QueryJobConfig() dataset_id = dataset table_ref = client.dataset(dataset_id).table(filename) job_config.destination = table_ref job_config.write_disposition = 'WRITE_TRUNCATE' dt = datetime.now() + timedelta(seconds=259200) unixtime = (dt - datetime(1970,1,1)).total_seconds()

BigQuery: No OAuth token with Google Drive scope was found

孤街浪徒 提交于 2020-03-25 16:07:39
问题 I'm trying to replace the contents of a Google Sheet with a BigQuery query. I'm in the Google Sheet and using a script based on these: https://greenido.wordpress.com/2013/12/16/big-query-and-google-spreadsheet-intergration/ Accessing BigQuery with Google Spreadsheet All the script does is pull the info from a BigQuery query and write it to a Google Sheet. But if I just run the script, I end up getting an error: BigQuery: No OAuth token with Google Drive scope was found What do I need to do to

BigQuery add new columns into nested STRUCT in subquery

帅比萌擦擦* 提交于 2020-03-24 01:58:54
问题 I have the following table that contains nested STRUCT s, and in a subquery, I am trying to add additional columns at the struct level . I've created a reproducible example of my efforts thus far: WITH wide_stats AS ( ( SELECT 'joe' name, 'bills' team, struct(struct(7 as fga, 5 as fgm) as o, struct(8 as fga, 3 as fgm) as d) as t1, struct(struct(3 as fga, 4 as fgm) as o, struct(9 as fga, 2 as fgm) as d) as t2 ) UNION ALL ( SELECT 'nick' name, 'jets' team, struct(struct(12 as fga, 7 as fgm) as