zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    JavaScript内置函数
    JavaScript内置函数
    javascript入门之算术乘法表
    第三章 3 python运算符的优先级
    第三章 2 pyhon中的运算符
    第三章 1 input输入函数
    第二章 5 python中的注释
    第二章 4 数据类型的转换
    第二章 3 数据类型
    第二章 2 python中的标识符和保留字
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/10804569.html
Copyright © 2011-2022 走看看