Support old and new dimension definitions

This commit is contained in:
Javier Goizueta 2018-09-25 19:10:56 +02:00
parent fbcfc7a582
commit fbf3fd9d8c

View File

@ -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}"`;
}));
};