Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/cubejs-api-gateway/openspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ components:
type: "string"
description:
type: "string"
cubeDescription:
type: "string"
description: "Description of the parent cube/view this segment belongs to"
shortTitle:
type: "string"
meta:
Expand Down Expand Up @@ -132,6 +135,9 @@ components:
type: "string"
description:
type: "string"
cubeDescription:
type: "string"
description: "Description of the parent cube/view this dimension belongs to"
type:
type: "string"
aliasMember:
Expand Down Expand Up @@ -172,6 +178,9 @@ components:
type: "string"
description:
type: "string"
cubeDescription:
type: "string"
description: "Description of the parent cube/view this measure belongs to"
type:
type: "string"
aggType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ConfigItem = {
title: string;
shortTitle: string;
description: string;
cubeDescription?: string;
type: string;
format: string;
/** ISO 4217 currency code in uppercase (e.g. USD, EUR) */
Expand Down Expand Up @@ -61,6 +62,7 @@ const annotation = (
title: config.title,
shortTitle: config.shortTitle,
description: config.description,
cubeDescription: config.cubeDescription,
type: config.type,
format: config.format,
currency: config.currency,
Expand Down
6 changes: 6 additions & 0 deletions packages/cubejs-api-gateway/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,11 @@ describe('API Gateway', () => {
expect(res.body.cubes[0]?.description).toBe('cube from compilerApi mock');
expect(res.body.cubes[0]?.hasOwnProperty('sql')).toBe(false);
expect(res.body.cubes[0]?.dimensions.find(dimension => dimension.name === 'Foo.id').description).toBe('id dimension from compilerApi mock');
expect(res.body.cubes[0]?.dimensions.find(dimension => dimension.name === 'Foo.id').cubeDescription).toBe('cube from compilerApi mock');
expect(res.body.cubes[0]?.measures.find(measure => measure.name === 'Foo.bar').description).toBe('measure from compilerApi mock');
expect(res.body.cubes[0]?.measures.find(measure => measure.name === 'Foo.bar').cubeDescription).toBe('cube from compilerApi mock');
expect(res.body.cubes[0]?.segments.find(segment => segment.name === 'Foo.quux').description).toBe('segment from compilerApi mock');
expect(res.body.cubes[0]?.segments.find(segment => segment.name === 'Foo.quux').cubeDescription).toBe('cube from compilerApi mock');
});

test('meta endpoint extended to get schema information with additional data', async () => {
Expand All @@ -699,8 +702,11 @@ describe('API Gateway', () => {
expect(res.body.cubes[0]?.description).toBe('cube from compilerApi mock');
expect(res.body.cubes[0]?.hasOwnProperty('sql')).toBe(true);
expect(res.body.cubes[0]?.dimensions.find(dimension => dimension.name === 'Foo.id').description).toBe('id dimension from compilerApi mock');
expect(res.body.cubes[0]?.dimensions.find(dimension => dimension.name === 'Foo.id').cubeDescription).toBe('cube from compilerApi mock');
expect(res.body.cubes[0]?.measures.find(measure => measure.name === 'Foo.bar').description).toBe('measure from compilerApi mock');
expect(res.body.cubes[0]?.measures.find(measure => measure.name === 'Foo.bar').cubeDescription).toBe('cube from compilerApi mock');
expect(res.body.cubes[0]?.segments.find(segment => segment.name === 'Foo.quux').description).toBe('segment from compilerApi mock');
expect(res.body.cubes[0]?.segments.find(segment => segment.name === 'Foo.quux').cubeDescription).toBe('cube from compilerApi mock');
});

describe('multi query support', () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/cubejs-api-gateway/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,25 @@ export const compilerApi = jest.fn().mockImplementation(async () => ({
{
name: 'Foo.bar',
description: 'measure from compilerApi mock',
cubeDescription: 'cube from compilerApi mock',
isVisible: true,
},
],
dimensions: [
{
name: 'Foo.id',
description: 'id dimension from compilerApi mock',
cubeDescription: 'cube from compilerApi mock',
isVisible: true,
},
{
name: 'Foo.time',
cubeDescription: 'cube from compilerApi mock',
isVisible: true,
},
{
name: 'Foo.timeGranularities',
cubeDescription: 'cube from compilerApi mock',
isVisible: true,
granularities: [
{
Expand All @@ -120,6 +124,7 @@ export const compilerApi = jest.fn().mockImplementation(async () => ({
{
name: 'Foo.quux',
description: 'segment from compilerApi mock',
cubeDescription: 'cube from compilerApi mock',
isVisible: true,
},
],
Expand All @@ -138,6 +143,7 @@ export const compilerApi = jest.fn().mockImplementation(async () => ({
{
name: 'Foo.bar',
description: 'measure from compilerApi mock',
cubeDescription: 'cube from compilerApi mock',
sql: 'bar',
isVisible: true,
},
Expand All @@ -146,17 +152,20 @@ export const compilerApi = jest.fn().mockImplementation(async () => ({
{
name: 'Foo.id',
description: 'id dimension from compilerApi mock',
cubeDescription: 'cube from compilerApi mock',
isVisible: true,
},
{
name: 'Foo.time',
cubeDescription: 'cube from compilerApi mock',
isVisible: true,
},
],
segments: [
{
name: 'Foo.quux',
description: 'segment from compilerApi mock',
cubeDescription: 'cube from compilerApi mock',
isVisible: true,
},
],
Expand Down
3 changes: 3 additions & 0 deletions packages/cubejs-backend-shared/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ const variables: Record<string, (...args: any) => any> = {
nestedFoldersDelimiter: () => get('CUBEJS_NESTED_FOLDERS_DELIMITER')
.default('')
.asString(),
maxEmbeddingDescriptionLength: () => get('CUBEJS_MAX_EMBEDDING_DESCRIPTION_LENGTH')
.default('0')
.asInt(),
defaultTimezone: () => get('CUBEJS_DEFAULT_TIMEZONE')
.default('UTC')
.asString(),
Expand Down
1 change: 1 addition & 0 deletions packages/cubejs-client-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ export type BaseCubeMember = {
title: string;
shortTitle: string;
description?: string;
cubeDescription?: string;
/**
* @deprecated use `public` instead
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type MeasureConfig = {
name: string;
title: string;
description?: string;
cubeDescription?: string;
shortTitle: string;
format?: MeasureFormat;
currency?: string;
Expand All @@ -92,6 +93,7 @@ export type DimensionConfig = {
title: string;
type: string;
description?: string;
cubeDescription?: string;
shortTitle: string;
suggestFilterValues: boolean;
format?: DimensionFormat;
Expand All @@ -111,6 +113,7 @@ export type SegmentConfig = {
title: string;
shortTitle: string;
description?: string;
cubeDescription?: string;
meta?: any;
isVisible: boolean;
public: boolean;
Expand Down Expand Up @@ -184,6 +187,17 @@ export class CubeToMetaTransformer implements CompilerInterface {
this.queries = this.cubes;
}

private static truncateDescription(description: string | undefined): string | undefined {
if (!description) {
return description;
}
const maxLen = getEnv('maxEmbeddingDescriptionLength');
if (maxLen > 0 && description.length > maxLen) {
return description.slice(0, maxLen);
}
return description;
}

protected transform(cube: CubeDefinitionExtended, _errorReporter?: ErrorReporter): TransformedCube {
const extendedCube = cube as ExtendedCubeDefinition;
const cubeName = extendedCube.name;
Expand Down Expand Up @@ -229,21 +243,25 @@ export class CubeToMetaTransformer implements CompilerInterface {

const nestedFolders: NestedFolder[] = (extendedCube.folders || []).map((f: Folder) => processFolder(f));

const truncDesc = CubeToMetaTransformer.truncateDescription;
const cubeDesc = truncDesc(extendedCube.description);

return {
config: {
name: cubeName,
type: extendedCube.isView ? 'view' : 'cube',
title: cubeTitle,
isVisible: isCubeVisible,
public: isCubeVisible,
description: extendedCube.description,
description: cubeDesc,
connectedComponent: this.joinGraph.connectedComponents()[cubeName],
meta: extendedCube.meta,
measures: Object.entries(extendedCube.measures || {}).map((nameToMetric: [string, any]) => {
const metricDef = nameToMetric[1] as ExtendedCubeSymbolDefinition;
const measureVisibility = isCubeVisible ? this.isVisible(metricDef, true) : false;
return {
...this.measureConfig(cubeName, cubeTitle, nameToMetric),
cubeDescription: cubeDesc,
isVisible: measureVisibility,
public: measureVisibility,
};
Expand All @@ -260,7 +278,8 @@ export class CubeToMetaTransformer implements CompilerInterface {
name: `${cubeName}.${dimensionName}`,
title: this.title(cubeTitle, nameToDimension, false),
type: this.dimensionDataType(extendedDimDef.type || 'string'),
description: extendedDimDef.description,
description: truncDesc(extendedDimDef.description),
cubeDescription: cubeDesc,
shortTitle: this.title(cubeTitle, nameToDimension, true),
suggestFilterValues:
extendedDimDef.suggestFilterValues == null
Expand Down Expand Up @@ -295,7 +314,8 @@ export class CubeToMetaTransformer implements CompilerInterface {
name: `${cubeName}.${segmentName}`,
title: this.title(cubeTitle, nameToSegment, false),
shortTitle: this.title(cubeTitle, nameToSegment, true),
description: extendedSegmentDef.description,
description: truncDesc(extendedSegmentDef.description),
cubeDescription: cubeDesc,
meta: extendedSegmentDef.meta,
isVisible: segmentVisibility,
public: segmentVisibility,
Expand Down Expand Up @@ -383,7 +403,7 @@ export class CubeToMetaTransformer implements CompilerInterface {
return {
name,
title: this.title(cubeTitle, nameToMetric, false),
description: extendedMetricDef.description,
description: CubeToMetaTransformer.truncateDescription(extendedMetricDef.description),
shortTitle: this.title(cubeTitle, nameToMetric, true),
format: this.transformMeasureFormat(extendedMetricDef.format),
currency: extendedMetricDef.currency?.toUpperCase(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Object {
"dimensions": Array [
Object {
"aliasMember": "CubeA.id",
"cubeDescription": undefined,
"currency": undefined,
"description": "Description for CubeA.id",
"format": "imageUrl",
Expand All @@ -27,6 +28,7 @@ Object {
},
Object {
"aliasMember": "CubeB.other_id",
"cubeDescription": undefined,
"currency": undefined,
"description": "Description for CubeB.other_id",
"format": "imageUrl",
Expand All @@ -53,6 +55,7 @@ Object {
Object {
"aggType": "number",
"aliasMember": "CubeA.count_a",
"cubeDescription": undefined,
"cumulative": false,
"cumulativeTotal": false,
"currency": undefined,
Expand All @@ -76,6 +79,7 @@ Object {
Object {
"aggType": "number",
"aliasMember": "CubeB.count_b",
"cubeDescription": undefined,
"cumulative": false,
"cumulativeTotal": false,
"currency": undefined,
Expand Down Expand Up @@ -114,6 +118,7 @@ Object {
"dimensions": Array [
Object {
"aliasMember": "CubeB.other_id",
"cubeDescription": undefined,
"currency": undefined,
"description": "Description for CubeB.other_id",
"format": "imageUrl",
Expand All @@ -140,6 +145,7 @@ Object {
Object {
"aggType": "number",
"aliasMember": "CubeA.count_a",
"cubeDescription": undefined,
"cumulative": false,
"cumulativeTotal": false,
"currency": undefined,
Expand All @@ -163,6 +169,7 @@ Object {
Object {
"aggType": "number",
"aliasMember": "CubeB.count_b",
"cubeDescription": undefined,
"cumulative": false,
"cumulativeTotal": false,
"currency": undefined,
Expand Down Expand Up @@ -201,6 +208,7 @@ Object {
"dimensions": Array [
Object {
"aliasMember": "CubeA.id",
"cubeDescription": undefined,
"currency": undefined,
"description": "Description for CubeA.id",
"format": "imageUrl",
Expand All @@ -221,6 +229,7 @@ Object {
},
Object {
"aliasMember": "CubeB.id",
"cubeDescription": undefined,
"currency": undefined,
"description": "Description for CubeB.id",
"format": "imageUrl",
Expand All @@ -241,6 +250,7 @@ Object {
},
Object {
"aliasMember": "CubeB.other_id",
"cubeDescription": undefined,
"currency": undefined,
"description": "Description for CubeB.other_id",
"format": "imageUrl",
Expand All @@ -267,6 +277,7 @@ Object {
Object {
"aggType": "number",
"aliasMember": "CubeA.count_a",
"cubeDescription": undefined,
"cumulative": false,
"cumulativeTotal": false,
"currency": undefined,
Expand All @@ -290,6 +301,7 @@ Object {
Object {
"aggType": "number",
"aliasMember": "CubeB.count_b",
"cubeDescription": undefined,
"cumulative": false,
"cumulativeTotal": false,
"currency": undefined,
Expand Down Expand Up @@ -328,6 +340,7 @@ Object {
"dimensions": Array [
Object {
"aliasMember": "CubeB.other_id",
"cubeDescription": undefined,
"currency": undefined,
"description": "Description for CubeB.other_id",
"format": "imageUrl",
Expand All @@ -354,6 +367,7 @@ Object {
Object {
"aggType": "number",
"aliasMember": "CubeA.count_a",
"cubeDescription": undefined,
"cumulative": false,
"cumulativeTotal": false,
"currency": undefined,
Expand All @@ -377,6 +391,7 @@ Object {
Object {
"aggType": "number",
"aliasMember": "CubeB.count_b",
"cubeDescription": undefined,
"cumulative": false,
"cumulativeTotal": false,
"currency": undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct V1CubeMetaDimension {
pub short_title: Option<String>,
#[serde(rename = "description", skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(rename = "cubeDescription", skip_serializing_if = "Option::is_none")]
pub cube_description: Option<String>,
#[serde(rename = "type")]
pub r#type: String,
/// When dimension is defined in View, it keeps the original path: Cube.dimension
Expand Down Expand Up @@ -48,6 +50,7 @@ impl V1CubeMetaDimension {
title: None,
short_title: None,
description: None,
cube_description: None,
r#type,
alias_member: None,
granularities: None,
Expand Down
Loading
Loading