google-bigquery

Default values for columns in Big Query Tables

天涯浪子 提交于 2021-02-18 21:09:21
问题 Is there a way to set default values for columns in tables in big query? I would like to set 'false' as a default value for a column of boolean data type. 回答1: A nullable column can (trivially) have a NULL default value, but there is no other notion of default in BigQuery (you either insert a particular value or omit the value and it will have the NULL value). That said, if you want to wrap your raw table in a View, you can map a NULL column value to any default that you like. 回答2: There is

LEFT OUTER JOIN Error creating a subquery on bigquery

ぃ、小莉子 提交于 2021-02-18 19:29:32
问题 I'm trying to eval MAL, WAL and DAU from a event table on my bq... I create a query find DAU and with him find WAU and MAU, but it does not work, i received this error: LEFT OUTER JOIN cannot be used without a condition that is an equality of fields from both sides of the join. It's my query WITH dau AS ( SELECT date, COUNT(DISTINCT(events.device_id)) as DAU_explorer FROM `workspace.event_table` as events GROUP BY 1 ) SELECT date, dau, (SELECT COUNT(DISTINCT(device_id)) FROM `workspace.event

Apps Script, convert a Sheet range to Blob

余生颓废 提交于 2021-02-18 07:29:32
问题 Background: I'm trying to upload an individual row of data from a Google Sheet and append it to a BigQuery table. Method: I've been using https://developers.google.com/apps-script/advanced/bigquery to do this, but instead of a file of data as the example is, I am using my own sheet with data from a specific row: var file = SpreadsheetApp.getActiveSpreadsheet(); var currentSheet = file.getSheetByName(name); var lastRow = currentSheet.getLastRow() var lastC = currentSheet.getLastColumn() var

Apps Script, convert a Sheet range to Blob

有些话、适合烂在心里 提交于 2021-02-18 07:29:17
问题 Background: I'm trying to upload an individual row of data from a Google Sheet and append it to a BigQuery table. Method: I've been using https://developers.google.com/apps-script/advanced/bigquery to do this, but instead of a file of data as the example is, I am using my own sheet with data from a specific row: var file = SpreadsheetApp.getActiveSpreadsheet(); var currentSheet = file.getSheetByName(name); var lastRow = currentSheet.getLastRow() var lastC = currentSheet.getLastColumn() var

Apps Script, convert a Sheet range to Blob

自古美人都是妖i 提交于 2021-02-18 07:29:02
问题 Background: I'm trying to upload an individual row of data from a Google Sheet and append it to a BigQuery table. Method: I've been using https://developers.google.com/apps-script/advanced/bigquery to do this, but instead of a file of data as the example is, I am using my own sheet with data from a specific row: var file = SpreadsheetApp.getActiveSpreadsheet(); var currentSheet = file.getSheetByName(name); var lastRow = currentSheet.getLastRow() var lastC = currentSheet.getLastColumn() var

Best way to create randomly assigned partitions in Google BigQuery

心不动则不痛 提交于 2021-02-17 06:27:08
问题 I have a BigQuery table that is not randomly sorted. The IDs are also not random. I would like to partition the data into chunks based on a random number, so that I can use those chunks for various parts of the project. The solution I have in mind is to add two columns to my table: a randomly generated number, and a partition number. I am following this code snippet on AI Platform Notebooks. The only substantive difference is I've changed the query_job line to traintestsplit=""" DECLARE randn

BigQuery Stored Procedure - Use variable in UPDATE statement for table name

南笙酒味 提交于 2021-02-17 06:25:18
问题 I am trying to use a while loop in a stored procedure to update a list of tables. When trying to execute the below code, I am getting the error: Table name "table_name" missing dataset while no default dataset is set in the request . It seems the stored procedure is not correctly reading the variable table_name when it is after UPDATE . Is this intentionally not supported? DECLARE table_names ARRAY<STRING>; DECLARE table_name STRING; DECLARE INDEX INT64 DEFAULT 0; SET table_names = [ "`dev

BigQuery automatically converts timestamp timezone to UTC

给你一囗甜甜゛ 提交于 2021-02-17 03:21:26
问题 I have a table as such: and a file as such: https://storage.googleapis.com/test_share_file/testTimestamp.csv which looks like: and I load the file to big query using python as such: from google.cloud import bigquery as bq gs_path = 'gs://test_share_file/testTimestamp.csv' bq_client = bq.Client.from_service_account_json(gcp_creds_fp) ds = bq_client.dataset('test1') tbl = ds.table('testTimestamp') job_config = bq.LoadJobConfig() job_config.write_disposition = bq.job.WriteDisposition.WRITE

Updating nested array in BigQuery based on value in another column

被刻印的时光 ゝ 提交于 2021-02-17 02:16:35
问题 I have a problem with BigQuery syntax that I'm a bit stuck on. I have an entry in a table that has multiple key value pairs as an array and I would like to update only a single specific string in the values when the key is a certain value. Here is the entry [ { "event_params": [ { "key": "programType", "value": { "string_value": "custom", "int_value": null, "float_value": null, "double_value": null } }, { "key": "firebase_event_origin", "value": { "string_value": "app", "int_value": null,

Turning JSON blob into BQ friendly format with JQ

久未见 提交于 2021-02-16 21:25:09
问题 To be upfront, I have next to no experience with JSON, JQ, or much of anything on the Java side. I've been spending a lot of time trying to use the jq command line function to properly format a test blob of data in a way that I can easily feed into Google BigQuery. { "total_items": 848, "page_count": 34, "items": [ { "landing_id": "708d9e3eb106820f98162d879198774b", "token": "708d9e3eb106820f98162d879198774b", "response_id": "708d9e3eb106820f98162d879198774b", "landed_at": "2019-02-12T01:58