@qrvey/formula-lang
Version:
QFormula support for qrvey projects
46 lines • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EVEN = void 0;
const constants_1 = require("../constants");
const utils_1 = require("../utils");
/**
* `EVEN` Returns a number rounded to the next greatest even integer.
*/
exports.EVEN = {
identifier: 'EVEN',
parameters: [
{
identifier: 'VALUE',
optional: false,
expectedPrimitive: constants_1.AST_PRIMITIVES.NUMBER,
validator: [utils_1.isNumberParam],
},
],
transpiler: {
elasticsearch,
snowflake,
redshift,
postgresql,
},
primitiveResult: constants_1.AST_PRIMITIVES.NUMBER,
};
function elasticsearch(value) {
return `EVEN(${value})`;
}
function SQL(value) {
return `
(((CASE
WHEN ${value} IS NULL THEN NULL
ELSE CEIL(ABS(${value}) / 2.0)
END) * 2) * (CASE WHEN ${value} < 0 THEN -1 ELSE 1 END))`.trim();
}
function snowflake(value) {
return SQL(value);
}
function redshift(value) {
return SQL(value);
}
function postgresql(value) {
return SQL(value);
}
//# sourceMappingURL=even.js.map