@malloydata/malloy 0.0.38 → 0.0.39-dev230613185207

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
@@ -1,4 +1,5 @@
1
- import { AtomicFieldType as AtomicFieldTypeInner, DialectFragment, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from '../model/malloy_types';
1
+ import { DialectFragment, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from '../model/malloy_types';
2
+ import { DialectFunctionOverloadDef } from './functions';
2
3
  interface DialectField {
3
4
  type: string;
4
5
  sqlExpression: string;
@@ -18,14 +19,6 @@ export interface QueryInfo {
18
19
  export declare const dayIndex: number;
19
20
  export declare function inDays(units: string): boolean;
20
21
  export declare function qtz(qi: QueryInfo): string | undefined;
21
- /**
22
- * Someday this might be used to control how a function call in malloy is
23
- * translated into a function call in SQL. Today this is just so that
24
- * the expression compiler can know the output type of a function.
25
- */
26
- export interface FunctionInfo {
27
- returnType: AtomicFieldTypeInner;
28
- }
29
22
  export declare type DialectFieldList = DialectField[];
30
23
  export declare abstract class Dialect {
31
24
  abstract name: string;
@@ -36,12 +29,13 @@ export declare abstract class Dialect {
36
29
  abstract divisionIsInteger: boolean;
37
30
  abstract supportsSumDistinctFunction: boolean;
38
31
  abstract unnestWithNumbers: boolean;
39
- protected abstract functionInfo: Record<string, FunctionInfo>;
40
32
  abstract defaultSampling: Sampling;
33
+ abstract supportsAggDistinct: boolean;
41
34
  abstract supportUnnestArrayAgg: boolean;
42
35
  abstract supportsCTEinCoorelatedSubQueries: boolean;
43
36
  abstract dontUnionIndex: boolean;
44
37
  abstract supportsQualify: boolean;
38
+ abstract getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
45
39
  abstract quoteTablePath(tablePath: string): string;
46
40
  abstract sqlGroupSetTable(groupSetCount: number): string;
47
41
  abstract sqlAnyValue(groupSet: number, fieldName: string): string;
@@ -69,11 +63,13 @@ export declare abstract class Dialect {
69
63
  ignoreInProject(_fieldName: string): boolean;
70
64
  abstract sqlCast(qi: QueryInfo, cast: TypecastFragment): Expr;
71
65
  abstract sqlLiteralTime(qi: QueryInfo, timeString: string, type: TimeFieldType, timezone?: string): string;
72
- abstract sqlLiteralString(literak: string): string;
73
- abstract sqlRegexpMatch(expr: Expr, regex: string): Expr;
74
- getFunctionInfo(functionName: string): FunctionInfo | undefined;
66
+ abstract sqlLiteralString(literal: string): string;
67
+ abstract sqlLiteralRegexp(literal: string): string;
68
+ abstract sqlRegexpMatch(expr: Expr, regex: Expr): Expr;
69
+ sqlLiteralNumber(literal: string): string;
75
70
  dialectExpr(qi: QueryInfo, df: DialectFragment): Expr;
76
71
  sqlSumDistinct(_key: string, _value: string, _funcName: string): string;
72
+ sqlAggDistinct(_key: string, _values: string[], _func: (valNames: string[]) => string): string;
77
73
  sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
78
74
  sqlOrderBy(orderTerms: string[]): string;
79
75
  sqlTzStr(qi: QueryInfo): string;
@@ -64,8 +64,8 @@ class Dialect {
64
64
  ignoreInProject(_fieldName) {
65
65
  return false;
66
66
  }
67
- getFunctionInfo(functionName) {
68
- return this.functionInfo[functionName.toLowerCase()];
67
+ sqlLiteralNumber(literal) {
68
+ return literal;
69
69
  }
70
70
  dialectExpr(qi, df) {
71
71
  switch (df.function) {
@@ -96,10 +96,23 @@ class Dialect {
96
96
  }
97
97
  case 'stringLiteral':
98
98
  return [this.sqlLiteralString(df.literal)];
99
+ case 'numberLiteral':
100
+ return [this.sqlLiteralNumber(df.literal)];
101
+ case 'regexpLiteral':
102
+ return [this.sqlLiteralRegexp(df.literal)];
99
103
  }
100
104
  }
101
105
  sqlSumDistinct(_key, _value, _funcName) {
102
- return 'sqlSumDistinct called bu not implemented';
106
+ return 'sqlSumDistinct called but not implemented';
107
+ }
108
+ // Like sqlSumDistinct, but for an arbitrary aggregate expression
109
+ sqlAggDistinct(_key, _values,
110
+ // A function which takes the value names used internally and produces the SQL operation using those
111
+ // value names.
112
+ // TODO maybe this should be flipped around and the SQL should be passed in directly along with the
113
+ // value names used?
114
+ _func) {
115
+ return 'sqlAggDistinct called but not implemented';
103
116
  }
104
117
  sqlSampleTable(tableSQL, sample) {
105
118
  if (sample !== undefined) {
@@ -1,3 +1,5 @@
1
1
  import { Dialect } from './dialect';
2
+ import { FunctionDef } from '../model';
2
3
  export declare function getDialect(name: string): Dialect;
3
4
  export declare function registerDialect(d: Dialect): void;
5
+ export declare function getDialectFunction(name: string): FunctionDef | undefined;
@@ -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 = void 0;
25
+ exports.getDialectFunction = exports.registerDialect = exports.getDialect = void 0;
26
26
  const duckdb_1 = require("./duckdb");
27
27
  const postgres_1 = require("./postgres");
28
28
  const standardsql_1 = require("./standardsql");
@@ -42,4 +42,64 @@ exports.registerDialect = registerDialect;
42
42
  registerDialect(new postgres_1.PostgresDialect());
43
43
  registerDialect(new standardsql_1.StandardSQLDialect());
44
44
  registerDialect(new duckdb_1.DuckDBDialect());
45
+ function paramsEqual(a, b) {
46
+ return (a.params.length === b.params.length &&
47
+ a.params.every((param, i) => {
48
+ const otherParam = b.params[i];
49
+ return (param.isVariadic === otherParam.isVariadic &&
50
+ param.name === otherParam.name &&
51
+ param.allowedTypes.length === otherParam.allowedTypes.length &&
52
+ param.allowedTypes.every(t => otherParam.allowedTypes.some(ot => t.dataType === ot.dataType &&
53
+ t.expressionType === ot.expressionType)));
54
+ }));
55
+ }
56
+ function paramsCompatible(a, b) {
57
+ // TODO detect when parameters are not exactly equal, but would cause collision issues...
58
+ return paramsEqual(a, b);
59
+ }
60
+ function returnEqual(a, b) {
61
+ return (a.returnType.dataType === b.returnType.dataType &&
62
+ a.returnType.expressionType === b.returnType.expressionType);
63
+ }
64
+ function getDialectFunction(name) {
65
+ const func = {
66
+ type: 'function',
67
+ name,
68
+ overloads: [],
69
+ };
70
+ let found = false;
71
+ for (const dialect of dialectMap.values()) {
72
+ const overloads = dialect.getGlobalFunctionDef(name);
73
+ if (overloads) {
74
+ for (const overload of overloads) {
75
+ let handled = false;
76
+ for (const existingOverload of func.overloads) {
77
+ if (!paramsCompatible(overload, existingOverload)) {
78
+ continue;
79
+ }
80
+ if (!paramsEqual(overload, existingOverload)) {
81
+ throw new Error('params are compatible but not equal');
82
+ }
83
+ if (!returnEqual(overload, existingOverload)) {
84
+ throw new Error('params match but return types differ!');
85
+ }
86
+ existingOverload.dialect[dialect.name] = overload.e;
87
+ handled = true;
88
+ }
89
+ if (!handled) {
90
+ func.overloads.push({
91
+ returnType: overload.returnType,
92
+ params: overload.params,
93
+ dialect: { [dialect.name]: overload.e },
94
+ needsWindowOrderBy: overload.needsWindowOrderBy,
95
+ between: overload.between,
96
+ });
97
+ }
98
+ }
99
+ found = true;
100
+ }
101
+ }
102
+ return found ? func : undefined;
103
+ }
104
+ exports.getDialectFunction = getDialectFunction;
45
105
  //# sourceMappingURL=dialect_map.js.map
@@ -1,5 +1,6 @@
1
- import { DateUnit, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from '../model/malloy_types';
2
- import { Dialect, DialectFieldList, FunctionInfo, QueryInfo } from './dialect';
1
+ import { DateUnit, Expr, ExtractUnit, Sampling, StructDef, TimeFieldType, TimeValue, TimestampUnit, TypecastFragment } from '../../model/malloy_types';
2
+ import { DialectFunctionOverloadDef } from '../functions';
3
+ import { Dialect, DialectFieldList, QueryInfo } from '../dialect';
3
4
  export declare class DuckDBDialect extends Dialect {
4
5
  name: string;
5
6
  defaultNumberType: string;
@@ -12,10 +13,10 @@ export declare class DuckDBDialect extends Dialect {
12
13
  rows: number;
13
14
  };
14
15
  supportUnnestArrayAgg: boolean;
16
+ supportsAggDistinct: boolean;
15
17
  supportsCTEinCoorelatedSubQueries: boolean;
16
18
  dontUnionIndex: boolean;
17
19
  supportsQualify: boolean;
18
- functionInfo: Record<string, FunctionInfo>;
19
20
  get udfPrefix(): string;
20
21
  quoteTablePath(tableName: string): string;
21
22
  sqlGroupSetTable(groupSetCount: number): string;
@@ -36,17 +37,19 @@ export declare class DuckDBDialect extends Dialect {
36
37
  sqlSelectAliasAsStruct(alias: string, physicalFieldNames: string[]): string;
37
38
  sqlMaybeQuoteIdentifier(identifier: string): string;
38
39
  sqlCreateTableAsSelect(_tableName: string, _sql: string): string;
39
- getFunctionInfo(functionName: string): FunctionInfo | undefined;
40
40
  sqlMeasureTime(from: TimeValue, to: TimeValue, units: string): Expr;
41
41
  sqlNow(): Expr;
42
42
  sqlTrunc(qi: QueryInfo, sqlTime: TimeValue, units: TimestampUnit): Expr;
43
43
  sqlExtract(qi: QueryInfo, from: TimeValue, units: ExtractUnit): Expr;
44
44
  sqlAlterTime(op: '+' | '-', expr: TimeValue, n: Expr, timeframe: DateUnit): Expr;
45
45
  sqlCast(qi: QueryInfo, cast: TypecastFragment): Expr;
46
- sqlRegexpMatch(expr: Expr, regexp: string): Expr;
46
+ sqlRegexpMatch(expr: Expr, regexp: Expr): Expr;
47
47
  sqlLiteralTime(qi: QueryInfo, timeString: string, type: TimeFieldType, timezone: string | undefined): string;
48
48
  sqlSumDistinct(key: string, value: string, funcName: string): string;
49
+ sqlAggDistinct(key: string, values: string[], func: (valNames: string[]) => string): string;
49
50
  sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
50
51
  sqlOrderBy(orderTerms: string[]): string;
51
52
  sqlLiteralString(literal: string): string;
53
+ sqlLiteralRegexp(literal: string): string;
54
+ getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
52
55
  }
@@ -23,9 +23,10 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.DuckDBDialect = void 0;
26
- const malloy_types_1 = require("../model/malloy_types");
27
- const utils_1 = require("../model/utils");
28
- const dialect_1 = require("./dialect");
26
+ const malloy_types_1 = require("../../model/malloy_types");
27
+ const utils_1 = require("../../model/utils");
28
+ const functions_1 = require("./functions");
29
+ const dialect_1 = require("../dialect");
29
30
  // need to refactor runSQL to take a SQLBlock instead of just a sql string.
30
31
  const hackSplitComment = '-- hack: split on this';
31
32
  const castMap = {
@@ -48,12 +49,10 @@ class DuckDBDialect extends dialect_1.Dialect {
48
49
  this.unnestWithNumbers = true;
49
50
  this.defaultSampling = { rows: 50000 };
50
51
  this.supportUnnestArrayAgg = true;
52
+ this.supportsAggDistinct = true;
51
53
  this.supportsCTEinCoorelatedSubQueries = true;
52
54
  this.dontUnionIndex = true;
53
55
  this.supportsQualify = true;
54
- this.functionInfo = {
55
- 'concat': { returnType: 'string' },
56
- };
57
56
  }
58
57
  // hack until they support temporary macros.
59
58
  get udfPrefix() {
@@ -187,9 +186,6 @@ class DuckDBDialect extends dialect_1.Dialect {
187
186
  sqlCreateTableAsSelect(_tableName, _sql) {
188
187
  throw new Error('Not implemented Yet');
189
188
  }
190
- getFunctionInfo(functionName) {
191
- return this.functionInfo[functionName];
192
- }
193
189
  sqlMeasureTime(from, to, units) {
194
190
  let lVal = from.value;
195
191
  let rVal = to.value;
@@ -291,6 +287,16 @@ class DuckDBDialect extends dialect_1.Dialect {
291
287
  )
292
288
  )`;
293
289
  }
290
+ sqlAggDistinct(key, values, func) {
291
+ return `(
292
+ SELECT ${func(values.map((v, i) => `a.val${i}`))} as value
293
+ FROM (
294
+ SELECT UNNEST(list(distinct {key:${key}, ${values
295
+ .map((v, i) => `val${i}: ${v}`)
296
+ .join(',')}})) a
297
+ )
298
+ )`;
299
+ }
294
300
  // sqlSumDistinct(key: string, value: string): string {
295
301
  // const _factor = 32;
296
302
  // const precision = 0.000001;
@@ -320,6 +326,12 @@ class DuckDBDialect extends dialect_1.Dialect {
320
326
  sqlLiteralString(literal) {
321
327
  return "'" + literal.replace(/'/g, "''") + "'";
322
328
  }
329
+ sqlLiteralRegexp(literal) {
330
+ return "'" + literal.replace(/'/g, "''") + "'";
331
+ }
332
+ getGlobalFunctionDef(name) {
333
+ return functions_1.DUCKDB_FUNCTIONS.get(name);
334
+ }
323
335
  }
324
336
  exports.DuckDBDialect = DuckDBDialect;
325
337
  //# sourceMappingURL=duckdb.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) `(BIT_LENGTH(${(0, util_1.arg)('value')}) / 8)`),
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 fnDiv(): 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.fnDiv = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnDiv() {
28
+ const dividend = (0, util_1.makeParam)('dividend', (0, util_1.anyExprType)('number'));
29
+ const divisor = (0, util_1.makeParam)('divisor', (0, util_1.anyExprType)('number'));
30
+ return [
31
+ (0, util_1.overload)((0, util_1.minScalar)('number'), [dividend.param, divisor.param],
32
+ // TODO In DuckDB 0.8 there is a new // operator which does integer division.
33
+ // When we upgrade, we should switch this to use that instead.
34
+ (0, util_1.sql) `CASE WHEN ${dividend.arg} / ${divisor.arg} < 0 THEN CEIL(${dividend.arg} / ${divisor.arg}) ELSE FLOOR(${dividend.arg} / ${divisor.arg}) END`),
35
+ ];
36
+ }
37
+ exports.fnDiv = fnDiv;
38
+ //# sourceMappingURL=div.js.map
@@ -0,0 +1 @@
1
+ export declare const DUCKDB_FUNCTIONS: import("../../functions/function_map").FunctionMap;
@@ -0,0 +1,52 @@
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.DUCKDB_FUNCTIONS = void 0;
26
+ const functions_1 = require("../../functions");
27
+ const byte_length_1 = require("./byte_length");
28
+ const div_1 = require("./div");
29
+ const ends_with_1 = require("./ends_with");
30
+ const greatest_and_least_1 = require("./greatest_and_least");
31
+ const is_inf_1 = require("./is_inf");
32
+ const is_nan_1 = require("./is_nan");
33
+ const log_1 = require("./log");
34
+ const rand_1 = require("./rand");
35
+ const replace_1 = require("./replace");
36
+ const trunc_1 = require("./trunc");
37
+ const unicode_1 = require("./unicode");
38
+ exports.DUCKDB_FUNCTIONS = functions_1.FUNCTIONS.clone();
39
+ exports.DUCKDB_FUNCTIONS.add('trunc', trunc_1.fnTrunc);
40
+ exports.DUCKDB_FUNCTIONS.add('rand', rand_1.fnRand);
41
+ exports.DUCKDB_FUNCTIONS.add('is_nan', is_nan_1.fnIsNan);
42
+ exports.DUCKDB_FUNCTIONS.add('is_inf', is_inf_1.fnIsInf);
43
+ exports.DUCKDB_FUNCTIONS.add('greatest', greatest_and_least_1.fnGreatest);
44
+ exports.DUCKDB_FUNCTIONS.add('least', greatest_and_least_1.fnLeast);
45
+ exports.DUCKDB_FUNCTIONS.add('div', div_1.fnDiv);
46
+ exports.DUCKDB_FUNCTIONS.add('byte_length', byte_length_1.fnByteLength);
47
+ exports.DUCKDB_FUNCTIONS.add('unicode', unicode_1.fnUnicode);
48
+ exports.DUCKDB_FUNCTIONS.add('replace', replace_1.fnReplace);
49
+ exports.DUCKDB_FUNCTIONS.add('ends_with', ends_with_1.fnEndsWith);
50
+ exports.DUCKDB_FUNCTIONS.add('log', log_1.fnLog);
51
+ exports.DUCKDB_FUNCTIONS.seal();
52
+ //# sourceMappingURL=duckdb_functions.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnEndsWith(): DialectFunctionOverloadDef[];
@@ -0,0 +1,35 @@
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], (0, util_1.sql) `COALESCE(SUFFIX(${value.arg}, ${suffix.arg}), false)`),
32
+ ];
33
+ }
34
+ exports.fnEndsWith = fnEndsWith;
35
+ //# 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,58 @@
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
+ // TODO create a way for a function spec to map SQL to each arg before spreading, or something like that
37
+ // Currently this SQL is pretty nasty, and we would rather write
38
+ // CASE WHEN arg1 IS NULL OR arg2 is NULL ... OR argN is NULL THEN NULL ELSE GREATEST(arg1, arg2, ..., argN) END
39
+ // But we can't do that with today's function spec.
40
+ // That might look someday like
41
+ /*
42
+ sqlFragment(
43
+ 'CASE WHEN ',
44
+ spread(map(arg('values'), '$ARG IS NULL'), ' OR '),
45
+ `THEN NULL ELSE ${fn}(`,
46
+ spread(arg('values')),
47
+ ') END'
48
+ ),
49
+ */
50
+ [
51
+ (0, util_1.sqlFragment)('CASE WHEN LEN(LIST_FILTER([', (0, util_1.spread)((0, util_1.arg)('values')), `], x -> x is null)) > 0 THEN NULL ELSE ${fn}(`, (0, util_1.spread)((0, util_1.arg)('values')), ') END'),
52
+ ]));
53
+ }
54
+ const fnGreatest = () => greatestOrLeast('GREATEST');
55
+ exports.fnGreatest = fnGreatest;
56
+ const fnLeast = () => greatestOrLeast('LEAST');
57
+ exports.fnLeast = fnLeast;
58
+ //# sourceMappingURL=greatest_and_least.js.map
@@ -0,0 +1 @@
1
+ export { DUCKDB_FUNCTIONS } from './duckdb_functions';
@@ -0,0 +1,28 @@
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.DUCKDB_FUNCTIONS = void 0;
26
+ var duckdb_functions_1 = require("./duckdb_functions");
27
+ Object.defineProperty(exports, "DUCKDB_FUNCTIONS", { enumerable: true, get: function () { return duckdb_functions_1.DUCKDB_FUNCTIONS; } });
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnIsInf(): 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.fnIsInf = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnIsInf() {
28
+ return [
29
+ (0, util_1.overload)((0, util_1.minScalar)('boolean'), [(0, util_1.param)('value', (0, util_1.anyExprType)('number'))], (0, util_1.sql) `COALESCE(ISINF(${(0, util_1.arg)('value')}), false)`),
30
+ ];
31
+ }
32
+ exports.fnIsInf = fnIsInf;
33
+ //# sourceMappingURL=is_inf.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnIsNan(): 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.fnIsNan = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnIsNan() {
28
+ return [
29
+ (0, util_1.overload)((0, util_1.minScalar)('boolean'), [(0, util_1.param)('value', (0, util_1.anyExprType)('number'))], (0, util_1.sql) `COALESCE(ISNAN(${(0, util_1.arg)('value')}), false)`),
30
+ ];
31
+ }
32
+ exports.fnIsNan = fnIsNan;
33
+ //# sourceMappingURL=is_nan.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnLog(): DialectFunctionOverloadDef[];