@qrvey/formula-lang
Version:
QFormula support for qrvey projects
46 lines • 1.19 kB
JavaScript
import { AST_PRIMITIVES, OPERATION_SCOPE } from '../constants';
import { isANumericColumnParam, replaceDotByUnderscore } from '../utils';
/**
* `MED` Returns the aggregated MEDIAN of a column.
*/
export const MED = {
identifier: 'MED',
operationScope: OPERATION_SCOPE.AGGREGATE,
functionScope: [OPERATION_SCOPE.AGGREGATE],
parameters: [
{
identifier: 'VALUE',
optional: false,
expectedPrimitive: AST_PRIMITIVES.NUMBER,
validator: [isANumericColumnParam],
},
],
transpiler: {
elasticsearch,
snowflake,
redshift,
postgresql,
databricks,
},
primitiveResult: AST_PRIMITIVES.NUMBER,
};
function elasticsearch(value) {
const _value = replaceDotByUnderscore(value);
return `params.get("MEDIAN_${_value}")`;
}
function SQL(value) {
return `MEDIAN(${value})`;
}
function snowflake(value) {
return SQL(value);
}
function redshift(value) {
return SQL(value);
}
function postgresql(value) {
return `PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY ${value})`;
}
function databricks(value) {
return SQL(value);
}
//# sourceMappingURL=aggMed.js.map