@malloydata/malloy 0.0.39-dev230613161129 → 0.0.39

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.
Files changed (288) hide show
  1. package/dist/dialect/dialect.d.ts +9 -13
  2. package/dist/dialect/dialect.js +16 -3
  3. package/dist/dialect/dialect_map.d.ts +2 -0
  4. package/dist/dialect/dialect_map.js +61 -1
  5. package/dist/dialect/{duckdb.d.ts → duckdb/duckdb.d.ts} +8 -5
  6. package/dist/dialect/{duckdb.js → duckdb/duckdb.js} +21 -9
  7. package/dist/dialect/duckdb/functions/byte_length.d.ts +2 -0
  8. package/dist/dialect/duckdb/functions/byte_length.js +33 -0
  9. package/dist/dialect/duckdb/functions/div.d.ts +2 -0
  10. package/dist/dialect/duckdb/functions/div.js +38 -0
  11. package/dist/dialect/duckdb/functions/duckdb_functions.d.ts +1 -0
  12. package/dist/dialect/duckdb/functions/duckdb_functions.js +52 -0
  13. package/dist/dialect/duckdb/functions/ends_with.d.ts +2 -0
  14. package/dist/dialect/duckdb/functions/ends_with.js +35 -0
  15. package/dist/dialect/duckdb/functions/greatest_and_least.d.ts +3 -0
  16. package/dist/dialect/duckdb/functions/greatest_and_least.js +58 -0
  17. package/dist/dialect/duckdb/functions/index.d.ts +1 -0
  18. package/dist/dialect/duckdb/functions/index.js +28 -0
  19. package/dist/dialect/duckdb/functions/is_inf.d.ts +2 -0
  20. package/dist/dialect/duckdb/functions/is_inf.js +33 -0
  21. package/dist/dialect/duckdb/functions/is_nan.d.ts +2 -0
  22. package/dist/dialect/duckdb/functions/is_nan.js +33 -0
  23. package/dist/dialect/duckdb/functions/log.d.ts +2 -0
  24. package/dist/dialect/duckdb/functions/log.js +38 -0
  25. package/dist/dialect/duckdb/functions/rand.d.ts +2 -0
  26. package/dist/dialect/duckdb/functions/rand.js +31 -0
  27. package/dist/dialect/duckdb/functions/replace.d.ts +2 -0
  28. package/dist/dialect/duckdb/functions/replace.js +40 -0
  29. package/dist/dialect/duckdb/functions/trunc.d.ts +2 -0
  30. package/dist/dialect/duckdb/functions/trunc.js +39 -0
  31. package/dist/dialect/duckdb/functions/unicode.d.ts +2 -0
  32. package/dist/dialect/duckdb/functions/unicode.js +35 -0
  33. package/dist/dialect/duckdb/index.d.ts +1 -0
  34. package/dist/dialect/duckdb/index.js +40 -0
  35. package/dist/dialect/functions/all_functions.d.ts +8 -0
  36. package/dist/dialect/functions/all_functions.js +135 -0
  37. package/dist/dialect/functions/atan2.d.ts +2 -0
  38. package/dist/dialect/functions/atan2.js +33 -0
  39. package/dist/dialect/functions/avg_moving.d.ts +2 -0
  40. package/dist/dialect/functions/avg_moving.js +46 -0
  41. package/dist/dialect/functions/chr.d.ts +4 -0
  42. package/dist/dialect/functions/chr.js +45 -0
  43. package/dist/dialect/functions/coalesce.d.ts +2 -0
  44. package/dist/dialect/functions/coalesce.js +38 -0
  45. package/dist/dialect/functions/concat.d.ts +2 -0
  46. package/dist/dialect/functions/concat.js +38 -0
  47. package/dist/dialect/functions/div.d.ts +2 -0
  48. package/dist/dialect/functions/div.js +36 -0
  49. package/dist/dialect/functions/first_value_window.d.ts +3 -0
  50. package/dist/dialect/functions/first_value_window.js +49 -0
  51. package/dist/dialect/functions/function_map.d.ts +16 -0
  52. package/dist/dialect/functions/function_map.js +50 -0
  53. package/dist/dialect/functions/greatest_and_least.d.ts +3 -0
  54. package/dist/dialect/functions/greatest_and_least.js +44 -0
  55. package/dist/dialect/functions/ifnull.d.ts +2 -0
  56. package/dist/dialect/functions/ifnull.js +38 -0
  57. package/dist/dialect/functions/index.d.ts +2 -0
  58. package/dist/dialect/functions/index.js +28 -0
  59. package/dist/dialect/functions/is_inf.d.ts +2 -0
  60. package/dist/dialect/functions/is_inf.js +33 -0
  61. package/dist/dialect/functions/is_nan.d.ts +2 -0
  62. package/dist/dialect/functions/is_nan.js +33 -0
  63. package/dist/dialect/functions/lag.d.ts +2 -0
  64. package/dist/dialect/functions/lag.js +53 -0
  65. package/dist/dialect/functions/lead.d.ts +2 -0
  66. package/dist/dialect/functions/lead.js +50 -0
  67. package/dist/dialect/functions/length.d.ts +3 -0
  68. package/dist/dialect/functions/length.js +39 -0
  69. package/dist/dialect/functions/log.d.ts +2 -0
  70. package/dist/dialect/functions/log.js +35 -0
  71. package/dist/dialect/functions/lower.d.ts +2 -0
  72. package/dist/dialect/functions/lower.js +34 -0
  73. package/dist/dialect/functions/nullif.d.ts +2 -0
  74. package/dist/dialect/functions/nullif.js +42 -0
  75. package/dist/dialect/functions/pi.d.ts +2 -0
  76. package/dist/{lang/ast/types/type-desc.js → dialect/functions/pi.js} +7 -1
  77. package/dist/dialect/functions/pow.d.ts +2 -0
  78. package/dist/dialect/functions/pow.js +35 -0
  79. package/dist/dialect/functions/rand.d.ts +2 -0
  80. package/dist/dialect/functions/rand.js +31 -0
  81. package/dist/dialect/functions/rank.d.ts +2 -0
  82. package/dist/dialect/functions/rank.js +36 -0
  83. package/dist/dialect/functions/regexp_extract.d.ts +2 -0
  84. package/dist/dialect/functions/regexp_extract.js +41 -0
  85. package/dist/dialect/functions/repeat.d.ts +2 -0
  86. package/dist/dialect/functions/repeat.js +35 -0
  87. package/dist/dialect/functions/replace.d.ts +2 -0
  88. package/dist/dialect/functions/replace.js +42 -0
  89. package/dist/dialect/functions/reverse.d.ts +2 -0
  90. package/dist/dialect/functions/reverse.js +34 -0
  91. package/dist/dialect/functions/round.d.ts +2 -0
  92. package/dist/dialect/functions/round.js +40 -0
  93. package/dist/dialect/functions/row_number.d.ts +2 -0
  94. package/dist/dialect/functions/row_number.js +40 -0
  95. package/dist/dialect/functions/simple_numeric_functions.d.ts +15 -0
  96. package/dist/dialect/functions/simple_numeric_functions.js +60 -0
  97. package/dist/dialect/functions/starts_ends_with.d.ts +3 -0
  98. package/dist/dialect/functions/starts_ends_with.js +43 -0
  99. package/dist/dialect/functions/stddev.d.ts +2 -0
  100. package/dist/dialect/functions/stddev.js +34 -0
  101. package/dist/dialect/functions/strpos.d.ts +2 -0
  102. package/dist/dialect/functions/strpos.js +35 -0
  103. package/dist/dialect/functions/substr.d.ts +2 -0
  104. package/dist/dialect/functions/substr.js +37 -0
  105. package/dist/dialect/functions/sum_min_max_window.d.ts +7 -0
  106. package/dist/dialect/functions/sum_min_max_window.js +94 -0
  107. package/dist/dialect/functions/trim_functions.d.ts +4 -0
  108. package/dist/dialect/functions/trim_functions.js +42 -0
  109. package/dist/dialect/functions/trunc.d.ts +2 -0
  110. package/dist/dialect/functions/trunc.js +38 -0
  111. package/dist/dialect/functions/upper.d.ts +2 -0
  112. package/dist/dialect/functions/upper.js +34 -0
  113. package/dist/dialect/functions/util.d.ts +45 -0
  114. package/dist/dialect/functions/util.js +187 -0
  115. package/dist/dialect/index.d.ts +1 -1
  116. package/dist/dialect/index.js +2 -1
  117. package/dist/dialect/postgres/functions/byte_length.d.ts +2 -0
  118. package/dist/dialect/postgres/functions/byte_length.js +33 -0
  119. package/dist/dialect/postgres/functions/ends_with.d.ts +2 -0
  120. package/dist/dialect/postgres/functions/ends_with.js +38 -0
  121. package/dist/dialect/postgres/functions/greatest_and_least.d.ts +3 -0
  122. package/dist/dialect/postgres/functions/greatest_and_least.js +45 -0
  123. package/dist/dialect/postgres/functions/ifnull.d.ts +2 -0
  124. package/dist/dialect/postgres/functions/ifnull.js +40 -0
  125. package/dist/dialect/postgres/functions/index.d.ts +1 -0
  126. package/dist/dialect/postgres/functions/index.js +28 -0
  127. package/dist/dialect/postgres/functions/is_inf.d.ts +2 -0
  128. package/dist/dialect/postgres/functions/is_inf.js +34 -0
  129. package/dist/dialect/postgres/functions/is_nan.d.ts +2 -0
  130. package/dist/dialect/postgres/functions/is_nan.js +33 -0
  131. package/dist/dialect/postgres/functions/log.d.ts +2 -0
  132. package/dist/dialect/postgres/functions/log.js +37 -0
  133. package/dist/dialect/postgres/functions/postgres_functions.d.ts +1 -0
  134. package/dist/dialect/postgres/functions/postgres_functions.js +60 -0
  135. package/dist/dialect/postgres/functions/rand.d.ts +2 -0
  136. package/dist/dialect/postgres/functions/rand.js +31 -0
  137. package/dist/dialect/postgres/functions/regexp_extract.d.ts +2 -0
  138. package/dist/dialect/postgres/functions/regexp_extract.js +35 -0
  139. package/dist/dialect/postgres/functions/replace.d.ts +2 -0
  140. package/dist/dialect/postgres/functions/replace.js +40 -0
  141. package/dist/dialect/postgres/functions/round.d.ts +2 -0
  142. package/dist/dialect/postgres/functions/round.js +39 -0
  143. package/dist/dialect/postgres/functions/stddev.d.ts +2 -0
  144. package/dist/dialect/postgres/functions/stddev.js +37 -0
  145. package/dist/dialect/postgres/functions/substr.d.ts +2 -0
  146. package/dist/dialect/postgres/functions/substr.js +38 -0
  147. package/dist/dialect/postgres/functions/trunc.d.ts +2 -0
  148. package/dist/dialect/postgres/functions/trunc.js +40 -0
  149. package/dist/dialect/postgres/functions/unicode.d.ts +2 -0
  150. package/dist/dialect/postgres/functions/unicode.js +34 -0
  151. package/dist/dialect/postgres/index.d.ts +1 -0
  152. package/dist/dialect/postgres/index.js +40 -0
  153. package/dist/dialect/{postgres.d.ts → postgres/postgres.d.ts} +9 -5
  154. package/dist/dialect/{postgres.js → postgres/postgres.js} +24 -10
  155. package/dist/dialect/standardsql/functions/chr.d.ts +2 -0
  156. package/dist/dialect/standardsql/functions/chr.js +37 -0
  157. package/dist/dialect/standardsql/functions/index.d.ts +1 -0
  158. package/dist/dialect/standardsql/functions/index.js +28 -0
  159. package/dist/dialect/standardsql/functions/pi.d.ts +2 -0
  160. package/dist/dialect/standardsql/functions/pi.js +32 -0
  161. package/dist/dialect/standardsql/functions/standardsql_functions.d.ts +1 -0
  162. package/dist/dialect/standardsql/functions/standardsql_functions.js +33 -0
  163. package/dist/dialect/standardsql/index.d.ts +1 -0
  164. package/dist/dialect/standardsql/index.js +40 -0
  165. package/dist/dialect/{standardsql.d.ts → standardsql/standardsql.d.ts} +7 -4
  166. package/dist/dialect/{standardsql.js → standardsql/standardsql.js} +13 -11
  167. package/dist/index.d.ts +1 -1
  168. package/dist/lang/ast/ast-utils.js +1 -0
  169. package/dist/lang/ast/elements/define-query.js +1 -1
  170. package/dist/lang/ast/elements/import-statement.js +6 -1
  171. package/dist/lang/ast/executors/index-executor.d.ts +1 -1
  172. package/dist/lang/ast/executors/index-executor.js +2 -2
  173. package/dist/lang/ast/executors/project-executor.d.ts +1 -1
  174. package/dist/lang/ast/executors/project-executor.js +2 -2
  175. package/dist/lang/ast/executors/reduce-executor.d.ts +2 -4
  176. package/dist/lang/ast/executors/reduce-executor.js +8 -4
  177. package/dist/lang/ast/expressions/binary-boolean.d.ts +1 -1
  178. package/dist/lang/ast/expressions/binary-boolean.js +2 -0
  179. package/dist/lang/ast/expressions/constant-sub-expression.js +10 -0
  180. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +2 -2
  181. package/dist/lang/ast/expressions/expr-aggregate-function.js +28 -2
  182. package/dist/lang/ast/expressions/expr-alternation-tree.js +1 -0
  183. package/dist/lang/ast/expressions/expr-cast.js +1 -0
  184. package/dist/lang/ast/expressions/expr-coalesce.d.ts +1 -1
  185. package/dist/lang/ast/expressions/expr-coalesce.js +1 -0
  186. package/dist/lang/ast/expressions/expr-count-distinct.d.ts +1 -1
  187. package/dist/lang/ast/expressions/expr-count.js +1 -0
  188. package/dist/lang/ast/expressions/expr-filter.d.ts +1 -1
  189. package/dist/lang/ast/expressions/expr-filter.js +1 -1
  190. package/dist/lang/ast/expressions/expr-func.d.ts +6 -1
  191. package/dist/lang/ast/expressions/expr-func.js +266 -16
  192. package/dist/lang/ast/expressions/expr-granular-time.d.ts +1 -1
  193. package/dist/lang/ast/expressions/expr-id-reference.js +12 -0
  194. package/dist/lang/ast/expressions/expr-logical-op.d.ts +1 -1
  195. package/dist/lang/ast/expressions/expr-max.d.ts +2 -2
  196. package/dist/lang/ast/expressions/expr-min.d.ts +2 -2
  197. package/dist/lang/ast/expressions/expr-not.d.ts +1 -1
  198. package/dist/lang/ast/expressions/expr-now.js +2 -0
  199. package/dist/lang/ast/expressions/expr-null.js +1 -0
  200. package/dist/lang/ast/expressions/expr-number.js +5 -1
  201. package/dist/lang/ast/expressions/expr-regex.js +4 -1
  202. package/dist/lang/ast/expressions/expr-string.js +1 -0
  203. package/dist/lang/ast/expressions/expr-time-extract.js +2 -0
  204. package/dist/lang/ast/expressions/expr-time.js +1 -0
  205. package/dist/lang/ast/expressions/expr-ungroup.d.ts +2 -2
  206. package/dist/lang/ast/expressions/expr-ungroup.js +15 -7
  207. package/dist/lang/ast/expressions/for-range.d.ts +1 -1
  208. package/dist/lang/ast/expressions/pick-when.js +7 -0
  209. package/dist/lang/ast/expressions/range.js +1 -0
  210. package/dist/lang/ast/expressions/time-literal.js +9 -3
  211. package/dist/lang/ast/field-space/column-space-field.d.ts +1 -2
  212. package/dist/lang/ast/field-space/dynamic-space.js +6 -4
  213. package/dist/lang/ast/field-space/field-definition-value.d.ts +1 -1
  214. package/dist/lang/ast/field-space/project-field-space.d.ts +2 -2
  215. package/dist/lang/ast/field-space/project-field-space.js +12 -13
  216. package/dist/lang/ast/field-space/query-space-field.d.ts +1 -2
  217. package/dist/lang/ast/field-space/query-space-field.js +1 -1
  218. package/dist/lang/ast/field-space/query-spaces.d.ts +16 -2
  219. package/dist/lang/ast/field-space/query-spaces.js +175 -10
  220. package/dist/lang/ast/field-space/reference-field.d.ts +3 -2
  221. package/dist/lang/ast/field-space/reference-field.js +8 -1
  222. package/dist/lang/ast/field-space/rename-space-field.d.ts +1 -2
  223. package/dist/lang/ast/field-space/static-space.d.ts +4 -3
  224. package/dist/lang/ast/field-space/static-space.js +4 -0
  225. package/dist/lang/ast/field-space/struct-space-field-base.d.ts +1 -2
  226. package/dist/lang/ast/field-space/struct-space-field-base.js +1 -1
  227. package/dist/lang/ast/field-space/wild-space-field.d.ts +1 -2
  228. package/dist/lang/ast/fragtype-utils.d.ts +1 -1
  229. package/dist/lang/ast/fragtype-utils.js +4 -3
  230. package/dist/lang/ast/index.d.ts +1 -0
  231. package/dist/lang/ast/index.js +1 -0
  232. package/dist/lang/ast/query-items/field-declaration.d.ts +40 -4
  233. package/dist/lang/ast/query-items/field-declaration.js +102 -3
  234. package/dist/lang/ast/query-items/field-references.d.ts +44 -2
  235. package/dist/lang/ast/query-items/field-references.js +110 -2
  236. package/dist/lang/ast/query-items/typecheck_utils.d.ts +10 -0
  237. package/dist/lang/ast/query-items/typecheck_utils.js +177 -0
  238. package/dist/lang/ast/query-properties/aggregate.js +0 -6
  239. package/dist/lang/ast/query-properties/calculate.d.ts +5 -0
  240. package/dist/lang/ast/query-properties/calculate.js +33 -0
  241. package/dist/lang/ast/query-properties/dimmensions.js +0 -3
  242. package/dist/lang/ast/query-properties/filters.js +6 -3
  243. package/dist/lang/ast/query-properties/group-by.js +0 -6
  244. package/dist/lang/ast/query-properties/measures.js +0 -3
  245. package/dist/lang/ast/query-properties/nest-reference.d.ts +2 -0
  246. package/dist/lang/ast/query-properties/nest-reference.js +23 -0
  247. package/dist/lang/ast/query-properties/ordering.d.ts +1 -1
  248. package/dist/lang/ast/query-properties/ordering.js +18 -8
  249. package/dist/lang/ast/query-properties/qop-desc.js +8 -4
  250. package/dist/lang/ast/query-properties/top.js +20 -6
  251. package/dist/lang/ast/sources/named-source.js +4 -0
  252. package/dist/lang/ast/sources/sql-source.js +5 -1
  253. package/dist/lang/ast/time-utils.d.ts +1 -2
  254. package/dist/lang/ast/types/expr-result.d.ts +1 -2
  255. package/dist/lang/ast/types/expression-def.d.ts +3 -4
  256. package/dist/lang/ast/types/expression-def.js +10 -2
  257. package/dist/lang/ast/types/field-space.d.ts +7 -0
  258. package/dist/lang/ast/types/global-name-space.d.ts +12 -0
  259. package/dist/lang/ast/types/global-name-space.js +51 -0
  260. package/dist/lang/ast/types/malloy-element.d.ts +1 -0
  261. package/dist/lang/ast/types/malloy-element.js +15 -2
  262. package/dist/lang/ast/types/query-property.d.ts +1 -2
  263. package/dist/lang/ast/types/query-property.js +2 -0
  264. package/dist/lang/ast/types/space-entry.d.ts +1 -1
  265. package/dist/lang/ast/types/space-field.d.ts +1 -2
  266. package/dist/lang/ast/types/space-field.js +5 -1
  267. package/dist/lang/ast/types/space-param.d.ts +1 -2
  268. package/dist/lang/ast/types/space-param.js +10 -2
  269. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +138 -135
  270. package/dist/lang/lib/Malloy/MalloyLexer.js +1135 -1103
  271. package/dist/lang/lib/Malloy/MalloyParser.d.ts +252 -275
  272. package/dist/lang/lib/Malloy/MalloyParser.js +1753 -1905
  273. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +40 -103
  274. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +25 -64
  275. package/dist/lang/malloy-to-ast.d.ts +11 -7
  276. package/dist/lang/malloy-to-ast.js +90 -51
  277. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +5 -2
  278. package/dist/lang/test/parse.spec.js +399 -18
  279. package/dist/lang/test/test-translator.d.ts +1 -0
  280. package/dist/lang/test/test-translator.js +5 -0
  281. package/dist/model/malloy_query.d.ts +13 -4
  282. package/dist/model/malloy_query.js +240 -76
  283. package/dist/model/malloy_types.d.ts +89 -18
  284. package/dist/model/malloy_types.js +88 -61
  285. package/dist/model/utils.d.ts +4 -0
  286. package/dist/model/utils.js +118 -1
  287. package/package.json +1 -1
  288. package/dist/lang/ast/types/type-desc.d.ts +0 -8
