cube-js / cube

๐Ÿ“Š Cube โ€” Universal semantic layer platform for AI, BI, spreadsheets, and embedded analytics
https://cube.dev
Other
17.97k stars 1.78k forks source link

Included member conflicts with existing member in view #6970

Open tobuka opened 1 year ago

tobuka commented 1 year ago

Describe the bug We have cube:

cube(`patient_network`, {
  sql: `SELECT
          id,
          meta_source,
          name,
          gender,
          year_of_birth,
          address_state,
          active,
          coalesce(toYear(today()) - year_of_birth, 0) as age
        FROM ehr.Patient
        AND (${FILTER_PARAMS.patient_network.age.filter(`age`)})
        AND (${FILTER_PARAMS.patient_network.gender.filter(`gender`)})`,

  public: false,

  measures: {
    count: {
      type: `count`,
      sql: `distinct ${CUBE}."id"`,
      description: `The count of unique patients in the dataset.`,
      shown: false
    },
  },

  dimensions: {
    id: {
      sql: `id`,
      type: `string`,
      description: `Patient ID`,
    },

    name: {
      sql: `name`,
      type: `string`,
      description: `Patient name`,
    },

    gender: {
      sql: `gender`,
      type: `string`
    },

    year_of_birth: {
      sql: `year_of_birth`,
      type: `time`,
      description: `Year of birth`,
    },

    age: {
      sql: `age`,
      type: "number",
      description: `Patient age`,
    },
  }
});

And we tried to create simple view:

view("test_view", {
  description: `Test view`,

  cubes: [
    {
      join_path: patient_network,
      prefix: true,
      includes: [`age`]
    },
  ],
  public: true
});

But we got error Compile errors: Included member 'patient_network_age' conflicts with existing member of 'test_view'. Please consider excluding this member.

We tried to create view like this:

view("test_view", {
  description: `Test view`,

  includes: [patient_network.age],
  public: true
});

but we got the same error

Expected behavior Working view

Version: 0.33.29

igorlukanin commented 1 year ago

Hi @ViktoriyaBurdey ๐Ÿ‘‹ Would you please try upgrading Cube to the latest version? I've tested this with 0.33.48 and both code snippets you've provided worked for me like a charm, unchanged.

tobuka commented 1 year ago

I've updated cube to version 0.33.48 (0.33.43 for clickhouse-driver) but it's not help. Error the same - Compile errors: Included member 'patient_network_age' conflicts with existing member of 'test_view'. Please consider excluding this member.

tobuka commented 1 year ago

Maybe I can check any configurations or something like that?

igorlukanin commented 1 year ago

May I kindly ask you to reproduce this in Cube Cloud? It's hard to debug without a common ground.

tobuka commented 1 year ago

Thanks, we've found the solution. We had problem in repositoryFactory option

fracca commented 1 year ago

Thanks, we've found the solution. We had problem in repositoryFactory option

Hey @ViktoriyaBurdey - Can you please explain further? I am having similar issues

yardenas commented 1 year ago

@fracca it seems like that happens when you have a cube and a view that share the same name (up to a base_) prefix. Changing the views name to something different resolved the issue

nolde commented 2 weeks ago

For anyone having this problem, we've found out that our problem was database permissions.

If your cube instance uses an user that does not have proper access to the database table you're targeting with the view, cubejs' schema compiler just goes crazy and spits out the Included member 'X' conflicts with existing member of 'Y' errors. Giving the user the appropriate permissions solves it all.

When you use a table with improper permissions in a normal cube, you get the proper error message; I would recommend cubejs to fix this issue to stop confusing people. We lost a lot of time before we realised what the actual issue was.

igorlukanin commented 1 week ago

@nolde Could you please help to reproduce? A minimal data model example, a minimal database schema, and a command to set "improper" permissions would be really helpful.

nolde commented 1 week ago

@igorlukanin sure!

  1. Create cube for target table
  2. Make sure cubejs does not have read permissions to target table at database level
  3. Create view that uses cube created in step 1

This will completely break the schema compiler and stop any queries from being executed.