简体   繁体   English

Cube.js 时间范围最佳实践

[英]Cube.js time range best practice

I have table with item price for date ranges.我有日期范围内的商品价格表。 what is the best way to model this in cube.js to allow time dimension queries like price over time, or average price for item?在cube.js 中对此进行建模以允许时间维度查询(如随时间推移的价格或商品的平均价格)的最佳方法是什么?

Thanks!谢谢!

the table looks like:该表看起来像:

CREATE pricing test_timestamp (
    id INT AUTO_INCREMENT PRIMARY KEY,
    itemId VARCHAR(255) NOT NULL,
    price INT,
    from TIMESTAMP,
    to TIMESTAMP
);

Considering periods as non overlapping:将期间视为非重叠:

cube(`Pricing`, {
  sql: `select itemId, price, from as timestamp from pricing_test_timestamp
  UNION ALL
  select itemId, -1 * price as price, to as timestamp from pricing_test_timestamp
  `,

  measures: {
    price: {
      sql: `price`,
      type: `sum`,
      rollingWindow: {
        trailing: `unbounded`
      }
    }
  },

  dimensions: {
    timestamp: {
      sql: `timestamp`,
      type: `number`
    }
  }
})

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM