cube.js 学习(七)cube.js type 以及format 说明

cube.js 对于measure以及dimension 提供了丰富的数据类型,基本满足我们常见应用的开发,同时对于不同类型也提供了
格式化的操作

measure类型

number

  • 格式
purchasesRatio: {
  sql: `${purchases} / ${count} * 100.0`,
  type: `number`,
  format: `percent`
}

count

  • 格式
numerOfUsers: {
  type: `count`,
  // optional
  drillMembers: [id, name, email, company]
}

countDistinct

类似sql 的count distinct

  • 格式
uniqueUserCount: {
  sql: `user_id`,
  type: "countDistinct"
}

countDistinctApprox

字面意思是countDistinct 的添加剂,同时和countDistinct 不一样,他是利用rollup-pre-aggregations,后端利用
hll或者类似的算法,加速数据的计算

  • 格式
uniqueUserCount: {
  sql: `user_id`,
  type: "countDistinctApprox"
}

sum

类似sql 的sum,但是与原生sql 不同,他将正确的计算数据,尽管连接可能导致数据重复

  • 格式
revenue: {
  sql: `amount`,
  type: `sum`
}

avg

类似sql 的avg 进行平均数的计算,但是与原生sql 不同,他将正确的计算数据,尽管连接可能导致数据重复

  • 格式
averageTransaction: {
  sql: `${transactionAmount}`,
  type: `avg`
}

min

  • 格式
dateFirstPurchase: {
  sql: `date_purchase`,
  type: `min`
}

max

  • 格式
dateLastPurchase: {
  sql: `date_purchase`,
  type: `max`
}

runningTotal

计算概述sql 中的值

  • 格式
totalSubscriptions: {
  sql: `subscription_amount`,
  type: `runningTotal`
}

measure格式化

百分比

  • 格式
purchaseConversion: {
  sql: `${purchase}/${checkout}*100.0`,
  type: `number`,
  format: `percent`
}

货币

  • 格式
totalAmount: {
  sql: `amount`,
  type: `runningTotal`,
  format: `currency`
}

dimension 类型

time

  • 格式
completedAt: {
  sql: `completed_at`,
  type: `time`
}

string

  • 格式
fullName: {
  sql: `CONCAT(${firstName}, ' ', ${lastName})`,
  type: `string`
}

number

  • 格式
amount: {
  sql: `amount`,
  type: `number`
}

geo

  • 格式
location: {
  type: `geo`,
  latitude: {
    sql: `${TABLE}.latitude`,
  },
  longitude: {
    sql: `${TABLE}.longitude`
  }
}

dimension 格式

imageUrl

  • 格式
image: {
  sql: `CONCAT('https://img.example.com/id/', ${id})`,
  type: `string`,
  format: `imageUrl`
}

id

  • 格式
image: {
  sql: `id`,
  type: `number`,
  format: `id`
}
  • 格式
orderLink: {
  sql: `'http://myswebsite.com/orders/' || id`,
  type: `string`,
  format: `link`
}

crmLink: {
  sql: `'https://na1.salesforce.com/' || id`,
  type: `string`,
  format: {
    label: `View in Salesforce`,
    type: `link`
  }
}

货币

  • 格式
amount: {
  sql: `abount`,
  type: `number`,
  format: `currency`
}

百分比

  • 格式
penRate: {
  sql: `COALESCE(100.0 * ${uniqOpenCount} / NULLIF(${deliveredCount}, 0), 0)`,
  type: `number`,
  format: `percent`
}

参考资料

https://cube.dev/docs/types-and-formats

posted on   荣锋亮  阅读(521)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2018-05-03 drone 学习六 发布部署&&集成私有容器仓库&&构建代码s3 保存
2018-05-03 hoverfly api 模拟框架了解
2016-05-03 Nagios 监控
2014-05-03 wcat 进行iis 压力测试
2014-05-03 log parser 微软iis 日志分析
2014-05-03 NTLM 了解

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示