Using dbt
This functionality only works with models written in JavaScript, not YAML.
Cube's metrics layer is able to read metrics definitions from dbt via the Metadata API and translate them into an equivalent Cube data model.
This can be done through reading the dbt-project.yml
file.
import dbt from '@cubejs-backend/dbt-schema-extension';
asyncModule(async () => {
// `/dbt` is the path to a folder containing `dbt-project.yml`
await dbt.loadMetricCubesFromDbtProject('/dbt');
});
Create a config.js
file as a sibling to the schema/
folder in your Cube
project:
exports.dbtJobId = 65806;
exports.dbtApiKey = 'YOUR_KEY_HERE';
Create a file called dbt.js
in the schema/
folder and enter the following
code snippet:
import dbt from '@cubejs-backend/dbt-schema-extension';
import { dbtJobId, dbtApiKey } from '../config';
asyncModule(async () => {
await dbt.loadMetricCubesFromDbtCloud(dbtJobId, dbtApiKey);
});
You can then define cubes under the above snippet:
import dbt from '@cubejs-backend/dbt-schema-extension';
import { dbtJobId, dbtApiKey } from '../config';
asyncModule(async () => {
await dbt.loadMetricCubesFromDbtCloud(dbtJobId, dbtApiKey);
});
cube('GithubCommitStatsCommitsCached', {
extends: GithubCommitStatsCommits,
preAggregations: {
main: {
measures: [commitsCount],
dimensions: [authorDomain, authorName],
timeDimension: timestamp,
granularity: 'day',
partitionGranularity: 'year',
},
},
});
Did you find this page useful?