Cube.js 时间间隔最佳实践

Cube.js time interval best practice

我有 table 工作时间间隔。在 cube.js 中对此进行建模以允许时间维度查询的最佳方式是什么,例如总工人工作时间、日期之间、一天中的总工人时间等等。

谢谢!

table 看起来像:

CREATE working_times test_timestamp (
    id INT AUTO_INCREMENT PRIMARY KEY,
    workerId VARCHAR(255) NOT NULL,
    from TIMESTAMP,
    to TIMESTAMP
);

和立方体:

cube(`WorkingTimes`, {
    sql: `SELECT * FROM db.working_times`,    

    measures: {
      ???
    },

    dimensions: {
      from: {
        sql: `from`,
        type: `time`
      },
      to: {
        sql: `to`,
        type: `time`
      },

    },
  });

可以定义为时间戳差异。假装是 MySQL:

cube(`WorkingTimes`, {
  sql: `SELECT * FROM db.working_times`,    

  measures: {
    workingMinutes: {
      sql: `TIMESTAMPDIFF(MINUTE, ${to}, ${from})`,
      type: `sum`
    }
  },

  dimensions: {
    from: {
      sql: `from`,
      type: `time`
    },
    to: {
      sql: `to`,
      type: `time`
    },

  },
});