google-bigquery

converting array of strings to single row values

◇◆丶佛笑我妖孽 提交于 2020-06-13 02:09:03
问题 I have records in Big Query table as name value Aashis ["AB",AC"] Rahul ["AA",AD"] Here name and value column is String Type I want the output as name value Aashis AB Aashis AC Rahul AA Rahul AD 回答1: Below is for BigQuery Standard SQL #standardSQL SELECT name, value FROM `project.dataset.table`, UNNEST(value) value You can test, play with above using dummy data from your question as below #standardSQL WITH `project.dataset.table` AS ( SELECT 'Aashis' name, ["AB","AC"] value UNION ALL SELECT

converting array of strings to single row values

拜拜、爱过 提交于 2020-06-13 02:08:51
问题 I have records in Big Query table as name value Aashis ["AB",AC"] Rahul ["AA",AD"] Here name and value column is String Type I want the output as name value Aashis AB Aashis AC Rahul AA Rahul AD 回答1: Below is for BigQuery Standard SQL #standardSQL SELECT name, value FROM `project.dataset.table`, UNNEST(value) value You can test, play with above using dummy data from your question as below #standardSQL WITH `project.dataset.table` AS ( SELECT 'Aashis' name, ["AB","AC"] value UNION ALL SELECT

Google BigQuery: retrieve last version of each row

心不动则不痛 提交于 2020-06-12 16:08:56
问题 I have a Google BigQuery Table which contains all the versions of resources. Every time a resource is created/updated/deleted a new row is added incrementing the version number (this number will be the timestamp of when the row is added) +-------+------------+--------+-------+-------------+ | ID | ResourceID | Action | Count | Timestamp | +-------+------------+--------+-------+-------------+ | ABC_1 | ABC | CREATE | 10 | {timestamp} | | ABC_2 | ABC | UPDATE | 8 | {timestamp} | | ABC_3 | ABC |

Google BigQuery: retrieve last version of each row

痴心易碎 提交于 2020-06-12 16:05:13
问题 I have a Google BigQuery Table which contains all the versions of resources. Every time a resource is created/updated/deleted a new row is added incrementing the version number (this number will be the timestamp of when the row is added) +-------+------------+--------+-------+-------------+ | ID | ResourceID | Action | Count | Timestamp | +-------+------------+--------+-------+-------------+ | ABC_1 | ABC | CREATE | 10 | {timestamp} | | ABC_2 | ABC | UPDATE | 8 | {timestamp} | | ABC_3 | ABC |

How to get max value of column values in a record ? (BigQuery)

北城以北 提交于 2020-06-12 09:29:13
问题 I wanna get max value of each rows, not max value of a field. For example, when I have a sample_table like this: sample_table |col1|col2|col3| |--------------| | 1 | 0 | 0 | | 0 | 2 | 0 | | 2 | 0 | 0 | | 0 | 0 | 3 | And the query and result I want is something like this: query SELECT SOME_GET_MAX_VAL_FUNC(col1, col2, col3) AS max_val FROM sample_table; result |max_val| |-------| | 1 | | 2 | | 2 | | 3 | I want some solution to replace SOME_GET_MAX_VAL_FUNC . If it is nearly impossible in SQL,

How to get max value of column values in a record ? (BigQuery)

给你一囗甜甜゛ 提交于 2020-06-12 09:28:49
问题 I wanna get max value of each rows, not max value of a field. For example, when I have a sample_table like this: sample_table |col1|col2|col3| |--------------| | 1 | 0 | 0 | | 0 | 2 | 0 | | 2 | 0 | 0 | | 0 | 0 | 3 | And the query and result I want is something like this: query SELECT SOME_GET_MAX_VAL_FUNC(col1, col2, col3) AS max_val FROM sample_table; result |max_val| |-------| | 1 | | 2 | | 2 | | 3 | I want some solution to replace SOME_GET_MAX_VAL_FUNC . If it is nearly impossible in SQL,

Big table vs Big Query usecase for timeseries data

点点圈 提交于 2020-06-10 05:12:23
问题 I am looking to finalize on Big table vs Big Query for my usecase of timeseries data. I had gone through https://cloud.google.com/bigtable/docs/schema-design-time-series This is for storing an Omniture data which contains information like website visitor key(some Long key), his cookie id(some Long key), timestamp series data web hits for his IP, cookie What can be used as the rowkey for Big table? I cannot be using timestamp or CookieId as a prefix, as I learn from the best practices. But

Cannot access field in Big Query with type ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, …>>

半腔热情 提交于 2020-06-09 15:27:07
问题 I'm trying to run a query using Standard SQL Dialect (ie not Legacy SQL) on BigQuery. My query is: SELECT date, hits.referer FROM `refresh.ga_sessions_xxxxxx*` LIMIT 1000 But keep getting the error Error: Cannot access field referer on a value with type ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, ...>> at [2:12] Anyone know the proper syntax? 回答1: if you are looking for all referers - try SELECT date, h.referer FROM `refresh.ga_sessions_xxxxxx*`, UNNEST(hits) as h 来源: https:/

Cannot access field in Big Query with type ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, …>>

筅森魡賤 提交于 2020-06-09 15:26:07
问题 I'm trying to run a query using Standard SQL Dialect (ie not Legacy SQL) on BigQuery. My query is: SELECT date, hits.referer FROM `refresh.ga_sessions_xxxxxx*` LIMIT 1000 But keep getting the error Error: Cannot access field referer on a value with type ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, ...>> at [2:12] Anyone know the proper syntax? 回答1: if you are looking for all referers - try SELECT date, h.referer FROM `refresh.ga_sessions_xxxxxx*`, UNNEST(hits) as h 来源: https:/

Why doesn't LAST_VALUE return the last value?

痞子三分冷 提交于 2020-06-09 08:54:11
问题 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