简体   繁体   English

将 Google Data Studio 社区连接器与 BigQuery 结合使用时的时间戳查询问题

[英]Timestamp query issue when using Google Data Studio community connector with BigQuery

I'm having an issue where Google Data Studio is sending bad timestamp data to my community connector, so that when I try and filter on a date, I get an error.我遇到一个问题,Google Data Studio 将错误的时间戳数据发送到我的社区连接器,因此当我尝试过滤日期时,出现错误。 I have two BigQuery TIMESTAMP type fields (named timestamp and created_at ), both being passed through to my community connector without modification.我有两个 BigQuery TIMESTAMP类型的字段(名为timestampcreated_at ),它们都未经修改地传递到我的社区连接器。 Once I add a date filter to the reports (in order to do time series, or regular filtering), like so:一旦我将日期过滤器添加到报告中(以便进行时间序列或常规过滤),如下所示:

在此处输入图像描述

then my queries from the connector (viewed in my BigQuery project history) begin to fail like this:然后我来自连接器的查询(在我的 BigQuery 项目历史记录中查看)开始像这样失败:

Could not cast literal "20200825" to type TIMESTAMP at [1:677]

The query in BigQuery looks something like this: BigQuery 中的查询看起来像这样:

SELECT t0.created_at, SUM(t0.sum_metric) AS t0_qt_1z4br3iwbc FROM (SELECT field1, field2, field3) from data_name.table_name where user_identifier in (2)) AS t0 WHERE (t0.created_at >= '20200825' AND t0.created_at <= '20200831') GROUP BY t0.created_at ORDER BY t0.created_at ASC;

This really feels like a bug with the community connector regarding BigQuery.这真的感觉像是关于 BigQuery 的社区连接器的错误。 Is there some way around this?有什么办法解决这个问题吗? Am I just doing something wrong I'm not seeing?我只是做错了什么我没有看到吗?

Ok, I solved this.好的,我解决了这个问题。 In your community connector you'll need to add this to your config:在您的社区连接器中,您需要将其添加到您的配置中:

config.setDateRangeRequired(true);

this will send a startDate and endDate parameter with your getData request (it defaults to 28 days).这将在您的 getData 请求中发送一个 startDate 和 endDate 参数(默认为 28 天)。 Access them in getData() like so:像这样在getData()中访问它们:

var startDate = request.dateRange.startDate;
var endDate = request.dateRange.endDate

and then use them in your query as necessary.然后根据需要在您的查询中使用它们。

As a side note, if you're storing a timestamp field in Google Data Studio and making a community connector, you'll need to set up a calculated field so that the reports treat it appropriately (display a human readable date instead of a timestamp).作为旁注,如果您在 Google Data Studio 中存储timestamp字段并制作社区连接器,则需要设置计算字段,以便报告适当地处理它(显示人类可读的日期而不是时间戳). I'm first reading the timestamp field out of the database as a string like: STRING(timestamp, 'UTC') AS timestamp and then using this value to create a dimension.我首先将时间戳字段作为字符串从数据库中读取出来,例如: STRING(timestamp, 'UTC') AS timestamp ,然后使用该值创建一个维度。 This is done in the schema like the following (use parsing appropriate to your field if it's different):这是在如下模式中完成的(如果不同,请使用适合您的领域的解析):

fields.newDimension()
  .setId('date_timestamp')
  .setName('date_timestamp')
  .setDescription('Timestamp as a date.')
  .setFormula("TODATE($timestamp, '%Y-%m-%d %H:%M:%S%z', '%Y%m%d')")
  .setType(types.YEAR_MONTH_DAY)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 中的 Google BigQuery 查询在使用 result() 时有效,但在使用 to_dataframe() 时出现权限问题 - Google BigQuery query in Python works when using result(), but Permission issue when using to_dataframe() 使用 Spark BigQuery 连接器查询 BigQuery 视图时未启用缓存 - Cache not enabled when querying BigQuery view using Spark BigQuery connector 在 Google Data Studio(Looker Studio) 中的现有报告中添加 BigQuery 查询结果 - Adding BigQuery query result in an already existing report in Google Data Studio(Looker Studio) 如何使用用户可以在 getFields 的计算字段中更新的参数(Data Studio 社区连接器) - How to use a parameter which a user can update in a calculated field in getFields (Data Studio Community Connector) Google AppScript 大型多行查询字符串 (BigQuery) 问题 - Google AppScript large multi-line query string (BigQuery) issue 如何将 Data Studio 控件传递给 BigQuery 自定义查询 - How to pass Data Studio Controls to BigQuery custom query 使用 window function 将 Google Data Studio 连接到 BigQuery 的问题 - Issues connecting Google Data Studio to BigQuery with window function UNIX 时间戳 TO Google bigQuery TS Format - UNIX timestamp TO Google bigQuery TS Format Google Cloud DataStream to Bigquery 模板无法将数据同步到大查询 - Google Cloud DataStream to Bigquery template not able to sync data to big query 使用数据工作室中大查询的数据重新创建谷歌分析仪表板 - Recreating google analytics dashboard using data from big query within data studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM