@qrvey/formula-lang 0.3.1 → 0.5.0
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 +23 -0
- package/dist/bundle.js +23152 -0
- package/dist/cjs/constants/index.d.ts +53 -0
- package/dist/cjs/constants/index.js +117 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/constants/interfaces.d.ts +91 -0
- package/dist/cjs/constants/interfaces.js +3 -0
- package/dist/cjs/constants/interfaces.js.map +1 -0
- package/dist/cjs/errors/definitions.d.ts +43 -0
- package/dist/cjs/errors/definitions.js +91 -0
- package/dist/cjs/errors/definitions.js.map +1 -0
- package/dist/cjs/errors/elasticsearch.d.ts +24 -0
- package/dist/cjs/errors/elasticsearch.js +30 -0
- package/dist/cjs/errors/elasticsearch.js.map +1 -0
- package/dist/cjs/errors/engineErrors.d.ts +2 -0
- package/dist/cjs/errors/engineErrors.js +25 -0
- package/dist/cjs/errors/engineErrors.js.map +1 -0
- package/dist/cjs/errors/index.d.ts +2 -0
- package/dist/cjs/errors/index.js +21 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/errors/snowflake.d.ts +15 -0
- package/dist/cjs/errors/snowflake.js +20 -0
- package/dist/cjs/errors/snowflake.js.map +1 -0
- package/dist/cjs/functions/abs.d.ts +5 -0
- package/dist/cjs/functions/abs.js +38 -0
- package/dist/cjs/functions/abs.js.map +1 -0
- package/dist/cjs/functions/datedif.d.ts +5 -0
- package/dist/cjs/functions/datedif.js +64 -0
- package/dist/cjs/functions/datedif.js.map +1 -0
- package/dist/cjs/functions/day.d.ts +5 -0
- package/dist/cjs/functions/day.js +39 -0
- package/dist/cjs/functions/day.js.map +1 -0
- package/dist/cjs/functions/hour.d.ts +5 -0
- package/dist/cjs/functions/hour.js +39 -0
- package/dist/cjs/functions/hour.js.map +1 -0
- package/dist/cjs/functions/if.d.ts +5 -0
- package/dist/cjs/functions/if.js +52 -0
- package/dist/cjs/functions/if.js.map +1 -0
- package/dist/cjs/functions/ifs.d.ts +5 -0
- package/dist/cjs/functions/ifs.js +74 -0
- package/dist/cjs/functions/ifs.js.map +1 -0
- package/dist/cjs/functions/index.d.ts +4 -0
- package/dist/cjs/functions/index.js +33 -0
- package/dist/cjs/functions/index.js.map +1 -0
- package/dist/cjs/functions/mid.d.ts +5 -0
- package/dist/cjs/functions/mid.js +54 -0
- package/dist/cjs/functions/mid.js.map +1 -0
- package/dist/cjs/functions/minute.d.ts +5 -0
- package/dist/cjs/functions/minute.js +39 -0
- package/dist/cjs/functions/minute.js.map +1 -0
- package/dist/cjs/functions/month.d.ts +5 -0
- package/dist/cjs/functions/month.js +39 -0
- package/dist/cjs/functions/month.js.map +1 -0
- package/dist/cjs/functions/second.d.ts +5 -0
- package/dist/cjs/functions/second.js +39 -0
- package/dist/cjs/functions/second.js.map +1 -0
- package/dist/cjs/functions/year.d.ts +5 -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.d.ts +1 -0
- package/dist/cjs/grammar/qformula.grammar.js +18 -0
- package/dist/cjs/grammar/qformula.grammar.js.map +1 -0
- package/dist/cjs/index.d.ts +10 -0
- 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.d.ts +3 -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/cjs/transpiler/index.d.ts +18 -0
- 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.d.ts +2 -0
- package/dist/cjs/transpiler/validateFuncStructure.js +41 -0
- package/dist/cjs/transpiler/validateFuncStructure.js.map +1 -0
- package/dist/cjs/utils/customFunctions.d.ts +4 -0
- package/dist/cjs/utils/customFunctions.js +35 -0
- package/dist/cjs/utils/customFunctions.js.map +1 -0
- package/dist/cjs/utils/elasticsearch/index.d.ts +2 -0
- package/dist/cjs/utils/elasticsearch/index.js +22 -0
- package/dist/cjs/utils/elasticsearch/index.js.map +1 -0
- package/dist/cjs/utils/elasticsearch/scripts.d.ts +11 -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.d.ts +7 -0
- package/dist/cjs/utils/getMonthMaxDayAllowed.js +26 -0
- package/dist/cjs/utils/getMonthMaxDayAllowed.js.map +1 -0
- package/dist/cjs/utils/getNodeValue.d.ts +2 -0
- package/dist/cjs/utils/getNodeValue.js +13 -0
- package/dist/cjs/utils/getNodeValue.js.map +1 -0
- package/dist/cjs/utils/getVariableType.d.ts +3 -0
- package/dist/cjs/utils/getVariableType.js +19 -0
- package/dist/cjs/utils/getVariableType.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +10 -0
- package/dist/cjs/utils/index.js +29 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/isDateParam.d.ts +2 -0
- package/dist/cjs/utils/isDateParam.js +12 -0
- package/dist/cjs/utils/isDateParam.js.map +1 -0
- package/dist/cjs/utils/isNumberParam.d.ts +2 -0
- package/dist/cjs/utils/isNumberParam.js +12 -0
- package/dist/cjs/utils/isNumberParam.js.map +1 -0
- package/dist/cjs/utils/isPositiveNumberParam.d.ts +2 -0
- package/dist/cjs/utils/isPositiveNumberParam.js +12 -0
- package/dist/cjs/utils/isPositiveNumberParam.js.map +1 -0
- package/dist/cjs/utils/isStringParam.d.ts +2 -0
- package/dist/cjs/utils/isStringParam.js +12 -0
- package/dist/cjs/utils/isStringParam.js.map +1 -0
- package/dist/cjs/utils/isValidDate.d.ts +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.d.ts +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.d.ts +3 -0
- package/dist/cjs/utils/sql/scripts.js +44 -0
- package/dist/cjs/utils/sql/scripts.js.map +1 -0
- package/dist/constants/index.d.ts +11 -2
- package/dist/constants/index.js +11 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/interfaces.d.ts +21 -11
- package/dist/errors/definitions.d.ts +20 -3
- package/dist/errors/definitions.js +20 -2
- package/dist/errors/definitions.js.map +1 -1
- package/dist/grammar/generated/qformula.lang.d.ts +9 -0
- package/dist/grammar/generated/qformula.lang.js +5 -4
- package/dist/grammar/generated/qformula.lang.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.html +21 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +1 -0
- package/dist/main.js +65 -0
- package/dist/main.js.map +1 -0
- package/dist/module/constants/index.d.ts +53 -0
- package/dist/module/constants/index.js +114 -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 +2 -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 +27 -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 +21 -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 +5 -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 +17 -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 +35 -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 +61 -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 +36 -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 +36 -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 +49 -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 +71 -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 +29 -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 +51 -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 +36 -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 +36 -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 +36 -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 +36 -0
- package/dist/module/functions/year.js.map +1 -0
- package/dist/module/grammar/generated/qformula.lang.d.ts +13 -0
- package/dist/module/grammar/generated/qformula.lang.js +45 -0
- 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 +2 -0
- package/dist/module/grammar/qformula.grammar.js.map +1 -0
- package/dist/module/index.d.ts +10 -0
- package/dist/module/index.js +20 -0
- 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/module/transpiler/index.js +102 -0
- 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 +37 -0
- package/dist/module/transpiler/validateFuncStructure.js.map +1 -0
- package/dist/module/utils/customFunctions.d.ts +4 -0
- package/dist/module/utils/customFunctions.js +29 -0
- package/dist/module/utils/customFunctions.js.map +1 -0
- package/dist/module/utils/elasticsearch/index.d.ts +2 -0
- package/dist/module/utils/elasticsearch/index.js +16 -0
- package/dist/module/utils/elasticsearch/index.js.map +1 -0
- package/dist/module/utils/elasticsearch/scripts.d.ts +11 -0
- package/dist/module/utils/elasticsearch/scripts.js +46 -0
- 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 +22 -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 +9 -0
- package/dist/module/utils/getNodeValue.js.map +1 -0
- package/dist/module/utils/getVariableType.d.ts +3 -0
- package/dist/module/utils/getVariableType.js +14 -0
- package/dist/module/utils/getVariableType.js.map +1 -0
- package/dist/module/utils/index.d.ts +10 -0
- package/dist/module/utils/index.js +11 -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 +8 -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 +8 -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 +8 -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 +8 -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 +4 -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 +2 -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 +39 -0
- package/dist/module/utils/sql/scripts.js.map +1 -0
- package/dist/parser/json-parser.js +26 -15
- package/dist/parser/json-parser.js.map +1 -1
- package/dist/parser/syntax-errors.d.ts +3 -0
- package/dist/parser/syntax-errors.js +20 -0
- package/dist/parser/syntax-errors.js.map +1 -0
- package/dist/transpiler/columnTranspilation.d.ts +3 -0
- package/dist/transpiler/columnTranspilation.js +25 -0
- package/dist/transpiler/columnTranspilation.js.map +1 -0
- package/dist/transpiler/index.d.ts +6 -5
- package/dist/transpiler/index.js +33 -20
- package/dist/transpiler/index.js.map +1 -1
- package/dist/transpiler/unshiftCustomFunctions.d.ts +2 -0
- package/dist/transpiler/unshiftCustomFunctions.js +10 -0
- package/dist/transpiler/unshiftCustomFunctions.js.map +1 -0
- package/dist/utils/customFunctions.d.ts +1 -0
- package/dist/utils/customFunctions.js +10 -2
- package/dist/utils/customFunctions.js.map +1 -1
- package/dist/utils/elasticsearch/index.d.ts +1 -1
- package/dist/utils/elasticsearch/index.js +1 -1
- package/dist/utils/elasticsearch/index.js.map +1 -1
- package/dist/utils/elasticsearch/scripts.d.ts +1 -0
- package/dist/utils/elasticsearch/scripts.js +14 -4
- package/dist/utils/elasticsearch/scripts.js.map +1 -1
- package/dist/utils/getVariableType.d.ts +3 -3
- package/dist/utils/getVariableType.js.map +1 -1
- package/jest.config.ts +6 -0
- package/package.json +21 -6
- package/__tests__/integration/__mocks__/elasticsearchScripts.ts +0 -21
- package/__tests__/integration/__mocks__/sqlScripts.ts +0 -20
- package/__tests__/integration/elasticsearch.test.ts +0 -158
- package/__tests__/integration/expression.test.ts +0 -22
- package/__tests__/integration/redshift.test.ts +0 -127
- package/__tests__/integration/sonwflake.test.ts +0 -123
- package/__tests__/unit/parser.test.ts +0 -236
- package/__tests__/unit/transpiler.test.ts +0 -128
- package/bitbucket-pipelines.yml +0 -63
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ENGINES } from '../constants';
|
|
2
|
-
import { customFunctionsList as
|
|
2
|
+
import { customFunctionsList as customFunctionsES, toDate as toDateES, setTimezoneToColumnDate as timezoneES, } from './elasticsearch';
|
|
3
3
|
import { toDate as toDateSQL } from './sql';
|
|
4
4
|
export function customFunction(engine, func) {
|
|
5
5
|
switch (engine) {
|
|
6
6
|
case ENGINES.ELASTICSEARCH:
|
|
7
|
-
return
|
|
7
|
+
return customFunctionsES(func);
|
|
8
8
|
default:
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
@@ -18,4 +18,12 @@ export function customDateCast(engine) {
|
|
|
18
18
|
return toDateSQL;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
export function customTimezone(engine) {
|
|
22
|
+
switch (engine) {
|
|
23
|
+
case ENGINES.ELASTICSEARCH:
|
|
24
|
+
return timezoneES;
|
|
25
|
+
default:
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
21
29
|
//# sourceMappingURL=customFunctions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customFunctions.js","sourceRoot":"","sources":["../../src/utils/customFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACH,mBAAmB,IAAI,
|
|
1
|
+
{"version":3,"file":"customFunctions.js","sourceRoot":"","sources":["../../src/utils/customFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACH,mBAAmB,IAAI,iBAAiB,EACxC,MAAM,IAAI,QAAQ,EAClB,uBAAuB,IAAI,UAAU,GACxC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,UAAU,cAAc,CAAC,MAAe,EAAE,IAAY;IACxD,QAAQ,MAAM,EAAE;QACZ,KAAK,OAAO,CAAC,aAAa;YACtB,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACnC;YACI,OAAO,KAAK,CAAC;KACpB;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAe;IAC1C,QAAQ,MAAM,EAAE;QACZ,KAAK,OAAO,CAAC,aAAa;YACtB,OAAO,QAAQ,CAAC;QACpB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,SAAS;YAClB,OAAO,SAAS,CAAC;KACxB;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAe;IAC1C,QAAQ,MAAM,EAAE;QACZ,KAAK,OAAO,CAAC,aAAa;YACtB,OAAO,UAAU,CAAC;QACtB;YACI,OAAO,KAAK,CAAC;KACpB;AACL,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { toDate } from './scripts';
|
|
1
|
+
export { toDate, setTimezoneToColumnDate } from './scripts';
|
|
2
2
|
export declare function customFunctionsList(func: string): string | false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/elasticsearch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/elasticsearch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAE5D,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC5C,QAAQ,IAAI,EAAE;QACV,KAAK,KAAK,CAAC;QACX,KAAK,OAAO,CAAC;QACb,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACT,OAAO,gBAAgB,CAAC;QAC5B;YACI,OAAO,KAAK,CAAC;KACpB;AACL,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DateDifUnitParam } from '../../constants/interfaces';
|
|
2
2
|
export declare function toDate(value: string): string;
|
|
3
|
+
export declare const setTimezoneToColumnDate: string;
|
|
3
4
|
export declare const dateFormatScript: string;
|
|
4
5
|
export declare const dayScript: (value: any) => string;
|
|
5
6
|
export declare const monthScript: (value: any) => string;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
(function (SCRIPT_NAMES) {
|
|
3
|
-
SCRIPT_NAMES["dateFormat"] = "DATE_FORMAT_SCRIPT";
|
|
4
|
-
})(SCRIPT_NAMES || (SCRIPT_NAMES = {}));
|
|
1
|
+
import { ELASTICSEARCH_SCRIPT_NAMES as SCRIPT_NAMES } from '../../constants';
|
|
5
2
|
export function toDate(value) {
|
|
6
3
|
return `ZonedDateTime.parse("${value}")`;
|
|
7
4
|
}
|
|
5
|
+
export const setTimezoneToColumnDate = `
|
|
6
|
+
${SCRIPT_NAMES.setTimezone}(def date, String timezone) {
|
|
7
|
+
if (date == null) return null;
|
|
8
|
+
def value;
|
|
9
|
+
if (date instanceof List) {
|
|
10
|
+
if (date.empty) return null;
|
|
11
|
+
value = date.value;
|
|
12
|
+
} else {
|
|
13
|
+
value = date;
|
|
14
|
+
}
|
|
15
|
+
return value.withZoneSameInstant(ZoneId.of(timezone));
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
8
18
|
export const dateFormatScript = `
|
|
9
19
|
String ${SCRIPT_NAMES.dateFormat}(def date_value, String format) {
|
|
10
20
|
def isCustomDate = (date_value instanceof JodaCompatibleZonedDateTime || date_value instanceof ZonedDateTime);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../src/utils/elasticsearch/scripts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../src/utils/elasticsearch/scripts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE7E,MAAM,UAAU,MAAM,CAAC,KAAa;IAChC,OAAO,wBAAwB,KAAK,IAAI,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG;EACrC,YAAY,CAAC,WAAW;;;;;;;;;;;CAWzB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;SACvB,YAAY,CAAC,UAAU;;;;;;;;CAQ/B,CAAC;AAEF,SAAS,eAAe,CAAC,KAAU,EAAE,MAAc;IAC/C,OAAO,oBAAoB,YAAY,CAAC,UAAU,IAAI,KAAK,MAAM,MAAM,KAAK,CAAC;AACjF,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAEtE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAEzE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAEvE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAEzE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAEzE,MAAM,UAAU,OAAO,CAAC,KAAU,EAAE,GAAQ,EAAE,IAAsB;IAChE,MAAM,KAAK,GAAG;QACV,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,QAAQ;QACX,CAAC,EAAE,MAAM;KACZ,CAAC;IACF,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,cAAc,WAAW,YAAY,KAAK,KAAK,GAAG,GAAG,CAAC;AACjE,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { FormulaContext, VariableASTType,
|
|
2
|
-
export declare function getVariableContext(variableName: string, context?: FormulaContext):
|
|
3
|
-
export declare function getVariableType(columnCxt?:
|
|
1
|
+
import { FormulaContext, VariableASTType, VariableContextDefinition } from '../constants/interfaces';
|
|
2
|
+
export declare function getVariableContext(variableName: string, context?: FormulaContext): VariableContextDefinition | undefined;
|
|
3
|
+
export declare function getVariableType(columnCxt?: VariableContextDefinition): VariableASTType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVariableType.js","sourceRoot":"","sources":["../../src/utils/getVariableType.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,kBAAkB,CAC9B,YAAoB,EACpB,OAAwB;;IAExB,OAAO,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,YAAY,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,uBAAuB,CAC5B,
|
|
1
|
+
{"version":3,"file":"getVariableType.js","sourceRoot":"","sources":["../../src/utils/getVariableType.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,kBAAkB,CAC9B,YAAoB,EACpB,OAAwB;;IAExB,OAAO,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,YAAY,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,uBAAuB,CAC5B,eAA0C;IAE1C,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,eAAe,CAC3B,SAAqC;IAErC,OAAO,SAAS,KAAK,SAAS;QAC1B,CAAC,CAAC,uBAAuB,CAAC,SAAS,CAAC;QACpC,CAAC,CAAC,UAAU,CAAC;AACrB,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.0",
|
|
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,21 +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(format: string): string {
|
|
11
|
-
return `Integer.parseInt(DATE_FORMAT_SCRIPT(ZonedDateTime.parse("2023-12-31T00:00:00.000Z"), '${format}'))`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function dateParser(format: string): string {
|
|
15
|
-
const dateToInt = dateFormatToInt(format);
|
|
16
|
-
return `${dateFormatScript}\n${dateToInt}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function dateDif(format: string) {
|
|
20
|
-
return `ChronoUnit.${format}.between(ZonedDateTime.parse("2023-12-31T00:00:00.000Z"), ZonedDateTime.parse("2022-12-31T00:00:00.000Z"))`;
|
|
21
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export function datePart(part: string) {
|
|
2
|
-
return `DATE_PART('${part}', CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ))`;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function dateDif(unit: string): string {
|
|
6
|
-
switch (unit) {
|
|
7
|
-
case 'day':
|
|
8
|
-
case 'month':
|
|
9
|
-
return `DATEDIFF('${unit}', CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ), CAST('2022-12-31T00:00:00.000Z' AS TIMESTAMPTZ))`;
|
|
10
|
-
case 'year':
|
|
11
|
-
return `CASE
|
|
12
|
-
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
|
|
13
|
-
THEN DATEDIFF('${unit}', CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ), CAST('2022-12-31T00:00:00.000Z' AS TIMESTAMPTZ))
|
|
14
|
-
ELSE DATEDIFF('${unit}', CAST('2023-12-31T00:00:00.000Z' AS TIMESTAMPTZ), CAST('2022-12-31T00:00:00.000Z' AS TIMESTAMPTZ)) - 1
|
|
15
|
-
END`; //Indentation care, be careful
|
|
16
|
-
|
|
17
|
-
default:
|
|
18
|
-
return '';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { ENGINES, Transpile } from '../../src';
|
|
2
|
-
import {
|
|
3
|
-
dateDif,
|
|
4
|
-
dateParser,
|
|
5
|
-
dateFormatToInt,
|
|
6
|
-
dateFormatScript,
|
|
7
|
-
} from './__mocks__/elasticsearchScripts';
|
|
8
|
-
const currentEngine = ENGINES.ELASTICSEARCH;
|
|
9
|
-
|
|
10
|
-
describe('ELASTICSEARCH Transpile program', () => {
|
|
11
|
-
test('Basic case', () => {
|
|
12
|
-
const result = Transpile('1 + 2', currentEngine);
|
|
13
|
-
expect(result?.expression).toBe('(1 + 2)');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('MID function', () => {
|
|
17
|
-
const result = Transpile('MID("test", 1, 5)', currentEngine);
|
|
18
|
-
expect(result?.expression).toBe(`'test'.substring(1, 5)`);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('Should transpile a function inside another function', () => {
|
|
22
|
-
const program = 'MID(MID("This is a test", 1, 5), 1, 2)';
|
|
23
|
-
const result = Transpile(program, currentEngine);
|
|
24
|
-
expect(result?.valid).toBe(true);
|
|
25
|
-
expect(result?.expression).toBe(
|
|
26
|
-
"'This is a test'.substring(1, 5).substring(1, 2)",
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('ABS function', () => {
|
|
31
|
-
const result = Transpile('ABS(5)', currentEngine);
|
|
32
|
-
expect(result?.expression).toBe(`Math.abs(5)`);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('DAY function', () => {
|
|
36
|
-
const result = Transpile('DAY("12/31/2023")', currentEngine);
|
|
37
|
-
const mock = dateParser('dd').replace(/\n/g, '');
|
|
38
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('Two DAY function', () => {
|
|
42
|
-
const result = Transpile(
|
|
43
|
-
'DAY("12/31/2023") + DAY("12/31/2023")',
|
|
44
|
-
currentEngine,
|
|
45
|
-
);
|
|
46
|
-
const concat = `${dateFormatScript}\n(${dateFormatToInt(
|
|
47
|
-
'dd',
|
|
48
|
-
)} + ${dateFormatToInt('dd')})`;
|
|
49
|
-
const mock = concat.replace(/\n/g, '');
|
|
50
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('MONTH function', () => {
|
|
54
|
-
const result = Transpile('MONTH("12/31/2023")', currentEngine);
|
|
55
|
-
const mock = dateParser('MM').replace(/\n/g, '');
|
|
56
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('One DAY plus One Month function', () => {
|
|
60
|
-
const result = Transpile(
|
|
61
|
-
'DAY("12/31/2023") + MONTH("12/31/2023")',
|
|
62
|
-
currentEngine,
|
|
63
|
-
);
|
|
64
|
-
const concat = `${dateFormatScript}\n(${dateFormatToInt(
|
|
65
|
-
'dd',
|
|
66
|
-
)} + ${dateFormatToInt('MM')})`;
|
|
67
|
-
const mock = concat.replace(/\n/g, '');
|
|
68
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('YEAR function', () => {
|
|
72
|
-
const result = Transpile('YEAR("12/31/2023")', currentEngine);
|
|
73
|
-
const mock = dateParser('yyyy').replace(/\n/g, '');
|
|
74
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('HOUR function', () => {
|
|
78
|
-
const result = Transpile('HOUR("12/31/2023")', currentEngine);
|
|
79
|
-
const mock = dateParser('HH').replace(/\n/g, '');
|
|
80
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('MINUTE function', () => {
|
|
84
|
-
const result = Transpile('MINUTE("12/31/2023")', currentEngine);
|
|
85
|
-
const mock = dateParser('mm').replace(/\n/g, '');
|
|
86
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('SECOND function', () => {
|
|
90
|
-
const result = Transpile('SECOND("12/31/2023")', currentEngine);
|
|
91
|
-
const mock = dateParser('ss').replace(/\n/g, '');
|
|
92
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(mock);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('DATEDIF function with Y unit', () => {
|
|
96
|
-
const result = Transpile(
|
|
97
|
-
'DATEDIF("12/31/2023", "12/31/2022", "Y")',
|
|
98
|
-
currentEngine,
|
|
99
|
-
);
|
|
100
|
-
const mock = dateDif('YEARS');
|
|
101
|
-
expect(result?.expression).toBe(mock);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('DATEDIF function with M unit', () => {
|
|
105
|
-
const result = Transpile(
|
|
106
|
-
'DATEDIF("12/31/2023", "12/31/2022", "M")',
|
|
107
|
-
currentEngine,
|
|
108
|
-
);
|
|
109
|
-
const mock = dateDif('MONTHS');
|
|
110
|
-
expect(result?.expression).toBe(mock);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('DATEDIF function with D unit', () => {
|
|
114
|
-
const result = Transpile(
|
|
115
|
-
'DATEDIF("12/31/2023", "12/31/2022", "D")',
|
|
116
|
-
currentEngine,
|
|
117
|
-
);
|
|
118
|
-
const mock = dateDif('DAYS');
|
|
119
|
-
expect(result?.expression).toBe(mock);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('DATEDIF function with a not valid Unit', () => {
|
|
123
|
-
const result = Transpile(
|
|
124
|
-
'DATEDIF("12/31/2023", "12/31/2022", "X")',
|
|
125
|
-
currentEngine,
|
|
126
|
-
);
|
|
127
|
-
expect(result).not.toBeUndefined();
|
|
128
|
-
expect(result?.valid).toBe(false);
|
|
129
|
-
expect(result?.error).not.toBeUndefined();
|
|
130
|
-
expect(result?.error?.code).toBe('DATE_DIF_UNIT_PARAM');
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('IF function full parameters', () => {
|
|
134
|
-
const result = Transpile('IF(5 = 1, "True", "False")', currentEngine);
|
|
135
|
-
expect(result).not.toBeUndefined();
|
|
136
|
-
expect(result?.error).toBeUndefined();
|
|
137
|
-
expect(result?.expression).toBe(`((5 == 1) ? 'True' : 'False')`);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test('IF function basic parameters', () => {
|
|
141
|
-
const result = Transpile('IF(5 = 1, "True")', currentEngine);
|
|
142
|
-
expect(result).not.toBeUndefined();
|
|
143
|
-
expect(result?.error).toBeUndefined();
|
|
144
|
-
expect(result?.expression).toBe(`((5 == 1) ? 'True' : false)`);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('IFS function basic parameters', () => {
|
|
148
|
-
const result = Transpile(
|
|
149
|
-
'IFS(5>10, "Greater than 10", 5>5, "Greater than 5",5>0, "Greater than 0")',
|
|
150
|
-
currentEngine,
|
|
151
|
-
);
|
|
152
|
-
expect(result).not.toBeUndefined();
|
|
153
|
-
expect(result?.error).toBeUndefined();
|
|
154
|
-
expect(result?.expression).toBe(
|
|
155
|
-
`((5 > 10) ? 'Greater than 10' : ((5 > 5) ? 'Greater than 5' : ((5 > 0) ? 'Greater than 0' : null)))`,
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -1,22 +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
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { ENGINES, Transpile } from '../../src';
|
|
2
|
-
import { datePart, dateDif } from './__mocks__/sqlScripts';
|
|
3
|
-
const currentEngine = ENGINES.REDSHIFT;
|
|
4
|
-
|
|
5
|
-
describe('SNOWFLAKE Transpile program', () => {
|
|
6
|
-
test('Basic case', () => {
|
|
7
|
-
const result = Transpile('1 + 2', currentEngine);
|
|
8
|
-
expect(result?.expression).toBe('(1 + 2)');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('MID function', () => {
|
|
12
|
-
const result = Transpile('MID("test", 1, 5)', currentEngine);
|
|
13
|
-
expect(result?.expression).toBe(`SUBSTRING('test', 1, 5)`);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('Should transpile a function inside another function', () => {
|
|
17
|
-
const program = 'MID(MID("This is a test", 1, 5), 1, 2)';
|
|
18
|
-
const result = Transpile(program, currentEngine);
|
|
19
|
-
expect(result?.valid).toBe(true);
|
|
20
|
-
expect(result?.expression).toBe(
|
|
21
|
-
"SUBSTRING(SUBSTRING('This is a test', 1, 5), 1, 2)",
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('ABS function', () => {
|
|
26
|
-
const result = Transpile('ABS(5)', currentEngine);
|
|
27
|
-
expect(result?.expression).toBe(`ABS(5)`);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('DAY function', () => {
|
|
31
|
-
const result = Transpile('DAY("12/31/2023")', currentEngine);
|
|
32
|
-
expect(result?.expression).toBe(datePart('day'));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('MONTH function', () => {
|
|
36
|
-
const result = Transpile('MONTH("12/31/2023")', currentEngine);
|
|
37
|
-
expect(result?.expression).toBe(datePart('month'));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('YEAR function', () => {
|
|
41
|
-
const result = Transpile('YEAR("12/31/2023")', currentEngine);
|
|
42
|
-
expect(result?.expression).toBe(datePart('year'));
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('HOUR function', () => {
|
|
46
|
-
const result = Transpile('HOUR("12/31/2023")', currentEngine);
|
|
47
|
-
expect(result?.expression).toBe(datePart('hour'));
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('MINUTE function', () => {
|
|
51
|
-
const result = Transpile('MINUTE("12/31/2023")', currentEngine);
|
|
52
|
-
expect(result?.expression).toBe(datePart('minute'));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('SECOND function', () => {
|
|
56
|
-
const result = Transpile('SECOND("12/31/2023")', currentEngine);
|
|
57
|
-
expect(result?.expression).toBe(datePart('second'));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('DATEDIF function with Y unit', () => {
|
|
61
|
-
const result = Transpile(
|
|
62
|
-
'DATEDIF("12/31/2023", "12/31/2022", "Y")',
|
|
63
|
-
currentEngine,
|
|
64
|
-
);
|
|
65
|
-
const mock = dateDif('year');
|
|
66
|
-
expect(result?.expression).toBe(mock);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('DATEDIF function with M unit', () => {
|
|
70
|
-
const result = Transpile(
|
|
71
|
-
'DATEDIF("12/31/2023", "12/31/2022", "M")',
|
|
72
|
-
currentEngine,
|
|
73
|
-
);
|
|
74
|
-
const mock = dateDif('month');
|
|
75
|
-
expect(result?.expression).toBe(mock);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('DATEDIF function with D unit', () => {
|
|
79
|
-
const result = Transpile(
|
|
80
|
-
'DATEDIF("12/31/2023", "12/31/2022", "D")',
|
|
81
|
-
currentEngine,
|
|
82
|
-
);
|
|
83
|
-
const mock = dateDif('day');
|
|
84
|
-
expect(result?.expression).toBe(mock);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('DATEDIF function with a not valid Unit', () => {
|
|
88
|
-
const result = Transpile(
|
|
89
|
-
'DATEDIF("12/31/2023", "12/31/2022", "X")',
|
|
90
|
-
currentEngine,
|
|
91
|
-
);
|
|
92
|
-
expect(result).not.toBeUndefined();
|
|
93
|
-
expect(result?.valid).toBe(false);
|
|
94
|
-
expect(result?.error).not.toBeUndefined();
|
|
95
|
-
expect(result?.error?.code).toBe('DATE_DIF_UNIT_PARAM');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('IF function full parameters', () => {
|
|
99
|
-
const result = Transpile('IF(5 = 1, "True", "False")', currentEngine);
|
|
100
|
-
expect(result).not.toBeUndefined();
|
|
101
|
-
expect(result?.error).toBeUndefined();
|
|
102
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(
|
|
103
|
-
`(CASE WHEN (5 = 1) THEN 'True' ELSE 'False'END)`,
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('IF function basic parameters', () => {
|
|
108
|
-
const result = Transpile('IF(5 = 1, "True")', currentEngine);
|
|
109
|
-
expect(result).not.toBeUndefined();
|
|
110
|
-
expect(result?.error).toBeUndefined();
|
|
111
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(
|
|
112
|
-
`(CASE WHEN (5 = 1) THEN 'True' ELSE FALSEEND)`,
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('IFS function basic parameters', () => {
|
|
117
|
-
const result = Transpile(
|
|
118
|
-
'IFS(5>10, "Greater than 10", 5>5, "Greater than 5",5>0, "Greater than 0")',
|
|
119
|
-
currentEngine,
|
|
120
|
-
);
|
|
121
|
-
expect(result).not.toBeUndefined();
|
|
122
|
-
expect(result?.error).toBeUndefined();
|
|
123
|
-
expect(result?.expression?.replace(/\n/g, '')).toBe(
|
|
124
|
-
`(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)`,
|
|
125
|
-
);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { ENGINES, Transpile } from '../../src';
|
|
2
|
-
import { datePart, dateDif } from './__mocks__/sqlScripts';
|
|
3
|
-
const currentEngine = ENGINES.SNOWFLAKE;
|
|
4
|
-
|
|
5
|
-
describe('SNOWFLAKE Transpile program', () => {
|
|
6
|
-
test('Basic case', () => {
|
|
7
|
-
const result = Transpile('1 + 2', currentEngine);
|
|
8
|
-
expect(result?.expression).toBe('(1 + 2)');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('MID function', () => {
|
|
12
|
-
const result = Transpile('MID("test", 1, 5)', currentEngine);
|
|
13
|
-
expect(result?.expression).toBe(`SUBSTRING('test', 1, 5)`);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('Should transpile a function inside another function', () => {
|
|
17
|
-
const program = 'MID(MID("This is a test", 1, 5), 1, 2)';
|
|
18
|
-
const result = Transpile(program, currentEngine);
|
|
19
|
-
expect(result?.valid).toBe(true);
|
|
20
|
-
expect(result?.expression).toBe(
|
|
21
|
-
"SUBSTRING(SUBSTRING('This is a test', 1, 5), 1, 2)",
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('ABS function', () => {
|
|
26
|
-
const result = Transpile('ABS(5)', currentEngine);
|
|
27
|
-
expect(result?.expression).toBe(`ABS(5)`);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('DAY function', () => {
|
|
31
|
-
const result = Transpile('DAY("12/31/2023")', currentEngine);
|
|
32
|
-
expect(result?.expression).toBe(datePart('day'));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('MONTH function', () => {
|
|
36
|
-
const result = Transpile('MONTH("12/31/2023")', currentEngine);
|
|
37
|
-
expect(result?.expression).toBe(datePart('month'));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('YEAR function', () => {
|
|
41
|
-
const result = Transpile('YEAR("12/31/2023")', currentEngine);
|
|
42
|
-
expect(result?.expression).toBe(datePart('year'));
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('HOUR function', () => {
|
|
46
|
-
const result = Transpile('HOUR("12/31/2023")', currentEngine);
|
|
47
|
-
expect(result?.expression).toBe(datePart('hour'));
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('MINUTE function', () => {
|
|
51
|
-
const result = Transpile('MINUTE("12/31/2023")', currentEngine);
|
|
52
|
-
expect(result?.expression).toBe(datePart('minute'));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('SECOND function', () => {
|
|
56
|
-
const result = Transpile('SECOND("12/31/2023")', currentEngine);
|
|
57
|
-
expect(result?.expression).toBe(datePart('second'));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('DATEDIF function with Y unit', () => {
|
|
61
|
-
const result = Transpile(
|
|
62
|
-
'DATEDIF("12/31/2023", "12/31/2022", "Y")',
|
|
63
|
-
currentEngine,
|
|
64
|
-
);
|
|
65
|
-
const mock = dateDif('year');
|
|
66
|
-
expect(result?.expression).toBe(mock);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('DATEDIF function with M unit', () => {
|
|
70
|
-
const result = Transpile(
|
|
71
|
-
'DATEDIF("12/31/2023", "12/31/2022", "M")',
|
|
72
|
-
currentEngine,
|
|
73
|
-
);
|
|
74
|
-
const mock = dateDif('month');
|
|
75
|
-
expect(result?.expression).toBe(mock);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('DATEDIF function with D unit', () => {
|
|
79
|
-
const result = Transpile(
|
|
80
|
-
'DATEDIF("12/31/2023", "12/31/2022", "D")',
|
|
81
|
-
currentEngine,
|
|
82
|
-
);
|
|
83
|
-
const mock = dateDif('day');
|
|
84
|
-
expect(result?.expression).toBe(mock);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('DATEDIF function with a not valid Unit', () => {
|
|
88
|
-
const result = Transpile(
|
|
89
|
-
'DATEDIF("12/31/2023", "12/31/2022", "X")',
|
|
90
|
-
currentEngine,
|
|
91
|
-
);
|
|
92
|
-
expect(result).not.toBeUndefined();
|
|
93
|
-
expect(result?.valid).toBe(false);
|
|
94
|
-
expect(result?.error).not.toBeUndefined();
|
|
95
|
-
expect(result?.error?.code).toBe('DATE_DIF_UNIT_PARAM');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('IF function full parameters', () => {
|
|
99
|
-
const result = Transpile('IF(5 = 1, "True", "False")', currentEngine);
|
|
100
|
-
expect(result).not.toBeUndefined();
|
|
101
|
-
expect(result?.error).toBeUndefined();
|
|
102
|
-
expect(result?.expression).toBe(`IFF((5 = 1), 'True', 'False')`);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('IF function basic parameters', () => {
|
|
106
|
-
const result = Transpile('IF(5 = 1, "True")', currentEngine);
|
|
107
|
-
expect(result).not.toBeUndefined();
|
|
108
|
-
expect(result?.error).toBeUndefined();
|
|
109
|
-
expect(result?.expression).toBe(`IFF((5 = 1), 'True', FALSE)`);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('IFS function basic parameters', () => {
|
|
113
|
-
const result = Transpile(
|
|
114
|
-
'IFS(5>10, "Greater than 10", 5>5, "Greater than 5",5>0, "Greater than 0")',
|
|
115
|
-
currentEngine,
|
|
116
|
-
);
|
|
117
|
-
expect(result).not.toBeUndefined();
|
|
118
|
-
expect(result?.error).toBeUndefined();
|
|
119
|
-
expect(result?.expression).toBe(
|
|
120
|
-
`IFF((5 > 10), 'Greater than 10', IFF((5 > 5), 'Greater than 5', IFF((5 > 0), 'Greater than 0', NULL)))`,
|
|
121
|
-
);
|
|
122
|
-
});
|
|
123
|
-
});
|