[英]Does Cube.js support preAggregations when using Context Variables inside the SQL definition of a cube?
According to the Cube.js documentation , one can define cubes using something called Context Variables, that allows the injection of filters (such as a particular user email) when querying that cube.根据Cube.js 文档,可以使用称为上下文变量的东西来定义多维数据集,这允许在查询该多维数据集时注入过滤器(例如特定用户的电子邮件)。 I haven't tried it yet, but I want to know if this feature is compatible with preaggregations, and also if it handles empty filter cases.
我还没有尝试过,但我想知道此功能是否与预聚合兼容,以及它是否处理空过滤器情况。
For example, if I define this cube (same as the example from the docs):例如,如果我定义这个多维数据集(与文档中的示例相同):
cube(`OrderFacts`, {
sql: `SELECT * FROM orders WHERE ${FILTER_PARAMS.OrderFacts.date.filter('date')}`,
measures: {
count: {
type: `count`
}
},
dimensions: {
date: {
sql: `date`,
type: `time`
}
}
});
will I be able to define a preAggregation such as this?我能定义这样的 preAggregation 吗?
preAggregations: {
date: {
type: `rollup`,
measureReferences: [someMeasure],
dimensionReferences: [someDimension],
timeDimensionReference: date,
granularity: `month`
}
}
and can I perform queries without a date
dimension filter?我可以在没有
date
维度过滤器的情况下执行查询吗? (so the sql
would end as SELECT * FROM orders WHERE;
) ? (所以
sql
将以SELECT * FROM orders WHERE;
结尾)?
To sum up: is there a way of injecting filters to a cube's sql
definition dynamically, but not at query time and instead at schema compile time ?总结一下:有没有一种方法可以动态地将过滤器注入多维数据集的
sql
定义,但不是在查询时而是在模式编译时?
I ask this because we are currently extending some cubes with information retrieved from our API, and we were overwriting the segment
field from this cubes, but due to performance issues we would prefer to overwrite the cube's sql
field (to filter unnecessary data from the start).我问这个是因为我们目前正在使用从我们的 API 检索到的信息扩展一些多维数据集,并且我们正在从这个多维数据集中覆盖
segment
字段,但是由于性能问题,我们更愿意覆盖多维数据集的sql
字段(从一开始就过滤不必要的数据) )。
NOTE: We are using asyncModule
to perform the queries to our API.注意:我们使用
asyncModule
来执行对 API 的查询。 We also need to build different cubes (for all our clients) referencing a common table, but with a dynamic SQL that will change depending on the client.我们还需要构建不同的多维数据集(为我们所有的客户)引用一个公用表,但使用将根据客户而改变的动态 SQL。
Our desired output should be (for an Orders table and F1
, ..., Fn
client filters from our API):我们想要的输出应该是(对于来自我们 API 的 Orders 表和
F1
, ..., Fn
客户端过滤器):
N cubes that extend a base Orders
cube: OrdersC1
, OrdersC2
, ..., OrdersCn
.扩展基本
Orders
多维数据集的 N 个多维数据集: OrdersC1
、 OrdersC2
、 ...、 OrdersCn
。
Each OrdersCi
cube with a modified version of the base Orders
sql, containing its Fi
filter.每个
OrdersCi
多维数据集都带有基本Orders
sql 的修改版本,包含其Fi
过滤器。
Each OrdersCi
cube with the same dimensions
, measures
and preAggregations
definitions, inherited from the base Orders
cube.每个
OrdersCi
多维数据集具有相同的dimensions
、 measures
和preAggregations
定义,继承自基本Orders
多维数据集。
We managed to implement all that I said before, but instead of modifying the sql
field, we overwrote the segments
field.我们设法实现了我之前所说的所有内容,但是我们没有修改
sql
字段,而是覆盖了segments
字段。
In general only partitioned rollups pass FILTER_PARAMS
for partitioned time dimensions.一般来说,只有分区汇总才能通过
FILTER_PARAMS
来获取分区时间维度。 All other pre-aggregations doesn't allow passing context variables.所有其他预聚合都不允许传递上下文变量。 There're two approaches you can use to leverage pre-aggregations in multi-tenant environments.
您可以使用两种方法在多租户环境中利用预聚合。
sql
for each customer cube such as OrdersC1
, OrdersC2
, etc. In this case all pre-aggregations defined in base Orders
cube will be inherited.OrdersC1
、 OrdersC2
等)覆盖sql
。在这种情况下,基本Orders
多维数据集中定义的所有预聚合都将被继承。 Each customer cube will have it's own set of pre-aggregations.N
customers and M
pre-aggregations then N * M
pre-aggregation tables should be built which can be costly in some scenarios.N
客户和M
预聚合,那么应该构建N * M
预聚合表,这在某些情况下可能会很昂贵。cube(`Orders`, {
sql: `SELECT * FROM orders`,
preAggregations: {
date: {
type: `rollup`,
measureReferences: [someMeasure],
dimensionReferences: [someDimension],
timeDimensionReference: date,
granularity: `month`
},
// ...
}
});
cube(`OrdersC1`, {
extends: Orders,
sql: `SELECT * FROM orders WHERE customer_id = 'C1'`,
});
cube(`Orders`, {
sql: `SELECT * FROM orders`,
// ...
dimensions: {
// ...
customerId: {
sql: `customer_id`,
type: `string`
}
},
preAggregations: {
date: {
type: `rollup`,
measureReferences: [someMeasure],
dimensionReferences: [customerId, someDimension],
timeDimensionReference: date,
granularity: `month`
},
// ...
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.