zoukankan      html  css  js  c++  java
  • cube.js 查询格式

    cube.js 提供了自己特有的数据查询模式,还是比较清晰的,包含了维度,度量,时间粒度,以及分段(segments)

    查询格式

    格式为 CUBEE_NAME.MEMBER_NAME 比如维度email,查询cube UsersUsers.email
    对于时间的查询处理CUBE_NAME.TIME_DIMENSION_NAME.GRANULARITY ,支持的时间粒度为
    second, minute, hour, day, week, month
    同时cube.js 接收数组模式的查询,默认是以数据聚合的模式处理的

    查询属性

    • 支持的属性
     
    - measures: An array of measures.
    - dimensions: An array of dimensions.
    - filters: An array of objects, describing filters. Learn about filters format.
    - timeDimensions: A convenient way to specify a time dimension with a filter. It is an array of objects in timeDimension format.
    - segments: An array of segments. A segment is a named filter, created in the Data Schema.
    - limit: A row limit for your query. The default value is 10000. The maximum allowed limit is 50000.
    - offset: The number of initial rows to be skipped for your query. The default value is 0.
    - order: An object, where the keys are measures or dimensions to order by and their corresponding values are either asc or desc. The order of the fields to order on is based on the order of the keys in the object.
    - timezone: All time based calculations performed within Cube.js are timezone-aware. Using this property you can set your desired timezone in TZ Database Name format, e.g.: America/Los_Angeles. The default value is UTC.
    - renewQuery: If renewQuery is set to true, Cube.js will renew all refreshKey for queries and query results in the foreground. However if the refreshKey or refreshKeyRenewalThreshold don't indicate that there's a need for an update this setting has no effect. The default value is false.
    NOTE: Cube.js provides only eventual consistency guarantee. Using too small refreshKeyRenewalThreshold values together with renewQuery in order to achieve immediate consistency can lead to endless refresh loops and overall system instability.
    - ungrouped: If ungrouped is set to true no GROUP BY statement will be added to the query. Instead, the raw results after filtering and joining will be returned without grouping. By default ungrouped queries require a primary key as a dimension of every cube involved in the query for security purposes. To disable this behavior please see the allowUngroupedWithoutPrimaryKey server option. In case of ungrouped query measures will be rendered as underlying sql of measures without aggregation and time dimensions will be truncated as usual however not grouped by. 

    参考格式

    {
      measures: ['Stories.count'],
      dimensions: ['Stories.category'],
      filters: [{
        member: 'Stories.isDraft',
        operator: 'equals',
        values: ['No']
      }],
      timeDimensions: [{
        dimension: 'Stories.time',
        dateRange: ['2015-01-01', '2015-12-31'],
        granularity: 'month'
      }],
      limit: 100,
      offset: 50,
      order: {
        'Stories.time': 'asc',
        'Stories.count': 'desc'
      },
      timezone: 'America/Los_Angeles'
    }
     
     
    • 默认排序
      默认参考以下规则
     
    第一个包含时间粒度维度生序
    第一个度量降序
    第一个维度生序
    • 可选的排序模式
      使用基于数组元组
     
    {
      ...,
      order: [
          ['Stories.time', 'asc'],
          ['Stories.count', 'asc']
        ]
      },
      ...
    }

    filter 格式

    filter 是一个json 对象,包含了以下参数

    - member 维度以及度量
    - operator, 操作
    - values 数据值

    filter 支持的操作

    cube.js 对于filter 操作支持的类型还是比较多的
    具体的可以参考官方文档

    布尔操作

    cube.js 支持了or 以及and 操作
    参考

     
    {
      or: [
        {
          member: 'visitors.source',
          operator: 'equals',
          values: ['some']
        },
        { 
          and: [
            {
              member: 'visitors.source',
              operator: 'equals',
              values: ['some']
            },
            {
              member: 'visitor_checkins.cardsCount',
              operator: 'equals',
              values: ['0']
            },
          ] 
        },
      ]
    }

    时间维度格式

    为了方便对于时间的查询cube.js 提供了时间维度的查询格式

    • 参考格式
    {
      measures: ['Stories.count'],
      timeDimensions: [{
        dimension: 'Stories.time',
        dateRange: ['2015-01-01', '2015-12-31'],
        granularity: 'month'
      }]
    }

    同时比较方便的是,也提供了人性化的查询时间,比如last 360 days 还是比较强大的

    说明

    以上只是一个简单的说明,具体的可以参考官方文档

    参考资料

    https://cube.dev/docs/query-format

  • 相关阅读:
    ES6 export
    vue-cli3实现分环境打包步骤(给不同的环境配置相对应的打包命令)
    vue.config.js
    npm install 错误 安装 chromedriver 失败的解决办法
    解决JS(Vue)input[type='file'] change事件无法上传相同文件的问题
    CSS设置浏览器滚动条样式
    ELK 性能(3) — 在 Docker 上运行高性能容错的 Elasticsearch 集群
    ELK 性能(2) — 如何在大业务量下保持 Elasticsearch 集群的稳定
    ELK 性能(1) — Logstash 性能及其替代方案
    ElasticSearch 2 (37)
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14224294.html
Copyright © 2011-2022 走看看