UNPKG

@qrvey/formula-lang

Version:

QFormula support for qrvey projects

43 lines 1 kB
import { AST_PRIMITIVES } from '../constants'; import { isNumberParam } from '../utils'; /** * `EVEN` Returns a number rounded to the next greatest even integer. */ export const EVEN = { identifier: 'EVEN', parameters: [ { identifier: 'VALUE', optional: false, expectedPrimitive: AST_PRIMITIVES.NUMBER, validator: [isNumberParam], }, ], transpiler: { elasticsearch, snowflake, redshift, postgresql, }, primitiveResult: 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