如何处理来自 cube.js 的错误“未知列”?

How can I handle error `unknown column` from cube.js?

我正在学习 https://real-time-dashboard.cube.dev/cube-js-api-with-mongo-db 中的教程,并从那里获取如下所示的数据集。

我的模式设置如下。

cube(`Events`, {
  sql: `SELECT 
    *
  FROM stats.events`,

  refreshKey: {
    sql: `SELECT UNIX_TIMESTAMP()`,
  },

  measures: {
    count: {
      type: `count`,
    },

    online: {
      type: `countDistinct`,
      sql: `${anonymousId}`,
      filters: [{ sql: `${timestamp} > date_sub(now(), interval 3 minute)` }],
    },

    pageView: {
      type: `count`,
      filters: [{ sql: `${eventType} = 'pageView'` }],
    },

    buttonClick: {
      type: `count`,
      filters: [{ sql: `${eventType} = 'buttonClicked'` }],
    },

    urlIsNotEmpty: {
      type: `count`,
      filters: [{ sql: `${url} = https://cubejs-real-time-demo.herokuapp.com/#/` }],
    },

    urlIsEmpty: {
      type: `count`,
      filters: [{ sql: `${url} = ''` }],
    },
  },

  dimensions: {
    secondsAgo: {
      sql: `TIMESTAMPDIFF(SECOND, timestamp, NOW())`,
      type: `number`,
    },

    anonymousId: {
      sql: `${CUBE}.\`anonymousId\``,
      type: `string`,
    },

    eventType: {
      sql: `${CUBE}.\`eventType\``,
      type: `string`,
    },

    url: {
      sql: `\`url\``,
      type: `string`,
    },

    timestamp: {
      sql: `${CUBE}.\`timestamp\``,
      type: `time`,
    },

    referrer: {
      sql: `\`events.referrer\``,
      type: `string`,
    },

    id: {
      sql: `${CUBE}._id`,
      type: `string`,
    },
  },
});

id、enveyType、anontymouseId、secondsAgo 工作正常。但是,当我尝试访问 urlreferrer 时,出现了这样的错误 Unknown column 'events.url' in 'field list'Error: Error: Unknown column 'events.referrer' in 'field list'。有人帮忙吗?

您能否尝试将 referrer 定义更改为:

referrer: {
  sql: `${CUBE}.referrer`,
  type: `string`,
},

同样适用于 url 维度。