在 cube.js 中,我将如何查询数组的内容?
In cube.js, how would I query over contents of an array?
假设我的数据中有一组信息(例如:tags: ['red', 'blue', 'green']
)。我如何将其添加到我的多维数据集以执行类似过滤标签数组 contains
特定值的操作?
我专门使用 Athena 驱动程序并预先聚合到 Aurora Postgres 中。
这是我到目前为止的进展,但还远远不够。
cube(`Events`, {
sql: `select * from events`,
joins: {
Tags: {
relationship: `hasMany`,
sql: `${tags}.id = ${tags}`
}
},
});
cube(`Tags`, {
sql: `UNNEST(tags) t (id, idx)`,
dimensions: {
tag: {
sql: `id`,
type: `string`
}
}
});
这是一个正确的方向。应添加标签多维数据集中事件 table 的主键和 select:
cube(`Events`, {
sql: `select * from events`,
joins: {
Tags: {
relationship: `hasMany`,
sql: `${Events}.id = ${Tags}.id`
}
},
dimensions: {
id: {
sql: `id`,
type: `string`,
primaryKey: true
}
}
});
cube(`Tags`, {
sql: `select e.id, t.id as tag from events e CROSS JOIN UNNEST(tags) t (id, idx)`,
dimensions: {
id: {
sql: `id || tag`,
type: `string`,
primaryKey: true
},
tag: {
sql: `tag`,
type: `string`
}
}
});
然后可以使用 Tags
多维数据集上的等于过滤器来查询它:
{
"measures": ["Events.count"],
"filters": [{
"dimension": "Tags.tag",
"operator": "equals",
"values": ["red"]
}]
}
假设我的数据中有一组信息(例如:tags: ['red', 'blue', 'green']
)。我如何将其添加到我的多维数据集以执行类似过滤标签数组 contains
特定值的操作?
我专门使用 Athena 驱动程序并预先聚合到 Aurora Postgres 中。
这是我到目前为止的进展,但还远远不够。
cube(`Events`, {
sql: `select * from events`,
joins: {
Tags: {
relationship: `hasMany`,
sql: `${tags}.id = ${tags}`
}
},
});
cube(`Tags`, {
sql: `UNNEST(tags) t (id, idx)`,
dimensions: {
tag: {
sql: `id`,
type: `string`
}
}
});
这是一个正确的方向。应添加标签多维数据集中事件 table 的主键和 select:
cube(`Events`, {
sql: `select * from events`,
joins: {
Tags: {
relationship: `hasMany`,
sql: `${Events}.id = ${Tags}.id`
}
},
dimensions: {
id: {
sql: `id`,
type: `string`,
primaryKey: true
}
}
});
cube(`Tags`, {
sql: `select e.id, t.id as tag from events e CROSS JOIN UNNEST(tags) t (id, idx)`,
dimensions: {
id: {
sql: `id || tag`,
type: `string`,
primaryKey: true
},
tag: {
sql: `tag`,
type: `string`
}
}
});
然后可以使用 Tags
多维数据集上的等于过滤器来查询它:
{
"measures": ["Events.count"],
"filters": [{
"dimension": "Tags.tag",
"operator": "equals",
"values": ["red"]
}]
}