[英]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
类型的字段(名为timestamp
和created_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.