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

Combine the output of Cube JS. #8969

Open
alexeybahterwork opened this issue Nov 19, 2024 · 0 comments
Open

Combine the output of Cube JS. #8969

alexeybahterwork opened this issue Nov 19, 2024 · 0 comments
Labels
question The issue is a question. Please use Stack Overflow for questions.

Comments

@alexeybahterwork
Copy link

Problem

I have a cube with two opposing dimensions, contract_num and ds_number. When I use these in the playground, the result is as shown in the screenshot(pic 1). Is it possible to combine different data? I understand that I can join the data, but in this case, all of the data is stored in a single table.

I need to establish a relationship between the parent_guarantee_id and the string_id in order to have the contract number supplied on the lines, as shown in the screenshot(pic 2).

contract_num is output if sql: ${guarantee}.parent_guarantee_id is null

ds_number is output if sql: ${guarantee}.parent_guarantee_id is not null

I think Cube.js might be able to do this, but I'm not sure.
Can you please help me solve this problem?

Related Cube.js schema

cube(`guarantee`, {
  sql_table: `guarantee`,

  title: `Guarantee`,

  data_source: `default`,

  joins: {  },

  dimensions: {
    id: {
      sql: `id`,
      type: `number`,
      primary_key: true,
      title: `ID`,
      shown: false,
    },

    string_id: {
      sql: `id`,
      type: `string`,
      title: `string_id,
      shown: true,
    },

    parent_guarantee_id: {
      sql: `parent_guarantee_id`,
      type: `string`,
      title: 'parent_guarantee_id',
    },

    contract_num: {
      case: {
        when: [
          {
            sql: `${guarantee}.parent_guarantee_id is null`,
            label: { sql: `contract_num` },
          },
        ],
        else: { label: ` ` },
      },
      type: `string`,
      title: 'contract_num',
    },

    ds_number: {
      case: {
        when: [
          {
            sql: `${guarantee}.parent_guarantee_id is not null`,
            label: { sql: `contract_num` },
          },
        ],
        else: { label: ` ` },
      },
      type: `string`,
      title: 'ds_number,
    },

  },
});
pic 1 pic 2

I have simplified the cube, so I cannot provide the generated SQL. I believe it will not be necessary in this case.

@alexeybahterwork alexeybahterwork added the question The issue is a question. Please use Stack Overflow for questions. label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question The issue is a question. Please use Stack Overflow for questions.
Projects
None yet
Development

No branches or pull requests

1 participant