google-bigquery

Why doesn't LAST_VALUE return the last value?

和自甴很熟 提交于 2020-06-09 08:54:00
问题 I want to find the last value of y over an ordered partition using a query like this: SELECT x, LAST_VALUE(y) OVER (PARTITION BY x ORDER BY y ASC) FROM table But LAST_VALUE returns lots of values that aren't the last value (in this case, the largest value) of y for a given partition. Why? (In this case, MAX can be used instead of LAST_VALUE to find the largest value, but why doesn't LAST_VALUE return the max value too?) 回答1: TLDR: The query you want is: SELECT x, LAST_VALUE(y) OVER (PARTITION

Reshape from wide to long in big query (standard SQL)

假装没事ソ 提交于 2020-06-07 21:39:31
问题 Unfortunately reshaping in BQ it's not as easy as in R and I can't export my data for this project. Here is input date country A B C D 20170928 CH 3000.3 121 13 3200 20170929 CH 2800.31 137 23 1614.31 Expected output date country Metric Value 20170928 CH A 3000.3 20170928 CH B 121 20170928 CH C 13 20170928 CH D 3200 20170929 CH A 2800.31 20170929 CH B 137 20170929 CH C 23 20170929 CH D 1614.31 Also my table has many more columns and rows (but I assume a lot of manual will be required) 回答1:

Is there a way in Big query to execute dynamic queries something like 'EXEC' in sql server?

为君一笑 提交于 2020-06-07 07:08:45
问题 I have a table with over 200 column names which are created with a temporary name like - custColum1 -custColum200. I have a mapping table which contains a list of custColum1-custColumn200 to which name it has to be mapped with. For example Table1(custColum1,custColum2) Mappingtable(tempColumnName,RealColumnName) data in mapping table be like (custColum1,Role_number) (custColum2,Person_name) I need to change table 1 to Table1(Role_number,Person_name). Note: I cannot create table1 with this

Is there a way in Big query to execute dynamic queries something like 'EXEC' in sql server?

独自空忆成欢 提交于 2020-06-07 07:08:45
问题 I have a table with over 200 column names which are created with a temporary name like - custColum1 -custColum200. I have a mapping table which contains a list of custColum1-custColumn200 to which name it has to be mapped with. For example Table1(custColum1,custColum2) Mappingtable(tempColumnName,RealColumnName) data in mapping table be like (custColum1,Role_number) (custColum2,Person_name) I need to change table 1 to Table1(Role_number,Person_name). Note: I cannot create table1 with this

BigQuery construct hierarchy array from key master-slave

爱⌒轻易说出口 提交于 2020-06-01 06:46:29
问题 I have a master-slave table structure. Col1 identify a user, Col2 identify his master I'm creating a query that builds an array which represents the entire hierarchy (my master, the master of my master, ...) and also in the opposite direction (my slaves, the slaves of my slaves, ...) WITH sample_data AS ( SELECT "user1" as name, "user2" as handler UNION ALL SELECT "user2" as name, "user3" as handler UNION ALL SELECT "user3" as name, "user4" as handler UNION ALL SELECT "user5" as name, "user1"

Any JDBC Driver for Google BigQuery Standard SQL

只谈情不闲聊 提交于 2020-05-29 11:07:19
问题 I need a JDBC driver to connect my application to Google BigQuery. I tried CData JDBC driver, but it did not support all types of Standard SQL queries. Are there any other complete options? 回答1: The official JDBC driver for BigQuery should support all types of standard SQL queries. 回答2: Are there any other complete options? You can use Query Prefix #standardSQL to force use of Standard SQL See more details in Setting a query prefix 来源: https://stackoverflow.com/questions/40538737/any-jdbc

Scheduled queries and clustering

喜欢而已 提交于 2020-05-28 06:19:05
问题 It does not seem to be possible to schedule Queries in BigQuery that write to time partitioned and clustered target tables (using WRITE_TRUNCATE and a partition decorator): we are getting the error message: Invalid value: Incompatible table partitioning specification. Expects partitioning specification interval(type:day) clustering(siteId,channelId), but input partitioning specification is interval(type:day) I don't understand why this is happening, isn't the clustering specification just a

Copy table from one dataset to another in google big query

痞子三分冷 提交于 2020-05-27 04:37:17
问题 I intend to copy a set of tables from one dataset to another within the same project. I execute the code in Ipython notebook. I get the list of table names to be copied in the variable “value” using the below code: list = bq.DataSet('test:TestDataset') for x in list.tables(): if(re.match('table1(.*)',x.name.table_id)): value = 'test:TestDataset.'+ x.name.table_id Then i tried using the “bq cp” command to copy table from one dataset to another. But I cannot execute the bq command in the

Copy table from one dataset to another in google big query

落花浮王杯 提交于 2020-05-27 04:37:05
问题 I intend to copy a set of tables from one dataset to another within the same project. I execute the code in Ipython notebook. I get the list of table names to be copied in the variable “value” using the below code: list = bq.DataSet('test:TestDataset') for x in list.tables(): if(re.match('table1(.*)',x.name.table_id)): value = 'test:TestDataset.'+ x.name.table_id Then i tried using the “bq cp” command to copy table from one dataset to another. But I cannot execute the bq command in the

Error in Google BigQuery <EOF>

不问归期 提交于 2020-05-26 10:38:33
问题 I am new to Google BigQuery. I need help with the query error: "Encountered " "WITH" "with "" at line 1, column 1. Was expecting: EOF" with t1 as ( select date(USEC_TO_TIMESTAMP(event_dim.timestamp_micros)) date, event_dim.name from [myfoody-1313:it_rawfish_myfoody_ANDROID.app_events_20160727] where event_dim.name='pv_detail' and event_dim.params.key='item_id' and event_dim.params.value.string_value='31' ) select date(d) as day, count(event_dim.name) from generate_series(current_date -