@@ -0,0 +1,7 @@
1
+ import { DialectFunctionOverloadDef } from './util';
2
+ export declare function fnMinCumulative(): DialectFunctionOverloadDef[];
3
+ export declare function fnMaxCumulative(): DialectFunctionOverloadDef[];
4
+ export declare function fnSumCumulative(): DialectFunctionOverloadDef[];
5
+ export declare function fnMinWindow(): DialectFunctionOverloadDef[];
6
+ export declare function fnMaxWindow(): DialectFunctionOverloadDef[];
7
+ export declare function fnSumWindow(): DialectFunctionOverloadDef[];
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.fnSumWindow = exports.fnMaxWindow = exports.fnMinWindow = exports.fnSumCumulative = exports.fnMaxCumulative = exports.fnMinCumulative = void 0;
26
+ const util_1 = require("./util");
27
+ const types = ['string', 'number', 'timestamp', 'date'];
28
+ function fnMinCumulative() {
29
+ return types.flatMap(type => {
30
+ const value = (0, util_1.makeParam)('value', (0, util_1.output)((0, util_1.maxAggregate)(type)));
31
+ return [
32
+ (0, util_1.overload)((0, util_1.minAnalytic)(type), [value.param], (0, util_1.sql) `MIN(${value.arg})`, {
33
+ needsWindowOrderBy: true,
34
+ }),
35
+ ];
36
+ });
37
+ }
38
+ exports.fnMinCumulative = fnMinCumulative;
39
+ function fnMaxCumulative() {
40
+ return types.flatMap(type => {
41
+ const value = (0, util_1.makeParam)('value', (0, util_1.output)((0, util_1.maxAggregate)(type)));
42
+ return [
43
+ (0, util_1.overload)((0, util_1.minAnalytic)(type), [value.param], (0, util_1.sql) `MAX(${value.arg})`, {
44
+ needsWindowOrderBy: true,
45
+ }),
46
+ ];
47
+ });
48
+ }
49
+ exports.fnMaxCumulative = fnMaxCumulative;
50
+ function fnSumCumulative() {
51
+ return types.flatMap(type => {
52
+ const value = (0, util_1.makeParam)('value', (0, util_1.output)((0, util_1.maxAggregate)(type)));
53
+ return [
54
+ (0, util_1.overload)((0, util_1.minAnalytic)(type), [value.param], (0, util_1.sql) `SUM(${value.arg})`, {
55
+ needsWindowOrderBy: true,
56
+ }),
57
+ ];
58
+ });
59
+ }
60
+ exports.fnSumCumulative = fnSumCumulative;
61
+ function fnMinWindow() {
62
+ return types.flatMap(type => {
63
+ const value = (0, util_1.makeParam)('value', (0, util_1.output)((0, util_1.maxAggregate)(type)));
64
+ return [
65
+ (0, util_1.overload)((0, util_1.minAnalytic)(type), [value.param], (0, util_1.sql) `MIN(${value.arg})`, {
66
+ needsWindowOrderBy: false,
67
+ }),
68
+ ];
69
+ });
70
+ }
71
+ exports.fnMinWindow = fnMinWindow;
72
+ function fnMaxWindow() {
73
+ return types.flatMap(type => {
74
+ const value = (0, util_1.makeParam)('value', (0, util_1.output)((0, util_1.maxAggregate)(type)));
75
+ return [
76
+ (0, util_1.overload)((0, util_1.minAnalytic)(type), [value.param], (0, util_1.sql) `MAX(${value.arg})`, {
77
+ needsWindowOrderBy: false,
78
+ }),
79
+ ];
80
+ });
81
+ }
82
+ exports.fnMaxWindow = fnMaxWindow;
83
+ function fnSumWindow() {
84
+ return types.flatMap(type => {
85
+ const value = (0, util_1.makeParam)('value', (0, util_1.output)((0, util_1.maxAggregate)(type)));
86
+ return [
87
+ (0, util_1.overload)((0, util_1.minAnalytic)(type), [value.param], (0, util_1.sql) `SUM(${value.arg})`, {
88
+ needsWindowOrderBy: false,
89
+ }),
90
+ ];
91
+ });
92
+ }
93
+ exports.fnSumWindow = fnSumWindow;
94
+ //# sourceMappingURL=sum_min_max_window.js.map
@@ -0,0 +1,4 @@
1
+ import { DialectFunctionOverloadDef } from './util';
2
+ export declare const fnTrim: () => DialectFunctionOverloadDef[];
3
+ export declare const fnLtrim: () => DialectFunctionOverloadDef[];
4
+ export declare const fnRtrim: () => DialectFunctionOverloadDef[];
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.fnRtrim = exports.fnLtrim = exports.fnTrim = void 0;
26
+ const util_1 = require("./util");
27
+ function trimFn(fn) {
28
+ return [
29
+ (0, util_1.overload)((0, util_1.minScalar)('number'), [(0, util_1.param)('value', (0, util_1.anyExprType)('string'))], [(0, util_1.sqlFragment)(`${fn}(`, (0, util_1.arg)('value'), ')')]),
30
+ (0, util_1.overload)((0, util_1.minScalar)('number'), [
31
+ (0, util_1.param)('value', (0, util_1.anyExprType)('string')),
32
+ (0, util_1.param)('trim_characters', (0, util_1.anyExprType)('string')),
33
+ ], [(0, util_1.sqlFragment)(`${fn}(`, (0, util_1.arg)('value'), ',', (0, util_1.arg)('trim_characters'), ')')]),
34
+ ];
35
+ }
36
+ const fnTrim = () => trimFn('TRIM');
37
+ exports.fnTrim = fnTrim;
38
+ const fnLtrim = () => trimFn('LTRIM');
39
+ exports.fnLtrim = fnLtrim;
40
+ const fnRtrim = () => trimFn('RTRIM');
41
+ exports.fnRtrim = fnRtrim;
42
+ //# sourceMappingURL=trim_functions.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from './util';
2
+ export declare function fnTrunc(): DialectFunctionOverloadDef[];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.fnTrunc = void 0;
26
+ const util_1 = require("./util");
27
+ function fnTrunc() {
28
+ const value = (0, util_1.makeParam)('value', (0, util_1.anyExprType)('number'));
29
+ // TODO this parameter should only accept integers, but we don't have a good
30
+ // way of expressing that constraint at the moment
31
+ const precision = (0, util_1.makeParam)('precision', (0, util_1.anyExprType)('number'));
32
+ return [
33
+ (0, util_1.overload)((0, util_1.minScalar)('number'), [value.param], (0, util_1.sql) `TRUNC(${value.arg})`),
34
+ (0, util_1.overload)((0, util_1.minScalar)('number'), [value.param, precision.param], (0, util_1.sql) `TRUNC(${value.arg}, ${precision.arg})`),
35
+ ];
36
+ }
37
+ exports.fnTrunc = fnTrunc;
38
+ //# sourceMappingURL=trunc.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from './util';
2
+ export declare function fnUpper(): DialectFunctionOverloadDef[];
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.fnUpper = void 0;
26
+ const util_1 = require("./util");
27
+ function fnUpper() {
28
+ const value = (0, util_1.makeParam)('value', (0, util_1.anyExprType)('string'));
29
+ return [
30
+ (0, util_1.overload)((0, util_1.minScalar)('string'), [value.param], (0, util_1.sql) `UPPER(${value.arg})`),
31
+ ];
32
+ }
33
+ exports.fnUpper = fnUpper;
34
+ //# sourceMappingURL=upper.js.map
@@ -0,0 +1,45 @@
1
+ import { FunctionParameterDef, Fragment, FieldValueType, TypeDesc, Expr, FunctionParamTypeDesc } from '../..';
2
+ export interface DialectFunctionOverloadDef {
3
+ returnType: TypeDesc;
4
+ params: FunctionParameterDef[];
5
+ e: Expr;
6
+ needsWindowOrderBy?: boolean;
7
+ between: {
8
+ preceding: number | string;
9
+ following: number | string;
10
+ } | undefined;
11
+ }
12
+ export declare function arg(name: string): Fragment;
13
+ export declare function spread(f: Fragment): Fragment;
14
+ /**
15
+ * Prefer `sql` when possible.
16
+ */
17
+ export declare function sqlFragment(...e: Expr): Fragment;
18
+ export declare function sql(strings: TemplateStringsArray, ...expr: (Fragment | string)[]): Expr;
19
+ export declare function constant(type: TypeDesc): TypeDesc;
20
+ export declare function output(type: TypeDesc): TypeDesc;
21
+ export declare function literal(type: TypeDesc): TypeDesc;
22
+ export declare function params(name: string, ...allowedTypes: FunctionParamTypeDesc[]): FunctionParameterDef;
23
+ /**
24
+ * Prefer `makeParam` for future function definitions
25
+ */
26
+ export declare function param(name: string, ...allowedTypes: FunctionParamTypeDesc[]): FunctionParameterDef;
27
+ export declare function makeParam(name: string, ...allowedTypes: FunctionParamTypeDesc[]): {
28
+ param: FunctionParameterDef;
29
+ arg: Fragment;
30
+ };
31
+ export declare function maxScalar(dataType: FieldValueType): TypeDesc;
32
+ export declare function maxAggregate(dataType: FieldValueType): TypeDesc;
33
+ export declare function anyExprType(dataType: FieldValueType): FunctionParamTypeDesc;
34
+ export declare function maxUngroupedAggregate(dataType: FieldValueType): FunctionParamTypeDesc;
35
+ export declare function maxAnalytic(dataType: FieldValueType): FunctionParamTypeDesc;
36
+ export declare function minScalar(dataType: FieldValueType): TypeDesc;
37
+ export declare function minAggregate(dataType: FieldValueType): TypeDesc;
38
+ export declare function minAnalytic(dataType: FieldValueType): TypeDesc;
39
+ export declare function overload(returnType: TypeDesc, params: FunctionParameterDef[], e: Expr, options?: {
40
+ needsWindowOrderBy?: boolean;
41
+ between?: {
42
+ preceding: number | string;
43
+ following: number | string;
44
+ };
45
+ }): DialectFunctionOverloadDef;
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.overload = exports.minAnalytic = exports.minAggregate = exports.minScalar = exports.maxAnalytic = exports.maxUngroupedAggregate = exports.anyExprType = exports.maxAggregate = exports.maxScalar = exports.makeParam = exports.param = exports.params = exports.literal = exports.output = exports.constant = exports.sql = exports.sqlFragment = exports.spread = exports.arg = void 0;
26
+ function arg(name) {
27
+ return {
28
+ type: 'function_parameter',
29
+ name,
30
+ };
31
+ }
32
+ exports.arg = arg;
33
+ function spread(f) {
34
+ return {
35
+ type: 'spread',
36
+ e: [f],
37
+ };
38
+ }
39
+ exports.spread = spread;
40
+ /**
41
+ * Prefer `sql` when possible.
42
+ */
43
+ function sqlFragment(...e) {
44
+ return {
45
+ type: 'sql_expression',
46
+ e,
47
+ };
48
+ }
49
+ exports.sqlFragment = sqlFragment;
50
+ function sql(strings, ...expr) {
51
+ return [
52
+ {
53
+ type: 'sql_expression',
54
+ e: interpolate([...strings], expr),
55
+ },
56
+ ];
57
+ }
58
+ exports.sql = sql;
59
+ function interpolate(outer, inner) {
60
+ const result = [];
61
+ for (let i = 0; i < outer.length; i++) {
62
+ result.push(outer[i]);
63
+ if (i < inner.length) {
64
+ result.push(inner[i]);
65
+ }
66
+ }
67
+ return result;
68
+ }
69
+ function constant(type) {
70
+ return {
71
+ ...type,
72
+ evalSpace: 'constant',
73
+ };
74
+ }
75
+ exports.constant = constant;
76
+ function output(type) {
77
+ return {
78
+ ...type,
79
+ evalSpace: 'output',
80
+ };
81
+ }
82
+ exports.output = output;
83
+ function literal(type) {
84
+ return {
85
+ ...type,
86
+ evalSpace: 'literal',
87
+ };
88
+ }
89
+ exports.literal = literal;
90
+ function params(name, ...allowedTypes) {
91
+ return {
92
+ name,
93
+ isVariadic: true,
94
+ allowedTypes,
95
+ };
96
+ }
97
+ exports.params = params;
98
+ /**
99
+ * Prefer `makeParam` for future function definitions
100
+ */
101
+ function param(name, ...allowedTypes) {
102
+ return {
103
+ name,
104
+ isVariadic: false,
105
+ allowedTypes,
106
+ };
107
+ }
108
+ exports.param = param;
109
+ function makeParam(name, ...allowedTypes) {
110
+ return { param: param(name, ...allowedTypes), arg: arg(name) };
111
+ }
112
+ exports.makeParam = makeParam;
113
+ function maxScalar(dataType) {
114
+ return {
115
+ dataType,
116
+ expressionType: 'scalar',
117
+ evalSpace: 'input',
118
+ };
119
+ }
120
+ exports.maxScalar = maxScalar;
121
+ function maxAggregate(dataType) {
122
+ return {
123
+ dataType,
124
+ expressionType: 'aggregate',
125
+ evalSpace: 'input',
126
+ };
127
+ }
128
+ exports.maxAggregate = maxAggregate;
129
+ function anyExprType(dataType) {
130
+ return {
131
+ dataType,
132
+ expressionType: undefined,
133
+ evalSpace: 'input',
134
+ };
135
+ }
136
+ exports.anyExprType = anyExprType;
137
+ function maxUngroupedAggregate(dataType) {
138
+ return {
139
+ dataType,
140
+ expressionType: 'ungrouped_aggregate',
141
+ evalSpace: 'input',
142
+ };
143
+ }
144
+ exports.maxUngroupedAggregate = maxUngroupedAggregate;
145
+ function maxAnalytic(dataType) {
146
+ return {
147
+ dataType,
148
+ expressionType: 'aggregate_analytic',
149
+ evalSpace: 'input',
150
+ };
151
+ }
152
+ exports.maxAnalytic = maxAnalytic;
153
+ function minScalar(dataType) {
154
+ return {
155
+ dataType,
156
+ expressionType: 'scalar',
157
+ evalSpace: 'input',
158
+ };
159
+ }
160
+ exports.minScalar = minScalar;
161
+ function minAggregate(dataType) {
162
+ return {
163
+ dataType,
164
+ expressionType: 'aggregate',
165
+ evalSpace: 'input',
166
+ };
167
+ }
168
+ exports.minAggregate = minAggregate;
169
+ function minAnalytic(dataType) {
170
+ return {
171
+ dataType,
172
+ expressionType: 'scalar_analytic',
173
+ evalSpace: 'input',
174
+ };
175
+ }
176
+ exports.minAnalytic = minAnalytic;
177
+ function overload(returnType, params, e, options) {
178
+ return {
179
+ returnType,
180
+ params,
181
+ e,
182
+ needsWindowOrderBy: options === null || options === void 0 ? void 0 : options.needsWindowOrderBy,
183
+ between: options === null || options === void 0 ? void 0 : options.between,
184
+ };
185
+ }
186
+ exports.overload = overload;
187
+ //# sourceMappingURL=util.js.map
@@ -3,4 +3,4 @@ export type { DialectFieldList } from './dialect';
3
3
  export { StandardSQLDialect } from './standardsql';
