UNPKG

@qrvey/formula-lang

Version:

QFormula support for qrvey projects

43 lines 1.01 kB
import { AST_PRIMITIVES } from '../constants'; import { isNumberParam } from '../utils'; /** * `ODD` Returns a number rounded to the next greatest odd integer. */ export const ODD = { identifier: 'ODD', parameters: [ { identifier: 'VALUE', optional: false, expectedPrimitive: AST_PRIMITIVES.NUMBER, validator: [isNumberParam], }, ], transpiler: { elasticsearch, snowflake, redshift, postgresql, }, primitiveResult: AST_PRIMITIVES.NUMBER, }; function elasticsearch(value) { return `ODD(${value})`; } function SQL(value) { return ` (((CASE WHEN ${value} IS NULL THEN NULL ELSE CEIL((ABS(${value}) + 1 ) / 2.0) END) * 2 - 1) * (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=odd.js.map