cube
cube copied to clipboard
Is there a way to pass the parameters to `segments` ?
Problem
I need a complex filter which based on the documentation I need to use segments
. The filter that I want to achieve is gonna be look like these:
segments: {
notMemberExcept: {
sql: `(
${CUBE}.user_id NOT IN (
SELECT user_id FROM members
) OR ${CUBE.userId} IN ($ValueFromUser) )`,
},
},
This where clause is important to be like that because previously I used alternative SQL that complied with CubeJS implementation but turns out it's gonna be a performance issue.
The problem is how I get the value from API in cube schema?
Related Cube.js schema
cube(`Users`, {
sql: `SELECT * FROM users`,
joins: {
Members: {
relationship: `hasMany`,
sql: `
${CUBE.orgId} = ${Members.orgId} AND
${CUBE.userId} = ${Members.userId}
`,
}
}
dimensions: {
orgId: {
sql: `org_id`,
type: `string`,
primaryKey: true,
shown: true,
},
issueId: {
sql: `user_id`,
type: `string`,
primaryKey: true,
shown: true,
},
name: {
sql: `name`,
type: `string`,
},
},
Hi @fyfirman 👋
Segments are not a good fit for this use case. Please decompose this segment using boolean logic operators in your query.
@fyfirman Did my advice help?