Support old and new dimension definitions
This commit is contained in:
parent
fbcfc7a582
commit
fbf3fd9d8c
@ -197,31 +197,36 @@ const timeDimensionParameters = definition => {
|
||||
};
|
||||
};
|
||||
|
||||
const dimensionExpression = definition => {
|
||||
// Adapt old-style dimension definitions for backwards compatibility
|
||||
const adaptDimensionDefinition = definition => {
|
||||
if (typeof(definition) === 'string') {
|
||||
return `"definition"`;
|
||||
return { column: definition }
|
||||
}
|
||||
return definition;
|
||||
};
|
||||
|
||||
const dimensionExpression = definition => {
|
||||
if (definition.group_by) {
|
||||
// Currently only time dimensions are supported with parameters
|
||||
return timeDimension(timeDimensionParameters(definition));
|
||||
} else {
|
||||
return `"${definition.column}"`;
|
||||
}
|
||||
// Currently only time dimensions are supported with parameters
|
||||
return timeDimension(timeDimensionParameters(definition));
|
||||
};
|
||||
|
||||
const dimensionNames = (ctx, table) => {
|
||||
let dimensions = aggregateDimensions(ctx);
|
||||
if (table) {
|
||||
return sep(Object.keys(dimensions).map(
|
||||
dimension_name => `${table}."${dimension_name}"`
|
||||
));
|
||||
}
|
||||
return sep(Object.keys(dimensions).map(dimension_name => {
|
||||
return `"${dimension_name}"`;
|
||||
return sep(Object.keys(dimensions).map(dimensionName => {
|
||||
return table ? `${table}."${dimensionName}"` : `"${dimensionName}"`;
|
||||
}));
|
||||
};
|
||||
|
||||
const dimensionDefs = ctx => {
|
||||
let dimensions = aggregateDimensions(ctx);
|
||||
return sep(Object.keys(dimensions).map(dimension_name => {
|
||||
const expression = dimensionExpression(dimensions[dimension_name]);
|
||||
return `${expression} AS "${dimension_name}"`;
|
||||
return sep(Object.keys(dimensions).map(dimensionName => {
|
||||
const dimension = adaptDimensionDefinition(dimensions[dimensionName]);
|
||||
const expression = dimensionExpression(dimension);
|
||||
return `${expression} AS "${dimensionName}"`;
|
||||
}));
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user