Skip to content

Combine the output of Cube JS. #8969

Open
@alexeybahterwork

Description

@alexeybahterwork

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionThe issue is a question. Please use Stack Overflow for questions.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions