【问题标题】:Data Studio Community Connector error: The number of columns in the data does not match the number in the schema数据洞察社区连接器错误:数据中的列数与架构中的数字不匹配
【发布时间】:2019-12-27 20:55:43
【问题描述】:

我正在按照推荐的 codelab 编写连接器并面临问题,这已经在 [another question] 中讨论过,但它并没有解决我的问题。

我收到Data Studio Community Connector error: The number of columns in the data does not match the number in the schema. 消息,即使我认为一切正常。

我仔细检查了请求的字段,只返回了请求的字段。它要求按预期返回 7 个数字字段。

感谢您的帮助。

我的getData() 方法:

function getData(request) {
   try {
     console.log("getData - request", request);

     // Create schema for requested fields
     var requestedFieldIds = request.fields.map(function(field) {
       return field.name;
     });
     var requestedFields = getFields().forIds(requestedFieldIds);

     // Fetch and parse data from API
     var url = [
       'https://api.hubstaff.com',
       '/v2/organizations/',
       request.organizationId,
       '/activities/daily',
       '?date[start]=2019-12-19&date[stop]=2019-12-26'
     ];

     var response = UrlFetchApp.fetch(url.join(''));    
     var parsedResponse = JSON.parse(response);   
     var rows = responseToRows(requestedFields, parsedResponse);

     console.log("getData - rows", rows);

     return {
       schema: requestedFields.build(),
       rows: rows
     };

  } catch (e) { 
    e = (typeof e === 'string') ? new Error(e) : e;
    Logger.log("Catch", e);
    console.log("Catch", e);
    throw e;
  }
}

"getData - request" 日志(来自 StackDriver“真实”补码调用):

{
   organizationId=XXXXXXXX, 
   fields=[
      {dataType=NUMBER, name=user_id, semantics={conceptType=DIMENSION, semanticType=NUMBER}}, 
      {dataType=NUMBER, name=tracked, semantics={isReaggregatable=true, conceptType=METRIC, semanticType=NUMBER}}, 
      {dataType=NUMBER, name=keyboard, semantics={isReaggregatable=true, conceptType=METRIC, semanticType=NUMBER}},
      {dataType=NUMBER, name=mouse, semantics={isReaggregatable=true, conceptType=METRIC, semanticType=NUMBER}},
      {dataType=NUMBER, name=overall, semantics={isReaggregatable=true, conceptType=METRIC, semanticType=NUMBER}}, 
      {dataType=NUMBER, name=idle, semantics={isReaggregatable=true, conceptType=METRIC, semanticType=NUMBER}}, 
      {dataType=NUMBER, name=resumed, semantics={isReaggregatable=true, conceptType=METRIC, semanticType=NUMBER}}
    ], 
    accessToken=XXXXXXXXX
}

"getData - rows" 日志(来自 StackDriver“真实”补码调用):

[
   {values=[164079, 320317.0, 75110.0, 142879.0, 163043.0, 25266.0, 454.0]}, 
   {values=[642198, 301352.0, 73463.0, 135327.0, 154413.0, 24198.0, 0.0]}, 
   {values=[615157, 275512.0, 69592.0, 123441.0, 140382.0, 22181.0, 0.0]}, 
   {values=[741562, 258775.0, 66839.0, 115086.0, 130181.0, 22181.0, 0.0]}, 
   {values=[405833, 229674.0, 58363.0, 100779.0, 114785.0, 22181.0, 0.0]}
]

【问题讨论】:

  • 对于此连接器的所有 getData 请求或仅包含这些字段的特定 getData 调用,您是否遇到问题? (如果用user_iduser_id 制作条形图会怎样?)
  • @MinhazKazi 感谢您的评论。我认为这是我的错。 stackdriver 日志记录不是那么直观的工具,在 Google Script 上调试也不容易。问题是另一点。我回答了我的问题。感谢您的帮助。

标签: google-data-studio


【解决方案1】:

我解决了问题,但与我的预期相差甚远。

我不知道究竟是为什么,但是,阅读日志我看到他们第一次通过request.organizationId 发送配置参数,然后通过request.configParams.organizationId 发送配置参数。为了解决这个问题,我做了:

var organizatioInd = request.organizationId || request.configParams.organizationId;
var accessToken = request.accessToken || request.configParams.accessToken;

这是我唯一更改的代码。

我过去的问题日志是第一个带有正确参数的调用,它记录了正确的结果。第二次调用(应该是真正的 Studio 调用)因为配置错误而失败。

【讨论】:

  • 不太可能通过request 发送一次configParams,然后只通过request.configParams。除了getData 中的第 3 行之外,还有其他地方可以记录 request 对象吗?
  • 我添加了对一个测试方法的调用(用于调试/测试目的),并且该方法使用该参数调用 getData(在根对象上)。然后,当 Data Studio 打开文件以使用代码时,文件本身使用错误的参数调用 getData,甚至在 Data Studio 调用它之前...跨度>
猜你喜欢
  • 2019-01-13
  • 1970-01-01
  • 1970-01-01
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多