cube-js / cube-js/cube

Is there a way to pass the parameters to `segments` ?

Open
#7,915 2 comments 0 reactions 0 assignees View on GitHub
data modeling question
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**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**
```javascript
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`,
},
},
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.