Skip to content

Commit

Permalink
Add better warnings for missing timeAttribute property
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmroz-allegro committed Feb 1, 2022
1 parent e7c8de6 commit 48add25
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/common/models/data-cube/data-cube.mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { expect, use } from "chai";
import { $, AttributeInfo } from "plywood";
import { SinonSpy, spy } from "sinon";
import equivalent from "../../../client/utils/test-utils/equivalent";
import { deduceAttributes } from "../../utils/external/datacube-to-external";
import { Cluster } from "../cluster/cluster";
Expand Down Expand Up @@ -724,6 +725,28 @@ describe("DataCube", () => {
formula: "$__time"
};

describe("timeAttribute property warnings", () => {
let consoleWarnSpy: SinonSpy;

beforeEach(() => {
consoleWarnSpy = spy(console, "warn");
});

afterEach(() => {
consoleWarnSpy.restore();
});

it("should warn if timeAttribute is missing", () => {
fromConfig({ ...baseCube }, druidCluster);
expect(consoleWarnSpy.args[0][0]).to.be.equal("DataCube \"wiki\" should have property timeAttribute. Setting timeAttribute to default value \"__time\"");
});

it("should warn if timeAttribute has different value than \"__time\"", () => {
fromConfig({ ...baseCube, timeAttribute: "foobar" }, druidCluster);
expect(consoleWarnSpy.args[0][0]).to.be.equal('timeAttribute in DataCube "wiki" should have value "__time" because it is required by Druid. Overriding timeAttribute to "__time"');
});
});

it("should add timeAttribute", () => {
const cube = fromConfig({ ...baseCube, dimensions: [timeDimensionJS] }, druidCluster);
expect(cube.timeAttribute).to.be.equivalent($("__time"));
Expand Down
5 changes: 4 additions & 1 deletion src/common/models/data-cube/data-cube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ function readAttributes(config: DataCubeJS): Pick<DataCube, "attributes" | "attr
function readTimeAttribute(config: DataCubeJS, cluster: Cluster | undefined, dimensions: Dimensions): { dimensions: Dimensions, timeAttribute: RefExpression } {
const isFromDruidCluster = config.clusterName !== "native" && cluster.type === "druid";
if (isFromDruidCluster) {
if (config.timeAttribute !== "__time") {
if (!isTruthy(config.timeAttribute)) {
console.warn(`DataCube "${config.name}" should have property timeAttribute. Setting timeAttribute to default value "__time"`);
}
if (isTruthy(config.timeAttribute) && config.timeAttribute !== "__time") {
console.warn(`timeAttribute in DataCube "${config.name}" should have value "__time" because it is required by Druid. Overriding timeAttribute to "__time"`);
}
const timeAttribute = $("__time");
Expand Down

0 comments on commit 48add25

Please sign in to comment.