Cube (alpha)

The Cube integration synchronizes your Cubes, dimensions, and measures with Grai. In this way you can quickly identify which data is being used in your Cube instance.

Web App

Cube Integration Homescreen

Fields

FieldValueExample
sourceThe name of the source, see sourcesmy-source
NameName for connectionCube
NamespaceNamespace for the connection, see namespacedefault
api_urlThe API url for your cube instance. This should end with '/v1'.https://red-apple.aws-us-west-2.cubecloudapp.dev/cubejs-api/v1 (opens in a new tab)
api_tokenThe JWT web token you wish to use for authentication with Cube.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTAyNjcwMzR9.CGi3Bo-FBKMFTD4l4q06dIixjcw5zpzVBgnZcOWrC-A
namespace_mapAn Optional JSON string (see below)see below

You can find more information about finding your api_url and associated api_token here (opens in a new tab). However, if you know the api_secret associated with your Cube instance you can use the following python script to generate a JWT token using the pyjwt library. This default token will be used to authenticate with the Cube API and includes no expiration date. You can uncomment the "exp" field to add an expiration date to the token with any duration you wish, however, you will need to rotate this token in Grai when it expires.

import jwt
import datetime
 
payload = {
    "iat": datetime.datetime.now(datetime.timezone.utc)
    #"exp": datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=365),
}
token = jwt.encode(payload, CUBE_API_SECRET, algorithm="HS256")
print(token)

Namespace Map

ℹ️

Grai will automatically extract source data from the "meta" field of your Cube definition files as well. You can find more information about how to use the meta field below.

In order to automatically tie your data lineage together, Grai needs to know which Grai namespace corresponds to each cube in your project. The namespaces field should be a JSON string with the Grai namespace for each Cube name e.g.

{
    "<cube_name>": "<namespace>"
}

Connecting Cube to other Data sources

In order to tie your Cube metadata into the rest of your data stack we need to know which data sources are associated with each Cube. Unfortunately, the Cube REST api's don't provide that information at the moment. Grai provides two options to incorporate this additional metadata

You can include this context when setting up a Cube connection in the namespace map field described above or alternatively in the meta field of your cube definition.

The Cube Meta Field

Grai will automatically read the meta field from your Cube schema definitions. Grai metadata should be placed under the "grai" subheading in the meta. Currently there are two fields we read.

FieldValueExample
source_namespaceThe Grai namespace associated with the Cube data source of the cube.
table_nameOptional. The name of the table the cube is querying from.

An example cube definition file can be found below.

cubes:
  - name: customers
    sql_table: customers
    data_source: grai
    meta:
      grai:
        source_namespace: default
 
    measures:
      - name: count
        sql: id
        type: count

Python Library

Installation

Install the Metabase Grai integration with pip

pip install grai_source_cube

More information about the API is available here.

Example

The library is split into a few distinct functions but if you only wish to extract nodes/edges you can do so as follows:

from grai_source_cube.base import CubeIntegration
from grai_schemas.v1.source import SourceSpec
 
config = {
    "api_url": "http://localhost:4000/cubejs-api/v1",
    "api_token": "<your_jwt_token>"
}
 
cube_source = SourceSpec(name="CubeSource", workspace={'name': 'your_workspace', 'organization': 'your_organization'})
 
integration = LookerIntegration(
    source=cube_source,
    config=config,
    namespace=<your_namespace>,
)
 
nodes, edges = integration.get_nodes_and_edges()
client.post([nodes, edges])