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

PreAggregations not working in Oracle #4374

Open MasaNahti opened 2 years ago

MasaNahti commented 2 years ago

Describe the bug I am using Cube.js with Docker in dev mode and testing it with our Oracle 12c database. In Cube.js Playground, I use "Add Rollup to Schema" to define PreAggregations. After defining a PreAggregation like this, I run a query in the Playground that should hit PreAggregations. According to Cube logs, it does, but then it breaks with this issue which is also displayed in Playground:

ORA-01036: illegal variable name/number

Logs are huge and confusing, so I will just copy the error and its traceback:

Error: ORA-01036: illegal variable name/number
Error querying db: scheduler-09309102-bab3-4331-98c4-ee59e7ec812d
{}
Error: ORA-01036: illegal variable name/number
    at QueryQueue.parseResult (/cubejs/packages/cubejs-query-orchestrator/src/orchestrator/QueryQueue.js:138:13)
    at QueryQueue.executeInQueue (/cubejs/packages/cubejs-query-orchestrator/src/orchestrator/QueryQueue.js:127:19)
    at PreAggregationLoader.loadPreAggregationWithKeys (/cubejs/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts:631:7)
    at PreAggregationLoader.loadPreAggregation (/cubejs/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts:510:22)
    at QueryOrchestrator.fetchQuery (/cubejs/packages/cubejs-query-orchestrator/src/orchestrator/QueryOrchestrator.ts:97:59)
    at OrchestratorApi.executeQuery (/cubejs/packages/cubejs-server-core/src/core/OrchestratorApi.ts:57:20)
    at /cubejs/packages/cubejs-server-core/src/core/RefreshScheduler.ts:459:13
    at async Promise.all (index 0)
    at async Promise.all (index 1)
    at RefreshScheduler.runScheduledRefresh (/cubejs/packages/cubejs-server-core/src/core/RefreshScheduler.ts:165:9)
    at async Promise.all (index 0)
    at Timeout._onTimeout (/cubejs/packages/cubejs-backend-shared/src/promises.ts:139:9)

To Reproduce Steps to reproduce the behavior:

  1. Connect Docker instance of Cube to Oracle DB (version 12c)
  2. Create a simple schema for your Oracle table
  3. Open Cube.js Playground
  4. In Playground menu, add measures and dimensions of choice, plus a Time dimension for a time period and granularity of choice
  5. Click the button "Add Rollup to Schema" and then the button "Add to the Data schema"
  6. Run query and see the error above

Expected behavior Working preAggregations with Oracle database.

Minimally reproducible Cube Schema I didn't understand this part of the issue instruction so I am just copying an example of my data schema:

cube(`CubeTest`, {
    sql: `SELECT * FROM some_table`,
    measures: {
      count: {
        type: `count`,
        drillMembers: []
      },
    },
    dimensions: {
      parameter: {
        sql: `parameter`,
        type: `number`,
      },
      datum: {
        sql: `datum`,
        type: `time`
      },
      station: {
        sql: `station`,
        type: `string`
      },
    },
    dataSource: `default`
  });

Version: Cube.js (0.29.34), ran in a Docker container from an image built from my custom dev.Dockerfile (in order to solve this open issue)

Additional context I get the same error whether I do mess with Cube code and fix this issue or not. If I do the fix, a certain query will work if I have no PreAggregations defined. That means that querying the Oracle database in the background works. But after I "Add Rollup to Schema", for this same query I get the error above. That makes me think that when building PreAggregations there is some other query to Oracle database that Oracle does not like. Or, querying the PreAggregation tables can also signal ORA errors. The same issue happens whether I use partitions or not. Cube Store (in dev mode) is running. My only modification in the cube.js file is:

module.exports = {
    allowUngroupedWithoutPrimaryKey: true
  };

Though I am not using the ungrouped property for testing PreAggregations. I should mention that I get the same error if I use Postman for querying Cube as well.

I really wished to fix this by myself but it is just far out of my league.

github-actions[bot] commented 2 years ago

If you are interested in working on this issue, please leave a comment below and we will be happy to assign the issue to you. If this is the first time you are contributing a Pull Request to Cube.js, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube.js Slack.