cube-js / cube

📊 Cube — The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.85k stars 1.77k forks source link

Dynamic data models with Jinja and Python: Does not support joins #7033

Open chaitnaya1391 opened 1 year ago

chaitnaya1391 commented 1 year ago

Describe the bug Dynamic addition of SQL joins sql: "{{ join.sql }}" enclosed in quotes fails. Without the quotes, it throws a character (=) error in YAML

cubes.yml.jinja file is as follow:

cubes:

  {%- set data = load_data() %}
  {%- if data is not none %}
    {%- for cube in data["cubes"] %}

    - name: {{ cube.object_name }}
      sql: {{ cube.object_name }}

    {%- if cube.joins is not none and cube.joins|length > 0 %}
      joins:
        {%- for join in cube.joins %}
        - name: {{ join.name }}
          type: {{ join.relationship }}
          sql: "{{ join.sql }}"
        {%- endfor %}
    {%- endif %}

    {%- if cube.dimensions is not none and cube.dimensions|length > 0 %}
      dimensions:
        {%- for dimension in cube.dimensions %}
        - name: {{ dimension.name }}
          type: {{ dimension.type }}
          sql: {{ dimension.sql }}
        {%- endfor %}
    {%- endif %}
    {%- endfor %}
  {%- endif %}

Error:

cube       | TypeError: js_yaml_1.default.stringify is not a function
cube       |     at /cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/YamlCompiler.ts:281:74
cube       |     at Array.map (<anonymous>)
cube       |     at YamlCompiler.yamlArrayToObj (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/YamlCompiler.ts:276:32)
cube       |     at YamlCompiler.transformYamlCubeObj (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/YamlCompiler.ts:126:26)
cube       |     at YamlCompiler.transpileAndPrepareJsFile (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/YamlCompiler.ts:108:26)
cube       |     at /cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/YamlCompiler.ts:93:39
cube       |     at Array.forEach (<anonymous>)
cube       |     at YamlCompiler.compileYamlFile (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/YamlCompiler.ts:92:31)
cube       |     at YamlCompiler.compileYamlWithJinjaFile (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/YamlCompiler.ts:68:17)
cube       |     at DataSchemaCompiler.compileFile (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/DataSchemaCompiler.js:237:25)
cube       |     at /cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/DataSchemaCompiler.js:205:14
cube       |     at Array.forEach (<anonymous>)
cube       |     at DataSchemaCompiler.compileCubeFiles (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/DataSchemaCompiler.js:204:8)
cube       |     at compilePhase (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/DataSchemaCompiler.js:100:46)
cube       |     at DataSchemaCompiler.doCompile (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/DataSchemaCompiler.js:102:12)
cube       |     at CompilerApi.getCompilers (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:65:26)
cube       |     at CompilerApi.metaConfig (/cube/node_modules/@cubejs-backend/server-core/src/core/CompilerApi.js:215:13)
cube       |     at ApiGateway.meta (/cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:514:26)
cube       |     at /cube/node_modules/@cubejs-backend/api-gateway/src/gateway.ts:318:11
ovr commented 1 year ago

Hello @chaitnaya1391 ,

This error was caused by name; it's null/undefined somewhere in your data model.

Could you give it a try again with the latest release (it will show you an error without crashing)?

Thanks!