Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-value filtering on same column through FILTER_PARAMS #2854

Merged
merged 3 commits into from Aug 31, 2021

Conversation

omab
Copy link
Contributor

@omab omab commented May 28, 2021

Check List

  • Tests has been run in packages where changes made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Issue Reference this PR resolves

No related issue.

Description of Changes Made (if issue reference is not provided)

This PR adds support to properly process multiple filters over the same dimension when accessing them through FILTER_PARAMS context variable, this becomes particularly handy when the expression involved is an ILIKE operator (or similar).

With this change it's possible to define SQLs like:

cube('Foo', {
  sql: `SELECT id, name FROM foo WHERE ${FILTER_PARAMS.Foo.name.filter('name')}`,
  dimensions: {
    id: {
      type: 'number',
      sql: 'id',
      primaryKey: true
    },
    name: {
      type: 'string',
      sql: 'name'
    }
  }
}

and if the filter passed are in the form:

filters: [
  {
    dimension: 'Foo.name',
    operator: 'contains',
    values: ['Foo']
  }, {
    dimension: 'Foo.name',
    operator: 'contains',
    values: ['Bar']
  }
]

Will result in an SQL query like:

SELECT id, name FROM foo WHERE name ILIKE '%Foo%' AND name ILIKE '%Bar%';

@omab omab requested a review from a team as a code owner May 28, 2021 20:06
@github-actions github-actions bot added the pr:community Contribution from Cube.js community members. label May 28, 2021
@omab omab changed the title Support multi-value filtering on same column Support multi-value filtering on same column through FILTER_PARAMS May 28, 2021
@paveltiunov
Copy link
Member

@omab Hey Matias! Sorry for the delay! Thanks for contributing it! Looks great!

@paveltiunov paveltiunov merged commit efc5745 into cube-js:master Aug 31, 2021
@omab
Copy link
Contributor Author

omab commented Aug 31, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:community Contribution from Cube.js community members.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants