@uwdata/mosaic-sql 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mosaic-sql.js +2242 -1064
- package/dist/mosaic-sql.min.js +1 -1
- package/dist/types/ast/aggregate.d.ts +70 -0
- package/dist/types/ast/between-op.d.ts +46 -0
- package/dist/types/ast/binary-op.d.ts +28 -0
- package/dist/types/ast/case.d.ts +68 -0
- package/dist/types/ast/cast.d.ts +21 -0
- package/dist/types/ast/column-param.d.ts +17 -0
- package/dist/types/ast/column-ref.d.ts +39 -0
- package/dist/types/ast/fragment.d.ts +14 -0
- package/dist/types/ast/from.d.ts +21 -0
- package/dist/types/ast/function.d.ts +21 -0
- package/dist/types/ast/in-op.d.ts +21 -0
- package/dist/types/ast/interval.d.ts +21 -0
- package/dist/types/ast/literal.d.ts +15 -0
- package/dist/types/ast/logical-op.d.ts +46 -0
- package/dist/types/ast/node.d.ts +24 -0
- package/dist/types/ast/order-by.d.ts +29 -0
- package/dist/types/ast/param.d.ts +19 -0
- package/dist/types/ast/query.d.ts +268 -0
- package/dist/types/ast/sample.d.ts +42 -0
- package/dist/types/ast/select.d.ts +22 -0
- package/dist/types/ast/table-ref.d.ts +25 -0
- package/dist/types/ast/unary-op.d.ts +39 -0
- package/dist/types/ast/verbatim.d.ts +9 -0
- package/dist/types/ast/window.d.ts +177 -0
- package/dist/types/ast/with.d.ts +22 -0
- package/dist/types/constants.d.ts +38 -0
- package/dist/types/functions/aggregate.d.ts +229 -0
- package/dist/types/functions/case.d.ts +15 -0
- package/dist/types/functions/cast.d.ts +26 -0
- package/dist/types/functions/column.d.ts +9 -0
- package/dist/types/functions/datetime.d.ts +44 -0
- package/dist/types/functions/literal.d.ts +16 -0
- package/dist/types/functions/numeric.d.ts +93 -0
- package/dist/types/functions/operators.d.ts +198 -0
- package/dist/types/functions/order-by.d.ts +17 -0
- package/dist/types/functions/spatial.d.ts +37 -0
- package/dist/types/functions/sql-template-tag.d.ts +16 -0
- package/dist/types/functions/string.d.ts +55 -0
- package/dist/types/functions/table-ref.d.ts +9 -0
- package/dist/types/functions/window.d.ts +87 -0
- package/dist/types/index-types.d.ts +2 -0
- package/dist/types/index.d.ts +53 -0
- package/dist/types/load/create.d.ts +8 -0
- package/dist/types/load/extension.d.ts +1 -0
- package/dist/types/load/load.d.ts +12 -0
- package/dist/types/load/sql-from.d.ts +11 -0
- package/dist/types/transforms/bin-1d.d.ts +14 -0
- package/dist/types/transforms/bin-2d.d.ts +18 -0
- package/dist/types/transforms/bin-linear-1d.d.ts +9 -0
- package/dist/types/transforms/bin-linear-2d.d.ts +18 -0
- package/dist/types/transforms/line-density.d.ts +23 -0
- package/dist/types/transforms/m4.d.ts +18 -0
- package/dist/types/transforms/scales.d.ts +1 -0
- package/dist/types/types.d.ts +59 -0
- package/dist/types/util/ast.d.ts +60 -0
- package/dist/types/util/function.d.ts +54 -0
- package/dist/types/util/string.d.ts +3 -0
- package/dist/types/util/type-check.d.ts +18 -0
- package/dist/types/visit/recurse.d.ts +28 -0
- package/dist/types/visit/rewrite.d.ts +10 -0
- package/dist/types/visit/visitors.d.ts +33 -0
- package/dist/types/visit/walk.d.ts +7 -0
- package/jsconfig.json +11 -0
- package/package.json +6 -4
- package/src/ast/aggregate.js +164 -0
- package/src/ast/between-op.js +75 -0
- package/src/ast/binary-op.js +40 -0
- package/src/ast/case.js +105 -0
- package/src/ast/cast.js +34 -0
- package/src/ast/column-param.js +29 -0
- package/src/ast/column-ref.js +72 -0
- package/src/ast/fragment.js +26 -0
- package/src/ast/from.js +40 -0
- package/src/ast/function.js +34 -0
- package/src/ast/in-op.js +33 -0
- package/src/ast/interval.js +33 -0
- package/src/ast/literal.js +55 -0
- package/src/ast/logical-op.js +67 -0
- package/src/ast/node.js +29 -0
- package/src/ast/order-by.js +48 -0
- package/src/ast/param.js +35 -0
- package/src/ast/query.js +578 -0
- package/src/ast/sample.js +53 -0
- package/src/ast/select.js +44 -0
- package/src/ast/table-ref.js +44 -0
- package/src/ast/unary-op.js +64 -0
- package/src/ast/verbatim.js +26 -0
- package/src/ast/window.js +290 -0
- package/src/ast/with.js +30 -0
- package/src/constants.js +44 -0
- package/src/functions/aggregate.js +335 -0
- package/src/functions/case.js +21 -0
- package/src/functions/cast.js +39 -0
- package/src/functions/column.js +20 -0
- package/src/functions/datetime.js +65 -0
- package/src/functions/literal.js +22 -0
- package/src/functions/numeric.js +139 -0
- package/src/functions/operators.js +298 -0
- package/src/functions/order-by.js +24 -0
- package/src/functions/spatial.js +56 -0
- package/src/functions/sql-template-tag.js +51 -0
- package/src/functions/string.js +82 -0
- package/src/functions/table-ref.js +14 -0
- package/src/functions/window.js +121 -0
- package/src/index-types.ts +2 -0
- package/src/index.js +57 -155
- package/src/load/create.js +10 -2
- package/src/load/load.js +4 -4
- package/src/load/sql-from.js +7 -6
- package/src/transforms/bin-1d.js +21 -0
- package/src/transforms/bin-2d.js +29 -0
- package/src/transforms/bin-linear-1d.js +26 -0
- package/src/transforms/bin-linear-2d.js +71 -0
- package/src/transforms/line-density.js +113 -0
- package/src/transforms/m4.js +38 -0
- package/src/{scales.js → transforms/scales.js} +31 -17
- package/src/types.ts +96 -0
- package/src/util/ast.js +96 -0
- package/src/util/function.js +78 -0
- package/src/util/string.js +16 -0
- package/src/util/type-check.js +29 -0
- package/src/visit/recurse.js +57 -0
- package/src/visit/rewrite.js +32 -0
- package/src/visit/visitors.js +108 -0
- package/src/visit/walk.js +30 -0
- package/tsconfig.json +12 -0
- package/src/Query.js +0 -593
- package/src/aggregates.js +0 -185
- package/src/cast.js +0 -19
- package/src/datetime.js +0 -31
- package/src/desc.js +0 -13
- package/src/expression.js +0 -170
- package/src/functions.js +0 -25
- package/src/literal.js +0 -6
- package/src/operators.js +0 -54
- package/src/ref.js +0 -109
- package/src/repeat.js +0 -3
- package/src/spatial.js +0 -10
- package/src/to-sql.js +0 -52
- package/src/windows.js +0 -239
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function that converts geometry data to GeoJSON format.
|
|
3
|
+
* @param {import('../types.js').ExprValue} expr The input expression.
|
|
4
|
+
* @returns {FunctionNode}
|
|
5
|
+
*/
|
|
6
|
+
export function geojson(expr: import("../types.js").ExprValue): FunctionNode;
|
|
7
|
+
/**
|
|
8
|
+
* Function that returns a spatial x position (using ST_X).
|
|
9
|
+
* @param {import('../types.js').ExprValue} expr The input expression.
|
|
10
|
+
* @returns {FunctionNode}
|
|
11
|
+
*/
|
|
12
|
+
export function x(expr: import("../types.js").ExprValue): FunctionNode;
|
|
13
|
+
/**
|
|
14
|
+
* Function that returns a spatial y position (using ST_Y).
|
|
15
|
+
* @param {import('../types.js').ExprValue} expr The input expression.
|
|
16
|
+
* @returns {FunctionNode}
|
|
17
|
+
*/
|
|
18
|
+
export function y(expr: import("../types.js").ExprValue): FunctionNode;
|
|
19
|
+
/**
|
|
20
|
+
* Function that returns the centroid point for geometry data.
|
|
21
|
+
* @param {import('../types.js').ExprValue} expr The input expression.
|
|
22
|
+
* @returns {FunctionNode}
|
|
23
|
+
*/
|
|
24
|
+
export function centroid(expr: import("../types.js").ExprValue): FunctionNode;
|
|
25
|
+
/**
|
|
26
|
+
* Function that returns the centroid x-coordinate for geometry data.
|
|
27
|
+
* @param {import('../types.js').ExprValue} expr The input expression.
|
|
28
|
+
* @returns {FunctionNode}
|
|
29
|
+
*/
|
|
30
|
+
export function centroidX(expr: import("../types.js").ExprValue): FunctionNode;
|
|
31
|
+
/**
|
|
32
|
+
* Function that returns yhe centroid y-coordinate for geometry data.
|
|
33
|
+
* @param {import('../types.js').ExprValue} expr The input expression.
|
|
34
|
+
* @returns {FunctionNode}
|
|
35
|
+
*/
|
|
36
|
+
export function centroidY(expr: import("../types.js").ExprValue): FunctionNode;
|
|
37
|
+
import { FunctionNode } from '../ast/function.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../ast/node.js').ExprNode
|
|
3
|
+
* | import('../types.js').ParamLike
|
|
4
|
+
* | string | number | boolean | Date
|
|
5
|
+
* } TemplateValue
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Template tag function for SQL fragments. Interpolated values
|
|
9
|
+
* may be strings, other SQL expression objects (such as column
|
|
10
|
+
* references), primitive values, or dynamic parameters.
|
|
11
|
+
* @param {TemplateStringsArray} strings Template string constants.
|
|
12
|
+
* @param {...TemplateValue} exprs Template expression values.
|
|
13
|
+
*/
|
|
14
|
+
export function sql(strings: TemplateStringsArray, ...exprs: TemplateValue[]): FragmentNode;
|
|
15
|
+
export type TemplateValue = import("../ast/node.js").ExprNode | import("../types.js").ParamLike | string | number | boolean | Date;
|
|
16
|
+
import { FragmentNode } from '../ast/fragment.js';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function that returns true if a string contains a regexp pattern,
|
|
3
|
+
* false otherwise.
|
|
4
|
+
* @param {import('../types.js').ExprValue} string The string match against.
|
|
5
|
+
* @param {import('../types.js').StringValue} pattern The regular expression pattern to match.
|
|
6
|
+
* @param {import('../types.js').StringValue} [options] Regular expression options:
|
|
7
|
+
* 'c': case-sensitive matching
|
|
8
|
+
* 'i': case-insensitive matching
|
|
9
|
+
* 'l': match literals instead of regular expression tokens
|
|
10
|
+
* 'm', 'n', 'p': newline sensitive matching
|
|
11
|
+
* 'g': global replace, only available for regexp_replace
|
|
12
|
+
* 's': non-newline sensitive matching
|
|
13
|
+
* @returns {FunctionNode}
|
|
14
|
+
*/
|
|
15
|
+
export function regexp_matches(string: import("../types.js").ExprValue, pattern: import("../types.js").StringValue, options?: import("../types.js").StringValue): FunctionNode;
|
|
16
|
+
/**
|
|
17
|
+
* Function that returns true if search_string is found within string.
|
|
18
|
+
* @param {import('../types.js').ExprValue} string The string to match against.
|
|
19
|
+
* @param {import('../types.js').StringValue} search_string The substring to search for.
|
|
20
|
+
* @returns {FunctionNode}
|
|
21
|
+
*/
|
|
22
|
+
export function contains(string: import("../types.js").ExprValue, search_string: import("../types.js").StringValue): FunctionNode;
|
|
23
|
+
/**
|
|
24
|
+
* Function that returns true if string begins with search_string.
|
|
25
|
+
* @param {import('../types.js').ExprValue} string The string to match against.
|
|
26
|
+
* @param {import('../types.js').StringValue} search_string The substring to search for.
|
|
27
|
+
* @returns {FunctionNode}
|
|
28
|
+
*/
|
|
29
|
+
export function prefix(string: import("../types.js").ExprValue, search_string: import("../types.js").StringValue): FunctionNode;
|
|
30
|
+
/**
|
|
31
|
+
* Function that returns true if string ends with search_string.
|
|
32
|
+
* @param {import('../types.js').ExprValue} string The string to match against.
|
|
33
|
+
* @param {import('../types.js').StringValue} search_string The substring to search for.
|
|
34
|
+
* @returns {FunctionNode}
|
|
35
|
+
*/
|
|
36
|
+
export function suffix(string: import("../types.js").ExprValue, search_string: import("../types.js").StringValue): FunctionNode;
|
|
37
|
+
/**
|
|
38
|
+
* Function that converts string to lower case.
|
|
39
|
+
* @param {import('../types.js').ExprValue} string The string to convert.
|
|
40
|
+
* @returns {FunctionNode}
|
|
41
|
+
*/
|
|
42
|
+
export function lower(string: import("../types.js").ExprValue): FunctionNode;
|
|
43
|
+
/**
|
|
44
|
+
* Function that converts string to upper case.
|
|
45
|
+
* @param {import('../types.js').ExprValue} string The string to convert.
|
|
46
|
+
* @returns {FunctionNode}
|
|
47
|
+
*/
|
|
48
|
+
export function upper(string: import("../types.js").ExprValue): FunctionNode;
|
|
49
|
+
/**
|
|
50
|
+
* Function that returns the number of characters in string.
|
|
51
|
+
* @param {import('../types.js').ExprValue} value The string to measure.
|
|
52
|
+
* @returns {FunctionNode}
|
|
53
|
+
*/
|
|
54
|
+
export function length(value: import("../types.js").ExprValue): FunctionNode;
|
|
55
|
+
import { FunctionNode } from '../ast/function.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a named table or view reference.
|
|
3
|
+
* @param {...(string | string[])} ids Table and namespace identifiers.
|
|
4
|
+
* For example 'name' or ['schema', 'name'].
|
|
5
|
+
* @returns {TableRefNode | undefined} A table reference, or undefined
|
|
6
|
+
* if the input identifier list is empty.
|
|
7
|
+
*/
|
|
8
|
+
export function tableRef(...ids: (string | string[])[]): TableRefNode | undefined;
|
|
9
|
+
import { TableRefNode } from '../ast/table-ref.js';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a window function that returns the number of the current row
|
|
3
|
+
* within the partition, counting from 1.
|
|
4
|
+
* @returns {WindowNode}
|
|
5
|
+
*/
|
|
6
|
+
export function row_number(): WindowNode;
|
|
7
|
+
/**
|
|
8
|
+
* Create a window function that returns the rank of the current row with gaps.
|
|
9
|
+
* This is the same as the row_number of its first peer.
|
|
10
|
+
* @returns {WindowNode}
|
|
11
|
+
*/
|
|
12
|
+
export function rank(): WindowNode;
|
|
13
|
+
/**
|
|
14
|
+
* Create a window function that returns the rank of the current row without
|
|
15
|
+
* gaps. The function counts peer groups.
|
|
16
|
+
* @returns {WindowNode}
|
|
17
|
+
*/
|
|
18
|
+
export function dense_rank(): WindowNode;
|
|
19
|
+
/**
|
|
20
|
+
* Create a window function that returns the relative rank of the current row.
|
|
21
|
+
* Computed as (rank() - 1) / (total partition rows - 1).
|
|
22
|
+
* @returns {WindowNode}
|
|
23
|
+
*/
|
|
24
|
+
export function percent_rank(): WindowNode;
|
|
25
|
+
/**
|
|
26
|
+
* Create a window function that returns the cumulative distribution. Computed
|
|
27
|
+
* as (number of preceding or peer partition rows) / total partition rows.
|
|
28
|
+
* @returns {WindowNode}
|
|
29
|
+
*/
|
|
30
|
+
export function cume_dist(): WindowNode;
|
|
31
|
+
/**
|
|
32
|
+
* Create a window function that returns an integer ranging from 1 to the
|
|
33
|
+
* argument value, dividing the partition as equally as possible.
|
|
34
|
+
* @param {import('../types.js').NumberValue} num_buckets The number of
|
|
35
|
+
* quantile buckets.
|
|
36
|
+
* @returns {WindowNode}
|
|
37
|
+
*/
|
|
38
|
+
export function ntile(num_buckets: import("../types.js").NumberValue): WindowNode;
|
|
39
|
+
/**
|
|
40
|
+
* Create a window function that returns the expression evaluated at the row
|
|
41
|
+
* that is offset rows before the current row within the partition.
|
|
42
|
+
* If there is no such row, instead return default (which must be of the same
|
|
43
|
+
* type as the expression). Both offset and default are evaluated with respect
|
|
44
|
+
* to the current row. If omitted, offset defaults to 1 and default to null.
|
|
45
|
+
* @param {import('../types.js').ExprValue} expr The expression to evaluate.
|
|
46
|
+
* @param {import('../types.js').NumberValue} [offset] The row offset
|
|
47
|
+
* (default `1`).
|
|
48
|
+
* @param {*} [defaultValue] The default value (default `null`).
|
|
49
|
+
* @returns {WindowNode}
|
|
50
|
+
*/
|
|
51
|
+
export function lag(expr: import("../types.js").ExprValue, offset?: import("../types.js").NumberValue, defaultValue?: any): WindowNode;
|
|
52
|
+
/**
|
|
53
|
+
* Create a window function that returns the expression evaluated at the row
|
|
54
|
+
* that is offset rows after the current row within the partition.
|
|
55
|
+
* If there is no such row, instead return default (which must be of the same
|
|
56
|
+
* type as the expression). Both offset and default are evaluated with respect
|
|
57
|
+
* to the current row. If omitted, offset defaults to 1 and default to null.
|
|
58
|
+
* @param {import('../types.js').ExprValue} expr The expression to evaluate.
|
|
59
|
+
* @param {import('../types.js').NumberValue} [offset] The row offset
|
|
60
|
+
* (default `1`).
|
|
61
|
+
* @param {*} [defaultValue] The default value (default `null`).
|
|
62
|
+
* @returns {WindowNode}
|
|
63
|
+
*/
|
|
64
|
+
export function lead(expr: import("../types.js").ExprValue, offset?: import("../types.js").NumberValue, defaultValue?: any): WindowNode;
|
|
65
|
+
/**
|
|
66
|
+
* Create a window function that returns the expression evaluated at the row
|
|
67
|
+
* that is the first row of the window frame.
|
|
68
|
+
* @param {import('../types.js').ExprValue} expr The expression to evaluate.
|
|
69
|
+
* @returns {WindowNode}
|
|
70
|
+
*/
|
|
71
|
+
export function first_value(expr: import("../types.js").ExprValue): WindowNode;
|
|
72
|
+
/**
|
|
73
|
+
* Create a window function that returns the expression evaluated at the row
|
|
74
|
+
* that is the last row of the window frame.
|
|
75
|
+
* @param {import('../types.js').ExprValue} expr The expression to evaluate.
|
|
76
|
+
* @returns {WindowNode}
|
|
77
|
+
*/
|
|
78
|
+
export function last_value(expr: import("../types.js").ExprValue): WindowNode;
|
|
79
|
+
/**
|
|
80
|
+
* Create a window function that returns the expression evaluated at the
|
|
81
|
+
* nth row of the window frame (counting from 1), or null if no such row.
|
|
82
|
+
* @param {import('../types.js').ExprValue} expr The expression to evaluate.
|
|
83
|
+
* @param {import('../types.js').NumberValue} nth The 1-based window frame index.
|
|
84
|
+
* @returns {WindowNode}
|
|
85
|
+
*/
|
|
86
|
+
export function nth_value(expr: import("../types.js").ExprValue, nth: import("../types.js").NumberValue): WindowNode;
|
|
87
|
+
import { WindowNode } from '../ast/window.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export { AggregateNode } from "./ast/aggregate.js";
|
|
2
|
+
export { BinaryOpNode } from "./ast/binary-op.js";
|
|
3
|
+
export { CastNode } from "./ast/cast.js";
|
|
4
|
+
export { ColumnParamNode } from "./ast/column-param.js";
|
|
5
|
+
export { FragmentNode } from "./ast/fragment.js";
|
|
6
|
+
export { FromClauseNode } from "./ast/from.js";
|
|
7
|
+
export { FunctionNode } from "./ast/function.js";
|
|
8
|
+
export { InOpNode } from "./ast/in-op.js";
|
|
9
|
+
export { IntervalNode } from "./ast/interval.js";
|
|
10
|
+
export { LiteralNode } from "./ast/literal.js";
|
|
11
|
+
export { OrderByNode } from "./ast/order-by.js";
|
|
12
|
+
export { ParamNode } from "./ast/param.js";
|
|
13
|
+
export { SampleClauseNode } from "./ast/sample.js";
|
|
14
|
+
export { SelectClauseNode } from "./ast/select.js";
|
|
15
|
+
export { VerbatimNode } from "./ast/verbatim.js";
|
|
16
|
+
export { WithClauseNode } from "./ast/with.js";
|
|
17
|
+
export { cond } from "./functions/case.js";
|
|
18
|
+
export { column } from "./functions/column.js";
|
|
19
|
+
export { literal } from "./functions/literal.js";
|
|
20
|
+
export { sql } from "./functions/sql-template-tag.js";
|
|
21
|
+
export { rewrite } from "./visit/rewrite.js";
|
|
22
|
+
export { walk } from "./visit/walk.js";
|
|
23
|
+
export { loadExtension } from "./load/extension.js";
|
|
24
|
+
export { bin1d } from "./transforms/bin-1d.js";
|
|
25
|
+
export { bin2d } from "./transforms/bin-2d.js";
|
|
26
|
+
export { binLinear1d } from "./transforms/bin-linear-1d.js";
|
|
27
|
+
export { binLinear2d } from "./transforms/bin-linear-2d.js";
|
|
28
|
+
export { lineDensity } from "./transforms/line-density.js";
|
|
29
|
+
export { m4 } from "./transforms/m4.js";
|
|
30
|
+
export { scaleTransform } from "./transforms/scales.js";
|
|
31
|
+
export { isParamLike } from "./util/type-check.js";
|
|
32
|
+
export { BetweenOpNode, NotBetweenOpNode } from "./ast/between-op.js";
|
|
33
|
+
export { CaseNode, WhenNode } from "./ast/case.js";
|
|
34
|
+
export { ColumnRefNode, ColumnNameRefNode, isColumnRef } from "./ast/column-ref.js";
|
|
35
|
+
export { AndNode, OrNode } from "./ast/logical-op.js";
|
|
36
|
+
export { SQLNode, ExprNode, isNode } from "./ast/node.js";
|
|
37
|
+
export { DescribeQuery, Query, SelectQuery, SetOperation, isDescribeQuery, isQuery, isSelectQuery } from "./ast/query.js";
|
|
38
|
+
export { TableRefNode, isTableRef } from "./ast/table-ref.js";
|
|
39
|
+
export { UnaryOpNode, UnaryPosftixOpNode } from "./ast/unary-op.js";
|
|
40
|
+
export { WindowClauseNode, WindowDefNode, WindowFrameNode, WindowFunctionNode, WindowNode } from "./ast/window.js";
|
|
41
|
+
export { argmax, argmin, arrayAgg, avg, corr, count, covariance, covarPop, entropy, first, kurtosis, mad, max, median, min, mode, last, product, quantile, regrAvgX, regrAvgY, regrCount, regrIntercept, regrR2, regrSXX, regrSXY, regrSYY, regrSlope, skewness, stddev, stddevPop, stringAgg, sum, variance, varPop } from "./functions/aggregate.js";
|
|
42
|
+
export { cast, float32, float64, int32 } from "./functions/cast.js";
|
|
43
|
+
export { dateBin, dateMonth, dateMonthDay, dateDay, epoch_ms, interval } from "./functions/datetime.js";
|
|
44
|
+
export { abs, ceil, exp, floor, greatest, isFinite, isInfinite, isNaN, least, ln, log, round, sign, sqrt, trunc } from "./functions/numeric.js";
|
|
45
|
+
export { and, or, not, isNull, isNotNull, bitNot, bitAnd, bitOr, bitLeft, bitRight, add, sub, mul, div, idiv, mod, pow, eq, neq, lt, gt, lte, gte, isDistinct, isNotDistinct, isBetween, isNotBetween, isIn } from "./functions/operators.js";
|
|
46
|
+
export { asc, desc } from "./functions/order-by.js";
|
|
47
|
+
export { geojson, x, y, centroid, centroidX, centroidY } from "./functions/spatial.js";
|
|
48
|
+
export { regexp_matches, contains, prefix, suffix, lower, upper, length } from "./functions/string.js";
|
|
49
|
+
export { cume_dist, dense_rank, first_value, lag, last_value, lead, nth_value, ntile, percent_rank, rank, row_number } from "./functions/window.js";
|
|
50
|
+
export { collectAggregates, collectColumns, collectParams, isAggregateExpression } from "./visit/visitors.js";
|
|
51
|
+
export { createTable, createSchema } from "./load/create.js";
|
|
52
|
+
export { loadCSV, loadJSON, loadObjects, loadParquet, loadSpatial } from "./load/load.js";
|
|
53
|
+
export { asLiteral, asNode, asTableRef, asVerbatim, over } from "./util/ast.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function loadExtension(name: any): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function load(method: any, tableName: any, fileName: any, options?: {}, defaults?: {}): string;
|
|
2
|
+
export function loadCSV(tableName: any, fileName: any, options: any): string;
|
|
3
|
+
export function loadJSON(tableName: any, fileName: any, options: any): string;
|
|
4
|
+
export function loadParquet(tableName: any, fileName: any, options: any): string;
|
|
5
|
+
/**
|
|
6
|
+
* Load geometry data within a spatial file format.
|
|
7
|
+
* This method requires that the DuckDB spatial extension is loaded.
|
|
8
|
+
* Supports GeoJSON, TopoJSON, and other comomn spatial formats.
|
|
9
|
+
* For TopoJSON, wet the layer option to indicate the feature to extract.
|
|
10
|
+
*/
|
|
11
|
+
export function loadSpatial(tableName: any, fileName: any, options?: {}): string;
|
|
12
|
+
export function loadObjects(tableName: any, data: any, options?: {}): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a SQL query that embeds the given data for loading.
|
|
3
|
+
* @param {*} data The dataset as an array of objects.
|
|
4
|
+
* @param {object} [options] Loading options.
|
|
5
|
+
* @param {string[]|object} [options.columns] The columns to include.
|
|
6
|
+
* If not specified, the keys of the first data object are used.
|
|
7
|
+
* @returns {string} SQL query string to load data.
|
|
8
|
+
*/
|
|
9
|
+
export function sqlFrom(data: any, { columns }?: {
|
|
10
|
+
columns?: string[] | object;
|
|
11
|
+
}): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute binned values over a one-dimensional extent.
|
|
3
|
+
* @param {import('../types.js').ExprValue} x The expression to bin.
|
|
4
|
+
* The expression must return numeric values. For example, to bin
|
|
5
|
+
* datetime values, the input expression might map them to numeric
|
|
6
|
+
* values such as milliseconds since the epoch.
|
|
7
|
+
* @param {number} lo The low value of the bin extent.
|
|
8
|
+
* @param {number} hi The high value of the bin extent.
|
|
9
|
+
* @param {number} bins The integer number of bins to use within the
|
|
10
|
+
* defined binning extent.
|
|
11
|
+
* @param {boolean} [reverse] Flag indicating if bins should be
|
|
12
|
+
* produced in reverse order from *hi* to *lo* (default `false`).
|
|
13
|
+
*/
|
|
14
|
+
export function bin1d(x: import("../types.js").ExprValue, lo: number, hi: number, bins: number, reverse?: boolean): import("../index.js").BinaryOpNode;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perform aggregation over a binned 2D domain. This method takes expressions
|
|
3
|
+
* for the (non-truncated) x and y bin values; these expressions should be
|
|
4
|
+
* in units of grid indices, but can contain fractional components. The
|
|
5
|
+
* resulting query performs grouping and aggregation over the binned domain,
|
|
6
|
+
* and uses a 2D integer bin index of the form (xbin + num_xbins * ybin).
|
|
7
|
+
* @param {SelectQuery} q The input query. The FROM and WHERE clauses should
|
|
8
|
+
* be added to the query separately, either before or after this method.
|
|
9
|
+
* @param {import('../types.js').ExprValue} xp The x bin expression.
|
|
10
|
+
* @param {import('../types.js').ExprValue} yp The y bin expression.
|
|
11
|
+
* @param {Record<string, import('../types.js').ExprValue>} aggs Named
|
|
12
|
+
* aggregate expressions over bins.
|
|
13
|
+
* @param {number} xn The number of bins along the x dimension
|
|
14
|
+
* @param {string[]} groupby Group by expressions.
|
|
15
|
+
* @returns {SelectQuery} The input query, with binning expressions added.
|
|
16
|
+
*/
|
|
17
|
+
export function bin2d(q: SelectQuery, xp: import("../types.js").ExprValue, yp: import("../types.js").ExprValue, aggs: Record<string, import("../types.js").ExprValue>, xn: number, groupby: string[]): SelectQuery;
|
|
18
|
+
import { SelectQuery } from '../ast/query.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perform linear binning in one dimension.
|
|
3
|
+
* @param {import('../ast/query.js').SelectQuery} query The base query to bin.
|
|
4
|
+
* @param {import('../types.js').ExprValue} x The expression to bin.
|
|
5
|
+
* @param {import('../types.js').ExprValue} [weight] The expression to weight by.
|
|
6
|
+
* @returns {Query}
|
|
7
|
+
*/
|
|
8
|
+
export function binLinear1d(query: import("../ast/query.js").SelectQuery, x: import("../types.js").ExprValue, weight?: import("../types.js").ExprValue): Query;
|
|
9
|
+
import { Query } from '../ast/query.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute densities over a 2D domain using linear binning. The weight of
|
|
3
|
+
* each data point is linearly distributed over adjacent bins, providing
|
|
4
|
+
* a better base for subsequent kernel density estimation. This method takes
|
|
5
|
+
* expressions for the (non-truncated) x and y bin values; these expressions
|
|
6
|
+
* should be in units of grid indices, but can contain fractional components.
|
|
7
|
+
* @param {SelectQuery} q The input query. The FROM and WHERE clauses should
|
|
8
|
+
* be added to the query separately, before this method is invoked.
|
|
9
|
+
* @param {import('../types.js').ExprValue} xp The x grid bin expression
|
|
10
|
+
* @param {import('../types.js').ExprValue} yp The y grid bin expression
|
|
11
|
+
* @param {import('../types.js').ExprValue | undefined} weight Point weights.
|
|
12
|
+
* @param {number} xn The number of x grid bins.
|
|
13
|
+
* @param {string[]} groupby Group by expressions.
|
|
14
|
+
* @returns {SelectQuery} A linear binning query for bin `index` and
|
|
15
|
+
* aggregate `density` columns, in addition to any group by expressions.
|
|
16
|
+
*/
|
|
17
|
+
export function binLinear2d(q: SelectQuery, xp: import("../types.js").ExprValue, yp: import("../types.js").ExprValue, weight: import("../types.js").ExprValue | undefined, xn: number, groupby: string[]): SelectQuery;
|
|
18
|
+
import { SelectQuery } from '../ast/query.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute line segment densities over a gridded 2D domain. The returned
|
|
3
|
+
* query uses multiple subqueries (CTEs) to identify line segment end point
|
|
4
|
+
* pairs, perform line rasterization in-database, normalize arc lengths,
|
|
5
|
+
* and then sum results for all line series to produce a density map.
|
|
6
|
+
* Based on Moritz and Fisher's work: https://arxiv.org/abs/1808.06019
|
|
7
|
+
* @param {SelectQuery} q The base query over the data.
|
|
8
|
+
* @param {import('../types.js').ExprValue} x Bin expression for x dimension.
|
|
9
|
+
* Provides gridded x coordinates, potentially with a fractional component.
|
|
10
|
+
* @param {import('../types.js').ExprValue} y Bin expression for x dimension.
|
|
11
|
+
* Provides gridded y coordinates, potentially with a fractional component.
|
|
12
|
+
* @param {string[]} z Group by columns that segment data into individual line
|
|
13
|
+
* series. An empty array indicates there is only a single line series.
|
|
14
|
+
* @param {number} xn The number of grid bins for the x dimension.
|
|
15
|
+
* @param {number} yn The number of grid bins for the y dimension.
|
|
16
|
+
* @param {string[]} [groupby] Additional group by expressions. Separate
|
|
17
|
+
* line density maps are created for each of these groups.
|
|
18
|
+
* @param {boolean} [normalize=true] Flag toggling approximate arc-length
|
|
19
|
+
* normalization to improve accuracy and reduce artifacts (default `true`).
|
|
20
|
+
* @returns {SelectQuery}
|
|
21
|
+
*/
|
|
22
|
+
export function lineDensity(q: SelectQuery, x: import("../types.js").ExprValue, y: import("../types.js").ExprValue, z: string[], xn: number, yn: number, groupby?: string[], normalize?: boolean): SelectQuery;
|
|
23
|
+
import { SelectQuery } from '../ast/query.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M4 is an optimization for value-preserving time-series aggregation
|
|
3
|
+
* (https://www.vldb.org/pvldb/vol7/p797-jugel.pdf). This implementation uses
|
|
4
|
+
* an efficient version with a single scan and the aggregate functions
|
|
5
|
+
* argmin and argmax, following https://arxiv.org/pdf/2306.03714.pdf.
|
|
6
|
+
* This method can bin along either the *x* or *y* dimension, as determined
|
|
7
|
+
* by the caller-provided *bin* expression.
|
|
8
|
+
* @param {import('../types.js').FromExpr} input The base query or table.
|
|
9
|
+
* @param {import('../types.js').ExprValue} bin An expression that maps
|
|
10
|
+
* time-series values to fractional pixel positions.
|
|
11
|
+
* @param {string} x The x dimension column name.
|
|
12
|
+
* @param {string} y The y dimension column name.
|
|
13
|
+
* @param {import('../ast/node.js').ExprNode[]} [groups] Additional
|
|
14
|
+
* groupby columns, for example for faceted charts.
|
|
15
|
+
* @returns {Query} The resulting M4 query.
|
|
16
|
+
*/
|
|
17
|
+
export function m4(input: import("../types.js").FromExpr, bin: import("../types.js").ExprValue, x: string, y: string, groups?: import("../ast/node.js").ExprNode[]): Query;
|
|
18
|
+
import { Query } from '../ast/query.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function scaleTransform(options: any): any;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ColumnRefNode } from './ast/column-ref.js';
|
|
2
|
+
import { ExprNode, SQLNode } from './ast/node.js';
|
|
3
|
+
import { TableRefNode } from './ast/table-ref.js';
|
|
4
|
+
import { Query } from './ast/query.js';
|
|
5
|
+
/**
|
|
6
|
+
* Interface representing a dynamic parameter value.
|
|
7
|
+
*/
|
|
8
|
+
export interface ParamLike {
|
|
9
|
+
/** The current parameter value. */
|
|
10
|
+
value: any;
|
|
11
|
+
/** Add an event listener callback. */
|
|
12
|
+
addEventListener(type: string, callback: EventCallback): void;
|
|
13
|
+
/** Remove an event listener callback. */
|
|
14
|
+
removeEventListener(type: string, callback: EventCallback): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Expression value input to SQL builder method.
|
|
18
|
+
*/
|
|
19
|
+
export type ExprValue = ExprNode | ParamLike | string | number | boolean | Date;
|
|
20
|
+
/**
|
|
21
|
+
* Expression values that may be nested in arrays.
|
|
22
|
+
*/
|
|
23
|
+
export type ExprVarArgs = MaybeArray<ExprValue>;
|
|
24
|
+
/**
|
|
25
|
+
* String-typed expression value.
|
|
26
|
+
*/
|
|
27
|
+
export type StringValue = ExprNode | ParamLike | string;
|
|
28
|
+
/**
|
|
29
|
+
* Number-typed expression value.
|
|
30
|
+
*/
|
|
31
|
+
export type NumberValue = ExprNode | ParamLike | number;
|
|
32
|
+
/**
|
|
33
|
+
* Event listener callback function.
|
|
34
|
+
*/
|
|
35
|
+
export type EventCallback = <T>(value: any) => Promise<T> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* SQL AST traversal visitor callback result.
|
|
38
|
+
* A falsy value (including `undefined`, `null`, `false`, and `0`) indicates
|
|
39
|
+
* that traversal should continue.
|
|
40
|
+
* A negative number values indicates that traversal should stop immediately.
|
|
41
|
+
* Any other truthy value indicates that traversal should not recurse on the
|
|
42
|
+
* current node, but should otherwise continue.
|
|
43
|
+
*/
|
|
44
|
+
export type VisitorResult = boolean | number | null | undefined | void;
|
|
45
|
+
/**
|
|
46
|
+
* SQL AST traversal callback function.
|
|
47
|
+
*/
|
|
48
|
+
export type VisitorCallback = (node: SQLNode) => VisitorResult;
|
|
49
|
+
/** Valid window function names. */
|
|
50
|
+
export type WindowFunctionName = 'cume_dist' | 'dense_rank' | 'first_value' | 'lag' | 'last_value' | 'lead' | 'nth_value' | 'ntile' | 'percent_rank' | 'rank_dense' | 'rank' | 'row_number';
|
|
51
|
+
export type MaybeArray<T> = T | T[];
|
|
52
|
+
export type SelectEntry = string | ColumnRefNode | [string, ExprNode] | Record<string, ExprValue>;
|
|
53
|
+
export type SelectExpr = MaybeArray<SelectEntry>;
|
|
54
|
+
export type WithExpr = MaybeArray<Record<string, Query>>;
|
|
55
|
+
export type FromEntry = string | TableRefNode | SQLNode | [string, SQLNode] | Record<string, string | SQLNode>;
|
|
56
|
+
export type FromExpr = MaybeArray<FromEntry>;
|
|
57
|
+
export type FilterExpr = MaybeArray<string | ExprNode>;
|
|
58
|
+
export type GroupByExpr = MaybeArray<string | ExprNode>;
|
|
59
|
+
export type OrderByExpr = MaybeArray<string | ExprNode>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interpret a value as a SQL AST node. String values are assumed to be
|
|
3
|
+
* column references. All other primitive values are interpreted as
|
|
4
|
+
* SQL literals. Dynamic parameters are interpreted as param AST nodes,
|
|
5
|
+
* while existing AST nodes are left as-is.
|
|
6
|
+
* @param {*} value The value to interpret as a SQL AST node.
|
|
7
|
+
* @returns {ExprNode}
|
|
8
|
+
*/
|
|
9
|
+
export function asNode(value: any): ExprNode;
|
|
10
|
+
/**
|
|
11
|
+
* Interpret a value as a verbatim SQL AST node. String values will be
|
|
12
|
+
* passed through to queries as verbatim text. All other primitive values
|
|
13
|
+
* are interpreted as SQL literals. Dynamic parameters are interpreted
|
|
14
|
+
* as param AST nodes, while existing AST nodes are left as-is.
|
|
15
|
+
* @param {*} value The value to interpret as a verbatim AST node.
|
|
16
|
+
* @returns {ExprNode}
|
|
17
|
+
*/
|
|
18
|
+
export function asVerbatim(value: any): ExprNode;
|
|
19
|
+
/**
|
|
20
|
+
* Interpret a value as a literal AST node. All other primitive values
|
|
21
|
+
* are interpreted as SQL literals. Dynamic parameters are interpreted
|
|
22
|
+
* as param AST nodes, while existing AST nodes are left as-is.
|
|
23
|
+
* @param {*} value The value to interpret as a literal AST node.
|
|
24
|
+
* @returns {ExprNode}
|
|
25
|
+
*/
|
|
26
|
+
export function asLiteral(value: any): ExprNode;
|
|
27
|
+
/**
|
|
28
|
+
* Interpret a value as a table reference AST node. String values are parsed
|
|
29
|
+
* assuming dot ('.') delimiters (as in `schema.table`). Array values are
|
|
30
|
+
* interpreted as pre-parsed name paths (as in `['schema', 'table']`). Any
|
|
31
|
+
* other values are left as-is.
|
|
32
|
+
* @param {string | string[] | TableRefNode} value The value to interpret as a
|
|
33
|
+
* table reference AST node.
|
|
34
|
+
* @returns {TableRefNode}
|
|
35
|
+
*/
|
|
36
|
+
export function asTableRef(value: string | string[] | TableRefNode): TableRefNode;
|
|
37
|
+
/**
|
|
38
|
+
* Parse a string as a column reference, potentially with
|
|
39
|
+
* dot ('.') delimited table, schema, and database references.
|
|
40
|
+
* @param {string} ref The column reference string.
|
|
41
|
+
* @returns {import('../ast/column-ref.js').ColumnRefNode}
|
|
42
|
+
*/
|
|
43
|
+
export function parseColumnRef(ref: string): import("../ast/column-ref.js").ColumnRefNode;
|
|
44
|
+
/**
|
|
45
|
+
* Parse a string as a table reference, potentially with
|
|
46
|
+
* dot ('.') delimited schema and database references.
|
|
47
|
+
* @param {string} ref The table reference string.
|
|
48
|
+
* @returns {import('../ast/table-ref.js').TableRefNode}
|
|
49
|
+
*/
|
|
50
|
+
export function parseTableRef(ref: string): import("../ast/table-ref.js").TableRefNode;
|
|
51
|
+
/**
|
|
52
|
+
* Create a new window definition node. The return value is an empty
|
|
53
|
+
* window definition. Use chained calls such as `partitionby` and `orderby`
|
|
54
|
+
* to specify the window settings.
|
|
55
|
+
* @returns {WindowDefNode}
|
|
56
|
+
*/
|
|
57
|
+
export function over(): WindowDefNode;
|
|
58
|
+
import { ExprNode } from '../ast/node.js';
|
|
59
|
+
import { TableRefNode } from '../ast/table-ref.js';
|
|
60
|
+
import { WindowDefNode } from '../ast/window.js';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test if an AST node is a specific function call.
|
|
3
|
+
* @param {import('../ast/node.js').SQLNode} node The SQL AST node to test.
|
|
4
|
+
* @param {string} name The function name.
|
|
5
|
+
* @returns {node is FunctionNode}
|
|
6
|
+
*/
|
|
7
|
+
export function isFunctionCall(node: import("../ast/node.js").SQLNode, name: string): node is FunctionNode;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new function call AST node.
|
|
10
|
+
* @param {string} name The function name.
|
|
11
|
+
* @param {...any} args The function arguments.
|
|
12
|
+
* @returns {FunctionNode}
|
|
13
|
+
*/
|
|
14
|
+
export function fn(name: string, ...args: any[]): FunctionNode;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new aggregate function AST node.
|
|
17
|
+
* @param {string} name The function name.
|
|
18
|
+
* @param {...any} args The function arguments.
|
|
19
|
+
* @returns {AggregateNode}
|
|
20
|
+
*/
|
|
21
|
+
export function aggFn(name: string, ...args: any[]): AggregateNode;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new window AST node. The output node has an empty window
|
|
24
|
+
* definition. Use chained calls such as `partitionby` and `orderby`
|
|
25
|
+
* to specify the window settings.
|
|
26
|
+
* @param {import('../types.js').WindowFunctionName} name The function name.
|
|
27
|
+
* @param {...any} args The function arguments.
|
|
28
|
+
* @returns {WindowNode}
|
|
29
|
+
*/
|
|
30
|
+
export function winFn(name: import("../types.js").WindowFunctionName, ...args: any[]): WindowNode;
|
|
31
|
+
/**
|
|
32
|
+
* Process a list of expression inputs. Nested arrays are flattened,
|
|
33
|
+
* null results are removed, and each input is cast (as needed) to
|
|
34
|
+
* be a proper SQL AST node. By default, strings are assumed to be
|
|
35
|
+
* column names, while other primitive values map to SQL literals.
|
|
36
|
+
* Use an alternative *cast* function to change this behavior.
|
|
37
|
+
* @param {any[]} list The list of expression inputs.
|
|
38
|
+
* @param {function} [cast] A function that casts an input value
|
|
39
|
+
* to a desired type. By default, `asNode` is used to coerce
|
|
40
|
+
* inputs to AST nodes as needed.
|
|
41
|
+
* @returns {ReturnType<cast>[]}
|
|
42
|
+
*/
|
|
43
|
+
export function exprList(list: any[], cast?: Function): ReturnType<Function>[];
|
|
44
|
+
/**
|
|
45
|
+
* Process a list of function arguments, stripping any undefined
|
|
46
|
+
* values from the end of the list.
|
|
47
|
+
* @template T
|
|
48
|
+
* @param {T[]} list The input function arguments.
|
|
49
|
+
* @returns {T[]} The prepared argument list.
|
|
50
|
+
*/
|
|
51
|
+
export function argsList<T>(list: T[]): T[];
|
|
52
|
+
import { FunctionNode } from '../ast/function.js';
|
|
53
|
+
import { AggregateNode } from '../ast/aggregate.js';
|
|
54
|
+
import { WindowNode } from '../ast/window.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a value is a string.
|
|
3
|
+
* @param {*} value The value to check.
|
|
4
|
+
* @returns {value is string}
|
|
5
|
+
*/
|
|
6
|
+
export function isString(value: any): value is string;
|
|
7
|
+
/**
|
|
8
|
+
* Check if a value is an array.
|
|
9
|
+
* @param {*} value The value to check.
|
|
10
|
+
* @returns {value is Array}
|
|
11
|
+
*/
|
|
12
|
+
export function isArray(value: any): value is any[];
|
|
13
|
+
/**
|
|
14
|
+
* Check if a value is a dynamic parameter.
|
|
15
|
+
* @param {*} value The value to check.
|
|
16
|
+
* @returns {value is import('../types.js').ParamLike}
|
|
17
|
+
*/
|
|
18
|
+
export function isParamLike(value: any): value is import("../types.js").ParamLike;
|