如何从查询中删除CubeJS默认的Group By子句

时间:2019-10-07 07:13:16

标签: node.js cube.js

当我们在其中运行任何查询时,

CubeJS 默认会应用 Group By 子句。

例如下面是我对雇员多维数据集的JSON查询:

{
  "dimensions": [
    "Employee.date",
    "Employee.state",
    "Employee.id"
  ],
  "timeDimensions": [],
  "filters": []
}

当我在CubeJS中的JSON查询上运行时,它将在SQL下运行:

SELECT
  `employee`.updatedAt `employee__date`,
  `employee`.state `employee__state`,
  `employee`.EmpId `employee__id`
FROM
  DEMO.Employee AS `employee`
GROUP BY
  1,
  2,
  3
ORDER BY
  1 ASC
LIMIT
  10000

下面供参考的是我拥有的 Employee 多维数据集:

cube(`Employee`, {
  sql: `SELECT * FROM DEMO.Employee `,
  title: `Employee`,

  measures: {
    count: {
      type: `count`
    }
  },
  dimensions: {
    id: {
      sql: `EmpId`,
      type: `string`
    },
    date: {
      sql: `updatedAt`,
      type: `time`
    },
    state: {
      sql: `state`,
      type: `string`
    }
  }
});

如果我期望在SQL下运行,我需要创建什么JSON查询:

SELECT
  `employee`.updatedAt `employee__date`,
  `employee`.state `employee__state`,
  `employee`.EmpId `employee__id`
FROM
  DEMO.Employee AS `employee`
WHERE
  `employee`.updatedAt ` BETWEEN '2019-01-01' AND '2019-05-01'
LIMIT
  10000

OR

是否可以从CubeJS本身生成的SQL查询中删除 Group By 子句。

1 个答案:

答案 0 :(得分:0)

自0.10.62开始,有ungrouped个查询属性,用于:https://cube.dev/docs/query-format#query-properties。在您的情况下,可以使用以下查询:

{
  "dimensions": [
    "Employee.date",
    "Employee.state",
    "Employee.id"
  ],
  "timeDimensions": [],
  "filters": [],
  "ungrouped": true
}