@qrvey/formula-lang 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +15 -0
- package/CHANGELOG.md +12 -0
- package/dist/{constants → cjs/constants}/index.d.ts +11 -2
- package/dist/cjs/constants/index.js +117 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/{constants → cjs/constants}/interfaces.d.ts +14 -4
- package/dist/cjs/constants/interfaces.js +3 -0
- package/dist/{constants → cjs/constants}/interfaces.js.map +1 -1
- package/dist/{errors → cjs/errors}/definitions.d.ts +20 -3
- package/dist/cjs/errors/definitions.js +91 -0
- package/dist/cjs/errors/definitions.js.map +1 -0
- package/dist/cjs/errors/elasticsearch.js +30 -0
- package/dist/cjs/errors/elasticsearch.js.map +1 -0
- package/dist/cjs/errors/engineErrors.js +25 -0
- package/dist/cjs/errors/engineErrors.js.map +1 -0
- package/dist/cjs/errors/index.js +21 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/errors/snowflake.js +20 -0
- package/dist/cjs/errors/snowflake.js.map +1 -0
- package/dist/cjs/functions/abs.js +38 -0
- package/dist/cjs/functions/abs.js.map +1 -0
- package/dist/cjs/functions/datedif.js +64 -0
- package/dist/cjs/functions/datedif.js.map +1 -0
- package/dist/cjs/functions/day.js +39 -0
- package/dist/cjs/functions/day.js.map +1 -0
- package/dist/cjs/functions/hour.js +39 -0
- package/dist/cjs/functions/hour.js.map +1 -0
- package/dist/cjs/functions/if.js +52 -0
- package/dist/cjs/functions/if.js.map +1 -0
- package/dist/cjs/functions/ifs.js +74 -0
- package/dist/cjs/functions/ifs.js.map +1 -0
- package/dist/cjs/functions/index.js +33 -0
- package/dist/cjs/functions/index.js.map +1 -0
- package/dist/cjs/functions/mid.js +54 -0
- package/dist/cjs/functions/mid.js.map +1 -0
- package/dist/cjs/functions/minute.js +39 -0
- package/dist/cjs/functions/minute.js.map +1 -0
- package/dist/cjs/functions/month.js +39 -0
- package/dist/cjs/functions/month.js.map +1 -0
- package/dist/cjs/functions/second.js +39 -0
- package/dist/cjs/functions/second.js.map +1 -0
- package/dist/cjs/functions/year.js +39 -0
- package/dist/cjs/functions/year.js.map +1 -0
- package/dist/cjs/grammar/generated/qformula.lang.d.ts +13 -0
- package/dist/cjs/grammar/generated/qformula.lang.js +50 -0
- package/dist/cjs/grammar/generated/qformula.lang.js.map +1 -0
- package/dist/cjs/grammar/qformula.grammar.js +18 -0
- package/dist/cjs/grammar/qformula.grammar.js.map +1 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +3 -2
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/main.d.ts +1 -0
- package/dist/cjs/main.js +69 -0
- package/dist/cjs/main.js.map +1 -0
- package/dist/cjs/parser/json-parser.js +201 -0
- package/dist/cjs/parser/json-parser.js.map +1 -0
- package/dist/cjs/parser/syntax-errors.d.ts +3 -0
- package/dist/cjs/parser/syntax-errors.js +28 -0
- package/dist/cjs/parser/syntax-errors.js.map +1 -0
- package/dist/cjs/transpiler/columnTranspilation.d.ts +3 -0
- package/dist/cjs/transpiler/columnTranspilation.js +29 -0
- package/dist/cjs/transpiler/columnTranspilation.js.map +1 -0
- package/dist/{transpiler → cjs/transpiler}/index.d.ts +4 -4
- package/dist/cjs/transpiler/index.js +107 -0
- package/dist/cjs/transpiler/index.js.map +1 -0
- package/dist/cjs/transpiler/unshiftCustomFunctions.d.ts +2 -0
- package/dist/cjs/transpiler/unshiftCustomFunctions.js +14 -0
- package/dist/cjs/transpiler/unshiftCustomFunctions.js.map +1 -0
- package/dist/cjs/transpiler/validateFuncStructure.js +41 -0
- package/dist/cjs/transpiler/validateFuncStructure.js.map +1 -0
- package/dist/{utils → cjs/utils}/customFunctions.d.ts +1 -0
- package/dist/cjs/utils/customFunctions.js +35 -0
- package/dist/cjs/utils/customFunctions.js.map +1 -0
- package/dist/{utils → cjs/utils}/elasticsearch/index.d.ts +1 -1
- package/dist/cjs/utils/elasticsearch/index.js +22 -0
- package/dist/cjs/utils/elasticsearch/index.js.map +1 -0
- package/dist/{utils → cjs/utils}/elasticsearch/scripts.d.ts +1 -0
- package/dist/cjs/utils/elasticsearch/scripts.js +57 -0
- package/dist/cjs/utils/elasticsearch/scripts.js.map +1 -0
- package/dist/cjs/utils/getMonthMaxDayAllowed.js +26 -0
- package/dist/cjs/utils/getMonthMaxDayAllowed.js.map +1 -0
- package/dist/cjs/utils/getNodeValue.js +13 -0
- package/dist/cjs/utils/getNodeValue.js.map +1 -0
- package/dist/cjs/utils/getVariableType.js +19 -0
- package/dist/cjs/utils/getVariableType.js.map +1 -0
- package/dist/cjs/utils/index.js +29 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/isDateParam.js +12 -0
- package/dist/cjs/utils/isDateParam.js.map +1 -0
- package/dist/cjs/utils/isNumberParam.js +12 -0
- package/dist/cjs/utils/isNumberParam.js.map +1 -0
- package/dist/cjs/utils/isPositiveNumberParam.js +12 -0
- package/dist/cjs/utils/isPositiveNumberParam.js.map +1 -0
- package/dist/cjs/utils/isStringParam.js +12 -0
- package/dist/cjs/utils/isStringParam.js.map +1 -0
- package/dist/cjs/utils/isValidDate.js +8 -0
- package/dist/cjs/utils/isValidDate.js.map +1 -0
- package/dist/cjs/utils/sql/index.js +6 -0
- package/dist/cjs/utils/sql/index.js.map +1 -0
- package/dist/cjs/utils/sql/scripts.js +44 -0
- package/dist/cjs/utils/sql/scripts.js.map +1 -0
- package/dist/module/constants/index.d.ts +53 -0
- package/dist/{constants → module/constants}/index.js +26 -0
- package/dist/module/constants/index.js.map +1 -0
- package/dist/module/constants/interfaces.d.ts +91 -0
- package/dist/module/constants/interfaces.js.map +1 -0
- package/dist/module/errors/definitions.d.ts +43 -0
- package/dist/module/errors/definitions.js +78 -0
- package/dist/module/errors/definitions.js.map +1 -0
- package/dist/module/errors/elasticsearch.d.ts +24 -0
- package/dist/module/errors/elasticsearch.js.map +1 -0
- package/dist/module/errors/engineErrors.d.ts +2 -0
- package/dist/module/errors/engineErrors.js.map +1 -0
- package/dist/module/errors/index.d.ts +2 -0
- package/dist/module/errors/index.js.map +1 -0
- package/dist/module/errors/snowflake.d.ts +15 -0
- package/dist/module/errors/snowflake.js.map +1 -0
- package/dist/module/functions/abs.d.ts +5 -0
- package/dist/module/functions/abs.js.map +1 -0
- package/dist/module/functions/datedif.d.ts +5 -0
- package/dist/module/functions/datedif.js.map +1 -0
- package/dist/module/functions/day.d.ts +5 -0
- package/dist/module/functions/day.js.map +1 -0
- package/dist/module/functions/hour.d.ts +5 -0
- package/dist/module/functions/hour.js.map +1 -0
- package/dist/module/functions/if.d.ts +5 -0
- package/dist/module/functions/if.js.map +1 -0
- package/dist/module/functions/ifs.d.ts +5 -0
- package/dist/module/functions/ifs.js.map +1 -0
- package/dist/module/functions/index.d.ts +4 -0
- package/dist/module/functions/index.js.map +1 -0
- package/dist/module/functions/mid.d.ts +5 -0
- package/dist/module/functions/mid.js.map +1 -0
- package/dist/module/functions/minute.d.ts +5 -0
- package/dist/module/functions/minute.js.map +1 -0
- package/dist/module/functions/month.d.ts +5 -0
- package/dist/module/functions/month.js.map +1 -0
- package/dist/module/functions/second.d.ts +5 -0
- package/dist/module/functions/second.js.map +1 -0
- package/dist/module/functions/year.d.ts +5 -0
- package/dist/module/functions/year.js.map +1 -0
- package/dist/module/grammar/generated/qformula.lang.d.ts +13 -0
- package/dist/{grammar → module/grammar}/generated/qformula.lang.js +5 -4
- package/dist/module/grammar/generated/qformula.lang.js.map +1 -0
- package/dist/module/grammar/qformula.grammar.d.ts +1 -0
- package/dist/module/grammar/qformula.grammar.js.map +1 -0
- package/dist/module/index.d.ts +10 -0
- package/dist/{index.js → module/index.js} +3 -2
- package/dist/module/index.js.map +1 -0
- package/dist/module/main.d.ts +1 -0
- package/dist/module/main.js +67 -0
- package/dist/module/main.js.map +1 -0
- package/dist/module/parser/json-parser.d.ts +3 -0
- package/dist/module/parser/json-parser.js +197 -0
- package/dist/module/parser/json-parser.js.map +1 -0
- package/dist/module/parser/syntax-errors.d.ts +3 -0
- package/dist/module/parser/syntax-errors.js +24 -0
- package/dist/module/parser/syntax-errors.js.map +1 -0
- package/dist/module/transpiler/columnTranspilation.d.ts +3 -0
- package/dist/module/transpiler/columnTranspilation.js +25 -0
- package/dist/module/transpiler/columnTranspilation.js.map +1 -0
- package/dist/module/transpiler/index.d.ts +18 -0
- package/dist/{transpiler → module/transpiler}/index.js +29 -21
- package/dist/module/transpiler/index.js.map +1 -0
- package/dist/module/transpiler/unshiftCustomFunctions.d.ts +2 -0
- package/dist/module/transpiler/unshiftCustomFunctions.js +10 -0
- package/dist/module/transpiler/unshiftCustomFunctions.js.map +1 -0
- package/dist/module/transpiler/validateFuncStructure.d.ts +2 -0
- package/dist/module/transpiler/validateFuncStructure.js.map +1 -0
- package/dist/module/utils/customFunctions.d.ts +4 -0
- package/dist/{utils → module/utils}/customFunctions.js +10 -2
- package/dist/module/utils/customFunctions.js.map +1 -0
- package/dist/module/utils/elasticsearch/index.d.ts +2 -0
- package/dist/{utils → module/utils}/elasticsearch/index.js +1 -1
- package/dist/module/utils/elasticsearch/index.js.map +1 -0
- package/dist/module/utils/elasticsearch/scripts.d.ts +11 -0
- package/dist/{utils → module/utils}/elasticsearch/scripts.js +14 -4
- package/dist/module/utils/elasticsearch/scripts.js.map +1 -0
- package/dist/module/utils/getMonthMaxDayAllowed.d.ts +7 -0
- package/dist/module/utils/getMonthMaxDayAllowed.js.map +1 -0
- package/dist/module/utils/getNodeValue.d.ts +2 -0
- package/dist/module/utils/getNodeValue.js.map +1 -0
- package/dist/module/utils/getVariableType.d.ts +3 -0
- package/dist/{utils → module/utils}/getVariableType.js +3 -2
- package/dist/module/utils/getVariableType.js.map +1 -0
- package/dist/module/utils/index.d.ts +10 -0
- package/dist/module/utils/index.js.map +1 -0
- package/dist/module/utils/isDateParam.d.ts +2 -0
- package/dist/module/utils/isDateParam.js.map +1 -0
- package/dist/module/utils/isNumberParam.d.ts +2 -0
- package/dist/module/utils/isNumberParam.js.map +1 -0
- package/dist/module/utils/isPositiveNumberParam.d.ts +2 -0
- package/dist/module/utils/isPositiveNumberParam.js.map +1 -0
- package/dist/module/utils/isStringParam.d.ts +2 -0
- package/dist/module/utils/isStringParam.js.map +1 -0
- package/dist/module/utils/isValidDate.d.ts +1 -0
- package/dist/module/utils/isValidDate.js.map +1 -0
- package/dist/module/utils/sql/index.d.ts +1 -0
- package/dist/module/utils/sql/index.js.map +1 -0
- package/dist/module/utils/sql/scripts.d.ts +3 -0
- package/dist/module/utils/sql/scripts.js.map +1 -0
- package/jest.config.ts +6 -0
- package/package.json +21 -6
- package/__tests__/integration/__mocks__/context.ts +0 -23
- package/__tests__/integration/__mocks__/elasticsearchScripts.ts +0 -28
- package/__tests__/integration/__mocks__/sqlScripts.ts +0 -21
- package/__tests__/integration/elasticsearch.test.ts +0 -172
- package/__tests__/integration/expression.test.ts +0 -56
- package/__tests__/integration/redshift.test.ts +0 -142
- package/__tests__/integration/sonwflake.test.ts +0 -138
- package/__tests__/unit/parser.test.ts +0 -236
- package/__tests__/unit/transpiler.test.ts +0 -128
- package/bitbucket-pipelines.yml +0 -63
- package/dist/constants/index.js.map +0 -1
- package/dist/errors/definitions.js +0 -42
- package/dist/errors/definitions.js.map +0 -1
- package/dist/errors/elasticsearch.js.map +0 -1
- package/dist/errors/engineErrors.js.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/errors/snowflake.js.map +0 -1
- package/dist/functions/abs.js.map +0 -1
- package/dist/functions/datedif.js.map +0 -1
- package/dist/functions/day.js.map +0 -1
- package/dist/functions/hour.js.map +0 -1
- package/dist/functions/if.js.map +0 -1
- package/dist/functions/ifs.js.map +0 -1
- package/dist/functions/index.js.map +0 -1
- package/dist/functions/mid.js.map +0 -1
- package/dist/functions/minute.js.map +0 -1
- package/dist/functions/month.js.map +0 -1
- package/dist/functions/second.js.map +0 -1
- package/dist/functions/year.js.map +0 -1
- package/dist/grammar/generated/qformula.lang.d.ts +0 -4
- package/dist/grammar/generated/qformula.lang.js.map +0 -1
- package/dist/grammar/qformula.grammar.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/parser/json-parser.js +0 -147
- package/dist/parser/json-parser.js.map +0 -1
- package/dist/transpiler/columnTranspilation.d.ts +0 -3
- package/dist/transpiler/columnTranspilation.js +0 -19
- package/dist/transpiler/columnTranspilation.js.map +0 -1
- package/dist/transpiler/index.js.map +0 -1
- package/dist/transpiler/validateFuncStructure.js.map +0 -1
- package/dist/utils/customFunctions.js.map +0 -1
- package/dist/utils/elasticsearch/index.js.map +0 -1
- package/dist/utils/elasticsearch/scripts.js.map +0 -1
- package/dist/utils/getMonthMaxDayAllowed.js.map +0 -1
- package/dist/utils/getNodeValue.js.map +0 -1
- package/dist/utils/getVariableType.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/isDateParam.js.map +0 -1
- package/dist/utils/isNumberParam.js.map +0 -1
- package/dist/utils/isPositiveNumberParam.js.map +0 -1
- package/dist/utils/isStringParam.js.map +0 -1
- package/dist/utils/isValidDate.js.map +0 -1
- package/dist/utils/sql/index.js.map +0 -1
- package/dist/utils/sql/scripts.js.map +0 -1
- /package/dist/{errors → cjs/errors}/elasticsearch.d.ts +0 -0
- /package/dist/{errors → cjs/errors}/engineErrors.d.ts +0 -0
- /package/dist/{errors → cjs/errors}/index.d.ts +0 -0
- /package/dist/{errors → cjs/errors}/snowflake.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/abs.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/datedif.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/day.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/hour.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/if.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/ifs.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/index.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/mid.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/minute.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/month.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/second.d.ts +0 -0
- /package/dist/{functions → cjs/functions}/year.d.ts +0 -0
- /package/dist/{grammar → cjs/grammar}/qformula.grammar.d.ts +0 -0
- /package/dist/{parser → cjs/parser}/json-parser.d.ts +0 -0
- /package/dist/{transpiler → cjs/transpiler}/validateFuncStructure.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/getMonthMaxDayAllowed.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/getNodeValue.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/getVariableType.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/index.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/isDateParam.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/isNumberParam.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/isPositiveNumberParam.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/isStringParam.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/isValidDate.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/sql/index.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/sql/scripts.d.ts +0 -0
- /package/dist/{constants → module/constants}/interfaces.js +0 -0
- /package/dist/{errors → module/errors}/elasticsearch.js +0 -0
- /package/dist/{errors → module/errors}/engineErrors.js +0 -0
- /package/dist/{errors → module/errors}/index.js +0 -0
- /package/dist/{errors → module/errors}/snowflake.js +0 -0
- /package/dist/{functions → module/functions}/abs.js +0 -0
- /package/dist/{functions → module/functions}/datedif.js +0 -0
- /package/dist/{functions → module/functions}/day.js +0 -0
- /package/dist/{functions → module/functions}/hour.js +0 -0
- /package/dist/{functions → module/functions}/if.js +0 -0
- /package/dist/{functions → module/functions}/ifs.js +0 -0
- /package/dist/{functions → module/functions}/index.js +0 -0
- /package/dist/{functions → module/functions}/mid.js +0 -0
- /package/dist/{functions → module/functions}/minute.js +0 -0
- /package/dist/{functions → module/functions}/month.js +0 -0
- /package/dist/{functions → module/functions}/second.js +0 -0
- /package/dist/{functions → module/functions}/year.js +0 -0
- /package/dist/{grammar → module/grammar}/qformula.grammar.js +0 -0
- /package/dist/{transpiler → module/transpiler}/validateFuncStructure.js +0 -0
- /package/dist/{utils → module/utils}/getMonthMaxDayAllowed.js +0 -0
- /package/dist/{utils → module/utils}/getNodeValue.js +0 -0
- /package/dist/{utils → module/utils}/index.js +0 -0
- /package/dist/{utils → module/utils}/isDateParam.js +0 -0
- /package/dist/{utils → module/utils}/isNumberParam.js +0 -0
- /package/dist/{utils → module/utils}/isPositiveNumberParam.js +0 -0
- /package/dist/{utils → module/utils}/isStringParam.js +0 -0
- /package/dist/{utils → module/utils}/isValidDate.js +0 -0
- /package/dist/{utils → module/utils}/sql/index.js +0 -0
- /package/dist/{utils → module/utils}/sql/scripts.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isStringParam.js","sourceRoot":"","sources":["../../../src/utils/isStringParam.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG5D,MAAM,UAAU,aAAa,CAAC,KAAU;IACpC,MAAM,KAAK,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC;IACxC,IAAI,CAAC,KAAK;QAAE,uBAAS,KAAK,IAAK,gBAAgB,CAAC,UAAU,CAAC,aAAa,CAAC,EAAG;IAC5E,OAAO,EAAE,KAAK,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValidDate(d: unknown): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidDate.js","sourceRoot":"","sources":["../../../src/utils/isValidDate.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,CAAU;IAClC,OAAO,CAAC,KAAK,CAAC,CAAW,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { toDate } from './scripts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/sql/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../../src/utils/sql/scripts.ts"],"names":[],"mappings":"AAEA,SAAS,QAAQ,CAAC,KAAa,EAAE,MAAc;IAC3C,OAAO,cAAc,MAAM,MAAM,KAAK,GAAG,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAa;IAChC,OAAO,SAAS,KAAK,mBAAmB,CAAC;AAC7C,CAAC;AAED,SAAS,cAAc,CAAC,KAAa,EAAE,GAAW,EAAE,IAAsB;IACtE,MAAM,KAAK,GAAG;QACV,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,KAAK;KACX,CAAC;IACF,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,aAAa,WAAW,MAAM,KAAK,KAAK,GAAG,GAAG,CAAC;AAC1D,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa,EAAE,GAAW;IACjD,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,gBAAgB,GAAG,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG;eACJ,gBAAgB;mBACZ,WAAW;eACf,WAAW;QAClB,CAAC;IACL,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,GAAW,EAAE,IAAsB;IACtE,MAAM,KAAK,GAAG;QACV,CAAC,EAAE,iBAAiB;QACpB,CAAC,EAAE,cAAc;QACjB,CAAC,EAAE,cAAc;KACpB,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC"}
|
package/jest.config.ts
ADDED
package/package.json
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qrvey/formula-lang",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "QFormula support for qrvey projects",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
5
|
+
"types": "dist/module/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/module/index.js",
|
|
9
|
+
"require": "./dist/cjs/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
8
12
|
"scripts": {
|
|
9
13
|
"test": "jest __tests__",
|
|
10
14
|
"test:coverage": "jest __tests__ --collect-coverage",
|
|
11
|
-
"build": "tsc",
|
|
15
|
+
"build": "tsc && tsc -m commonjs --outDir dist/cjs",
|
|
12
16
|
"build:watch": "tsc -w",
|
|
17
|
+
"debug:bundle": "webpack",
|
|
18
|
+
"debug:watch": "webpack --watch",
|
|
19
|
+
"debug:serve": "cd dist && live-server --port=3553 --open=/",
|
|
20
|
+
"debug:local": "npm-run-all --parallel debug:watch debug:serve",
|
|
21
|
+
"debug:copy-index": "mkdir -p dist && cp src/index.html dist/",
|
|
13
22
|
"prepublishOnly": "npm run build",
|
|
23
|
+
"start": "npm run debug:copy-index && npm run debug:bundle && npm run debug:local",
|
|
14
24
|
"cm": "cz",
|
|
15
25
|
"prepare-lang": "rollup -c --bundleConfigAsCjs",
|
|
16
26
|
"corp-release": "corp-semantic-release -v --branch release/publish",
|
|
@@ -52,12 +62,17 @@
|
|
|
52
62
|
"husky": "^8.0.3",
|
|
53
63
|
"jest": "^29.5.0",
|
|
54
64
|
"lint-staged": "^13.2.1",
|
|
65
|
+
"live-server": "^1.2.2",
|
|
66
|
+
"npm-run-all": "^4.1.5",
|
|
55
67
|
"prettier": "^2.8.7",
|
|
56
68
|
"rollup": "^3.20.2",
|
|
57
69
|
"rollup-plugin-dts": "^5.3.0",
|
|
58
70
|
"rollup-plugin-ts": "^3.2.0",
|
|
59
71
|
"ts-jest": "^29.1.0",
|
|
60
|
-
"
|
|
72
|
+
"ts-loader": "^9.4.2",
|
|
73
|
+
"typescript": "~4.9.5",
|
|
74
|
+
"webpack": "^5.80.0",
|
|
75
|
+
"webpack-cli": "^5.0.2"
|
|
61
76
|
},
|
|
62
77
|
"config": {
|
|
63
78
|
"commitizen": {
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { FormulaContext } from '../../../src/constants/interfaces';
|
|
2
|
-
|
|
3
|
-
export const basicContext: FormulaContext = {
|
|
4
|
-
model: [
|
|
5
|
-
{
|
|
6
|
-
id: 'ID123.test',
|
|
7
|
-
label: 'Column String',
|
|
8
|
-
column: 'Origin_String_Column_Test',
|
|
9
|
-
type: 'string',
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
id: 'DateID1',
|
|
13
|
-
label: 'Column Date',
|
|
14
|
-
column: 'Origin_Date_Column_Test',
|
|
15
|
-
type: 'date',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: 'NOW',
|
|
19
|
-
label: 'NOW',
|
|
20
|
-
type: 'string',
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const dateFormatScript = `String DATE_FORMAT_SCRIPT(def date_value, String format) {
|
|
2
|
-
def isCustomDate = (date_value instanceof JodaCompatibleZonedDateTime || date_value instanceof ZonedDateTime);
|
|
3
|
-
if (date_value instanceof List && !isCustomDate) {
|
|
4
|
-
if (date_value.empty) return null;
|
|
5
|
-
date_value = date_value.value;
|
|
6
|
-
}
|
|
7
|
-
return DateTimeFormatter.ofPattern(format).format(date_value)
|
|
8
|
-
}`;
|
|
9
|
-
|
|
10
|
-
export function dateFormatToInt(
|
|
11
|
-
format: string,
|
|
12
|
-
column: string | undefined = undefined,
|
|
13
|
-
): string {
|
|
14
|
-
if (!column) column = `ZonedDateTime.parse("2023-12-31T00:00:00.000Z")`;
|
|
15
|
-
return `Integer.parseInt(DATE_FORMAT_SCRIPT(${column}, '${format}'))`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function dateParser(
|
|
19
|
-
format: string,
|
|
20
|
-
column: string | undefined = undefined,
|
|
21
|
-
): string {
|
|
22
|
-
const dateToInt = dateFormatToInt(format, column);
|
|
23
|
-
return `${dateFormatScript}\n${dateToInt}`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function dateDif(format: string) {
|
|
27
|
-
return `ChronoUnit.${format}.between(ZonedDateTime.parse("2023-12-31T00:00:00.000Z"), ZonedDateTime.parse("2022-12-31T00:00:00.000Z"))`;
|
|
28
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export function datePart(part: string, column: string | undefined = undefined) {
|
|
2
|
-
if (!column) column = `CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ)`;
|
|
3
|
-
return `DATE_PART('${part}', ${column})`;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function dateDif(unit: string): string {
|
|
7
|
-
switch (unit) {
|
|
8
|
-
case 'day':
|
|
9
|
-
case 'month':
|
|
10
|
-
return `DATEDIFF('${unit}', CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ), CAST('2022-12-31T00:00:00.000Z' AS TIMESTAMPTZ))`;
|
|
11
|
-
case 'year':
|
|
12
|
-
return `CASE
|
|
13
|
-
WHEN DATEDIFF('day', CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ), CAST('DATE_PART('CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ)', year)|| '-' ||DATE_PART('CAST('2022-12-31T00:00:00.000Z' AS TIMESTAMPTZ)', month)|| '-' ||DATE_PART('CAST('2022-12-31T00:00:00.000Z' AS TIMESTAMPTZ)', day)' AS TIMESTAMPTZ)) >= 0
|
|
14
|
-
THEN DATEDIFF('${unit}', CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ), CAST('2022-12-31T00:00:00.000Z' AS TIMESTAMPTZ))
|
|
15
|
-
ELSE DATEDIFF('${unit}', CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ), CAST('2022-12-31T00:00:00.000Z' AS TIMESTAMPTZ)) - 1
|
|
16
|
-
END`; //Indentation care, be careful
|
|
17
|
-
|
|
18
|
-
default:
|
|
19
|
-
return '';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { ENGINES, Transpile } from '../../src';
|
|
2
|
-
import {
|
|
3
|
-
dateDif,
|
|
4
|
-
dateParser,
|
|
5
|
-
dateFormatToInt,
|
|
6
|
-
dateFormatScript,
|
|
7
|
-
} from './__mocks__/elasticsearchScripts';
|
|
8
|
-
import { basicContext } from './__mocks__/context';
|
|
9
|
-
const currentEngine = ENGINES.ELASTICSEARCH;
|
|
10
|
-
|
|
11
|
-
describe('ELASTICSEARCH Transpile program', () => {
|
|
12
|
-
test('Basic case', () => {
|
|
13
|
-
const result = Transpile('1 + 2', currentEngine);
|
|
14
|
-
expect(result?.expression).toBe('(1 + 2)');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('MID function', () => {
|
|
18
|
-
const result = Transpile('MID("test", 1, 5)', currentEngine);
|
|
19
|
-
expect(result?.expression).toBe(`'test'.substring(1, 5)`);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('Should transpile a function inside another function', () => {
|
|
23
|
-
const program = 'MID(MID("This is a test", 1, 5), 1, 2)';
|
|
24
|
-
const result = Transpile(program, currentEngine);
|
|
25
|
-
expect(result?.valid).toBe(true);
|
|
26
|
-
expect(result?.expression).toBe(
|
|
27
|
-
"'This is a test'.substring(1, 5).substring(1, 2)",
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('ABS function', () => {
|
|
32
|
-
const result = Transpile('ABS(5)', currentEngine);
|
|
33
|
-
expect(result?.expression).toBe(`Math.abs(5)`);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('Cast Date string', () => {
|
|
37
|
-
const result = Transpile('"12/31/2022 13:35:45"', currentEngine);
|
|
38
|
-
expect(result?.expression).toBe(
|
|
39
|
-
`ZonedDateTime.parse("2022-12-31T13:35:45.000Z")`,
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('DAY function', () => {
|
|
44
|
-
const result = Transpile('DAY("12/31/2023")', currentEngine);
|
|
45
|
-
const mock = dateParser('dd').replace(/\n/g, '');
|
|
46
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('Two DAY function', () => {
|
|
50
|
-
const result = Transpile(
|
|
51
|
-
'DAY("12/31/2023") + DAY("12/31/2023")',
|
|
52
|
-
currentEngine,
|
|
53
|
-
);
|
|
54
|
-
const ddToInt = dateFormatToInt('dd');
|
|
55
|
-
const concat = `${dateFormatScript}\n(${ddToInt} + ${ddToInt})`;
|
|
56
|
-
const mock = concat.replace(/\n/g, '');
|
|
57
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('DAY function with a variable Column', () => {
|
|
61
|
-
const result = Transpile('DAY([DateID1])', currentEngine, basicContext);
|
|
62
|
-
const column = 'doc["Origin_Date_Column_Test"]';
|
|
63
|
-
const mock = dateParser('dd', column).replace(/\n/g, '');
|
|
64
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('MONTH function', () => {
|
|
68
|
-
const result = Transpile('MONTH("12/31/2023")', currentEngine);
|
|
69
|
-
const mock = dateParser('MM').replace(/\n/g, '');
|
|
70
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('One DAY plus One Month function', () => {
|
|
74
|
-
const result = Transpile(
|
|
75
|
-
'DAY("12/31/2023") + MONTH("12/31/2023")',
|
|
76
|
-
currentEngine,
|
|
77
|
-
);
|
|
78
|
-
const concat = `${dateFormatScript}\n(${dateFormatToInt(
|
|
79
|
-
'dd',
|
|
80
|
-
)} + ${dateFormatToInt('MM')})`;
|
|
81
|
-
const mock = concat.replace(/\n/g, '');
|
|
82
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('YEAR function', () => {
|
|
86
|
-
const result = Transpile('YEAR("12/31/2023")', currentEngine);
|
|
87
|
-
const mock = dateParser('yyyy').replace(/\n/g, '');
|
|
88
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('HOUR function', () => {
|
|
92
|
-
const result = Transpile('HOUR("12/31/2023")', currentEngine);
|
|
93
|
-
const mock = dateParser('HH').replace(/\n/g, '');
|
|
94
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('MINUTE function', () => {
|
|
98
|
-
const result = Transpile('MINUTE("12/31/2023")', currentEngine);
|
|
99
|
-
const mock = dateParser('mm').replace(/\n/g, '');
|
|
100
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('SECOND function', () => {
|
|
104
|
-
const result = Transpile('SECOND("12/31/2023")', currentEngine);
|
|
105
|
-
const mock = dateParser('ss').replace(/\n/g, '');
|
|
106
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('DATEDIF function with Y unit', () => {
|
|
110
|
-
const result = Transpile(
|
|
111
|
-
'DATEDIF("12/31/2023", "12/31/2022", "Y")',
|
|
112
|
-
currentEngine,
|
|
113
|
-
);
|
|
114
|
-
const mock = dateDif('YEARS');
|
|
115
|
-
expect(result?.expression).toBe(mock);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test('DATEDIF function with M unit', () => {
|
|
119
|
-
const result = Transpile(
|
|
120
|
-
'DATEDIF("12/31/2023", "12/31/2022", "M")',
|
|
121
|
-
currentEngine,
|
|
122
|
-
);
|
|
123
|
-
const mock = dateDif('MONTHS');
|
|
124
|
-
expect(result?.expression).toBe(mock);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('DATEDIF function with D unit', () => {
|
|
128
|
-
const result = Transpile(
|
|
129
|
-
'DATEDIF("12/31/2023", "12/31/2022", "D")',
|
|
130
|
-
currentEngine,
|
|
131
|
-
);
|
|
132
|
-
const mock = dateDif('DAYS');
|
|
133
|
-
expect(result?.expression).toBe(mock);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test('DATEDIF function with a not valid Unit', () => {
|
|
137
|
-
const result = Transpile(
|
|
138
|
-
'DATEDIF("12/31/2023", "12/31/2022", "X")',
|
|
139
|
-
currentEngine,
|
|
140
|
-
);
|
|
141
|
-
expect(result).not.toBeUndefined();
|
|
142
|
-
expect(result?.valid).toBe(false);
|
|
143
|
-
expect(result?.error).not.toBeUndefined();
|
|
144
|
-
expect(result?.error?.code).toBe('DATE_DIF_UNIT_PARAM');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('IF function full parameters', () => {
|
|
148
|
-
const result = Transpile('IF(5 = 1, "True", "False")', currentEngine);
|
|
149
|
-
expect(result).not.toBeUndefined();
|
|
150
|
-
expect(result?.error).toBeUndefined();
|
|
151
|
-
expect(result?.expression).toBe(`((5 == 1) ? 'True' : 'False')`);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test('IF function basic parameters', () => {
|
|
155
|
-
const result = Transpile('IF(5 = 1, "True")', currentEngine);
|
|
156
|
-
expect(result).not.toBeUndefined();
|
|
157
|
-
expect(result?.error).toBeUndefined();
|
|
158
|
-
expect(result?.expression).toBe(`((5 == 1) ? 'True' : false)`);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test('IFS function basic parameters', () => {
|
|
162
|
-
const result = Transpile(
|
|
163
|
-
'IFS(5>10, "Greater than 10", 5>5, "Greater than 5",5>0, "Greater than 0")',
|
|
164
|
-
currentEngine,
|
|
165
|
-
);
|
|
166
|
-
expect(result).not.toBeUndefined();
|
|
167
|
-
expect(result?.error).toBeUndefined();
|
|
168
|
-
expect(result?.expression).toBe(
|
|
169
|
-
`((5 > 10) ? 'Greater than 10' : ((5 > 5) ? 'Greater than 5' : ((5 > 0) ? 'Greater than 0' : null)))`,
|
|
170
|
-
);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { ENGINES, Transpile } from '../../src';
|
|
2
|
-
import { MissingArgumentError } from '../../src/errors';
|
|
3
|
-
|
|
4
|
-
describe('Raw Expression test suite', () => {
|
|
5
|
-
test('should transpile a logical operator', () => {
|
|
6
|
-
const program = '1 < 2';
|
|
7
|
-
const result = Transpile(program, ENGINES.ELASTICSEARCH);
|
|
8
|
-
expect(result?.valid).toBe(true);
|
|
9
|
-
expect(result?.expression).toBe('(1 < 2)');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('IFS function should not work (invalid parameters)', () => {
|
|
13
|
-
const result = Transpile(
|
|
14
|
-
'IFS(5>10, "Greater than 10", 5>5, "Greater than 5",5>0)',
|
|
15
|
-
ENGINES.ELASTICSEARCH,
|
|
16
|
-
);
|
|
17
|
-
expect(result).not.toBeUndefined();
|
|
18
|
-
expect(result?.valid).toBe(false);
|
|
19
|
-
expect(result?.error).not.toBeUndefined();
|
|
20
|
-
expect(result?.error instanceof MissingArgumentError).toBeTruthy();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('Should transpile a column', () => {
|
|
24
|
-
const program = '[8db21fc4]';
|
|
25
|
-
const columnName = 'Origin_Column_Test';
|
|
26
|
-
const result = Transpile(program, ENGINES.ELASTICSEARCH, {
|
|
27
|
-
model: [
|
|
28
|
-
{
|
|
29
|
-
label: 'Text',
|
|
30
|
-
id: '8db21fc4',
|
|
31
|
-
column: columnName,
|
|
32
|
-
type: 'string',
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
});
|
|
36
|
-
expect(result?.valid).toBe(true);
|
|
37
|
-
expect(result?.expression).toBe(`doc["${columnName}"]`);
|
|
38
|
-
});
|
|
39
|
-
/*
|
|
40
|
-
test('Should transpile a column with property', () => {
|
|
41
|
-
const program = '[8db21fc4.country]';
|
|
42
|
-
const columnName = 'Origin_Column_Test';
|
|
43
|
-
const result = Transpile(program, ENGINES.ELASTICSEARCH, {
|
|
44
|
-
model: [
|
|
45
|
-
{
|
|
46
|
-
label: 'Text',
|
|
47
|
-
id: '8db21fc4',
|
|
48
|
-
column: columnName,
|
|
49
|
-
type: 'string',
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
});
|
|
53
|
-
expect(result?.valid).toBe(true);
|
|
54
|
-
expect(result?.expression).toBe(`doc["${columnName}"]`);
|
|
55
|
-
});*/
|
|
56
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { ENGINES, Transpile } from '../../src';
|
|
2
|
-
import { datePart, dateDif } from './__mocks__/sqlScripts';
|
|
3
|
-
import { basicContext } from './__mocks__/context';
|
|
4
|
-
const currentEngine = ENGINES.REDSHIFT;
|
|
5
|
-
|
|
6
|
-
describe('SNOWFLAKE Transpile program', () => {
|
|
7
|
-
test('Basic case', () => {
|
|
8
|
-
const result = Transpile('1 + 2', currentEngine);
|
|
9
|
-
expect(result?.expression).toBe('(1 + 2)');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('MID function', () => {
|
|
13
|
-
const result = Transpile('MID("test", 1, 5)', currentEngine);
|
|
14
|
-
expect(result?.expression).toBe(`SUBSTRING('test', 1, 5)`);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('Should transpile a function inside another function', () => {
|
|
18
|
-
const program = 'MID(MID("This is a test", 1, 5), 1, 2)';
|
|
19
|
-
const result = Transpile(program, currentEngine);
|
|
20
|
-
expect(result?.valid).toBe(true);
|
|
21
|
-
expect(result?.expression).toBe(
|
|
22
|
-
"SUBSTRING(SUBSTRING('This is a test', 1, 5), 1, 2)",
|
|
23
|
-
);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('ABS function', () => {
|
|
27
|
-
const result = Transpile('ABS(5)', currentEngine);
|
|
28
|
-
expect(result?.expression).toBe(`ABS(5)`);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('Cast Date string', () => {
|
|
32
|
-
const result = Transpile('"12/31/2022 13:35:45"', currentEngine);
|
|
33
|
-
expect(result?.expression).toBe(
|
|
34
|
-
`CAST('2022-12-31T13:35:45.000Z' AS TIMESTAMPTZ)`,
|
|
35
|
-
);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('DAY function', () => {
|
|
39
|
-
const result = Transpile('DAY("12/31/2023")', currentEngine);
|
|
40
|
-
expect(result?.expression).toBe(datePart('day'));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('DAY function with a variable Column', () => {
|
|
44
|
-
const result = Transpile('DAY([DateID1])', currentEngine, basicContext);
|
|
45
|
-
const column = '"Origin_Date_Column_Test"';
|
|
46
|
-
const mock = datePart('day', column).replace(/\n/g, '');
|
|
47
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('MONTH function', () => {
|
|
51
|
-
const result = Transpile('MONTH("12/31/2023")', currentEngine);
|
|
52
|
-
expect(result?.expression).toBe(datePart('month'));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('YEAR function', () => {
|
|
56
|
-
const result = Transpile('YEAR("12/31/2023")', currentEngine);
|
|
57
|
-
expect(result?.expression).toBe(datePart('year'));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('HOUR function', () => {
|
|
61
|
-
const result = Transpile('HOUR("12/31/2023")', currentEngine);
|
|
62
|
-
expect(result?.expression).toBe(datePart('hour'));
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('MINUTE function', () => {
|
|
66
|
-
const result = Transpile('MINUTE("12/31/2023")', currentEngine);
|
|
67
|
-
expect(result?.expression).toBe(datePart('minute'));
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('SECOND function', () => {
|
|
71
|
-
const result = Transpile('SECOND("12/31/2023")', currentEngine);
|
|
72
|
-
expect(result?.expression).toBe(datePart('second'));
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('DATEDIF function with Y unit', () => {
|
|
76
|
-
const result = Transpile(
|
|
77
|
-
'DATEDIF("12/31/2023", "12/31/2022", "Y")',
|
|
78
|
-
currentEngine,
|
|
79
|
-
);
|
|
80
|
-
const mock = dateDif('year');
|
|
81
|
-
expect(result?.expression).toBe(mock);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('DATEDIF function with M unit', () => {
|
|
85
|
-
const result = Transpile(
|
|
86
|
-
'DATEDIF("12/31/2023", "12/31/2022", "M")',
|
|
87
|
-
currentEngine,
|
|
88
|
-
);
|
|
89
|
-
const mock = dateDif('month');
|
|
90
|
-
expect(result?.expression).toBe(mock);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('DATEDIF function with D unit', () => {
|
|
94
|
-
const result = Transpile(
|
|
95
|
-
'DATEDIF("12/31/2023", "12/31/2022", "D")',
|
|
96
|
-
currentEngine,
|
|
97
|
-
);
|
|
98
|
-
const mock = dateDif('day');
|
|
99
|
-
expect(result?.expression).toBe(mock);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test('DATEDIF function with a not valid Unit', () => {
|
|
103
|
-
const result = Transpile(
|
|
104
|
-
'DATEDIF("12/31/2023", "12/31/2022", "X")',
|
|
105
|
-
currentEngine,
|
|
106
|
-
);
|
|
107
|
-
expect(result).not.toBeUndefined();
|
|
108
|
-
expect(result?.valid).toBe(false);
|
|
109
|
-
expect(result?.error).not.toBeUndefined();
|
|
110
|
-
expect(result?.error?.code).toBe('DATE_DIF_UNIT_PARAM');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('IF function full parameters', () => {
|
|
114
|
-
const result = Transpile('IF(5 = 1, "True", "False")', currentEngine);
|
|
115
|
-
expect(result).not.toBeUndefined();
|
|
116
|
-
expect(result?.error).toBeUndefined();
|
|
117
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(
|
|
118
|
-
`(CASE WHEN (5 = 1) THEN 'True' ELSE 'False'END)`,
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('IF function basic parameters', () => {
|
|
123
|
-
const result = Transpile('IF(5 = 1, "True")', currentEngine);
|
|
124
|
-
expect(result).not.toBeUndefined();
|
|
125
|
-
expect(result?.error).toBeUndefined();
|
|
126
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(
|
|
127
|
-
`(CASE WHEN (5 = 1) THEN 'True' ELSE FALSEEND)`,
|
|
128
|
-
);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('IFS function basic parameters', () => {
|
|
132
|
-
const result = Transpile(
|
|
133
|
-
'IFS(5>10, "Greater than 10", 5>5, "Greater than 5",5>0, "Greater than 0")',
|
|
134
|
-
currentEngine,
|
|
135
|
-
);
|
|
136
|
-
expect(result).not.toBeUndefined();
|
|
137
|
-
expect(result?.error).toBeUndefined();
|
|
138
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(
|
|
139
|
-
`(CASE WHEN (5 > 10) THEN 'Greater than 10' ELSE (CASE WHEN (5 > 5) THEN 'Greater than 5' ELSE (CASE WHEN (5 > 0) THEN 'Greater than 0' ELSE NULL END) END) END)`,
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
});
|