4
4
  export { PostgresDialect } from './postgres';
5
5
  export { DuckDBDialect } from './duckdb';
6
- export { getDialect, registerDialect } from './dialect_map';
6
+ export { getDialect, registerDialect, getDialectFunction } from './dialect_map';
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.registerDialect = exports.getDialect = exports.DuckDBDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.Dialect = void 0;
25
+ exports.getDialectFunction = exports.registerDialect = exports.getDialect = exports.DuckDBDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.Dialect = void 0;
26
26
  var dialect_1 = require("./dialect");
27
27
  Object.defineProperty(exports, "Dialect", { enumerable: true, get: function () { return dialect_1.Dialect; } });
28
28
  var standardsql_1 = require("./standardsql");
@@ -34,4 +34,5 @@ Object.defineProperty(exports, "DuckDBDialect", { enumerable: true, get: functio
34
34
  var dialect_map_1 = require("./dialect_map");
35
35
  Object.defineProperty(exports, "getDialect", { enumerable: true, get: function () { return dialect_map_1.getDialect; } });
36
36
  Object.defineProperty(exports, "registerDialect", { enumerable: true, get: function () { return dialect_map_1.registerDialect; } });
37
+ Object.defineProperty(exports, "getDialectFunction", { enumerable: true, get: function () { return dialect_map_1.getDialectFunction; } });
37
38
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnByteLength(): DialectFunctionOverloadDef[];
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.fnByteLength = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnByteLength() {
28
+ return [
29
+ (0, util_1.overload)((0, util_1.minScalar)('number'), [(0, util_1.param)('value', (0, util_1.anyExprType)('string'))], (0, util_1.sql) `OCTET_LENGTH(${(0, util_1.arg)('value')})`),
30
+ ];
31
+ }
32
+ exports.fnByteLength = fnByteLength;
33
+ //# sourceMappingURL=byte_length.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnEndsWith(): DialectFunctionOverloadDef[];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.fnEndsWith = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnEndsWith() {
28
+ const value = (0, util_1.makeParam)('value', (0, util_1.anyExprType)('string'));
29
+ const suffix = (0, util_1.makeParam)('suffix', (0, util_1.anyExprType)('string'));
30
+ return [
31
+ (0, util_1.overload)((0, util_1.minScalar)('boolean'), [value.param, suffix.param],
32
+ // There's no ENDS_WITH function in Postgres, so we do a hacky check that the last
33
+ // N characters, where N is the length of the suffix, are equal to the suffix.
34
+ (0, util_1.sql) `COALESCE(RIGHT(${value.arg}, LENGTH(${suffix.arg})) = ${suffix.arg}, false)`),
35
+ ];
36
+ }
37
+ exports.fnEndsWith = fnEndsWith;
38
+ //# sourceMappingURL=ends_with.js.map
@@ -0,0 +1,3 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare const fnGreatest: () => DialectFunctionOverloadDef[];
3
+ export declare const fnLeast: () => DialectFunctionOverloadDef[];
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.fnLeast = exports.fnGreatest = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ const types = [
28
+ 'string',
29
+ 'number',
30
+ 'timestamp',
31
+ 'date',
32
+ 'json',
33
+ ];
34
+ function greatestOrLeast(fn) {
35
+ return types.map(type => (0, util_1.overload)((0, util_1.minScalar)(type), [(0, util_1.params)('values', (0, util_1.anyExprType)(type))],
36
+ // We match BigQuery null behavior here -- if any argument is null, return null
37
+ [
38
+ (0, util_1.sqlFragment)('CASE WHEN NUM_NULLS(', (0, util_1.spread)((0, util_1.arg)('values')), `) > 0 THEN NULL ELSE ${fn}(`, (0, util_1.spread)((0, util_1.arg)('values')), ') END'),
39
+ ]));
40
+ }
41
+ const fnGreatest = () => greatestOrLeast('GREATEST');
42
+ exports.fnGreatest = fnGreatest;
43
+ const fnLeast = () => greatestOrLeast('LEAST');
44
+ exports.fnLeast = fnLeast;
45
+ //# sourceMappingURL=greatest_and_least.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnIfnull(): DialectFunctionOverloadDef[];
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.fnIfnull = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ const types = [
28
+ 'string',
29
+ 'number',
30
+ 'timestamp',
31
+ 'date',
32
+ 'json',
33
+ ];
34
+ function fnIfnull() {
35
+ return types.map(type => (0, util_1.overload)((0, util_1.minScalar)(type), [(0, util_1.param)('value', (0, util_1.anyExprType)(type)), (0, util_1.param)('default', (0, util_1.anyExprType)(type))],
36
+ // Postgres doesn't have an IFNULL function, so we use COALESCE, which is equivalent.
37
+ (0, util_1.sql) `COALESCE(${(0, util_1.arg)('value')}, ${(0, util_1.arg)('default')})`));
38
+ }
39
+ exports.fnIfnull = fnIfnull;
40
+ //# sourceMappingURL=ifnull.js.map