df-script 1.4.0 → 1.6.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/README.md +203 -38
- package/dist/api.d.ts +16 -8
- package/dist/columnExpressions/ColumnExpr.d.ts +26 -364
- package/dist/columnExpressions/ExprBase.d.ts +8 -11
- package/dist/columnExpressions/constants.d.ts +2 -0
- package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
- package/dist/columnExpressions/functions/element.d.ts +5 -0
- package/dist/columnExpressions/functions/implode.d.ts +3 -0
- package/dist/columnExpressions/functions/lit.d.ts +3 -1
- package/dist/columnExpressions/functions/seq_range.d.ts +31 -0
- package/dist/columnExpressions/functions/when.d.ts +2 -2
- package/dist/columnExpressions/index.d.ts +6 -3
- package/dist/columnExpressions/mixins/AggregationExpr.d.ts +25 -50
- package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +43 -67
- package/dist/columnExpressions/mixins/ArrayExpr.d.ts +39 -0
- package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +31 -60
- package/dist/columnExpressions/mixins/ListExpr.d.ts +16 -40
- package/dist/columnExpressions/mixins/LogicalExpr.d.ts +7 -33
- package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +6 -31
- package/dist/columnExpressions/mixins/StringExpr.d.ts +7 -32
- package/dist/columnExpressions/mixins/StructExpr.d.ts +16 -0
- package/dist/columnExpressions/mixins/TemporalExpr.d.ts +4 -30
- package/dist/columnExpressions/mixins/WindowExpr.d.ts +27 -49
- package/dist/columnExpressions/types.d.ts +1 -0
- package/dist/columnExpressions/utils.d.ts +4 -0
- package/dist/constants.d.ts +11 -0
- package/dist/dataframe/constants.d.ts +3 -0
- package/dist/dataframe/dataframe.d.ts +28 -11
- package/dist/dataframe/grouped/grouped.d.ts +2 -3
- package/dist/dataframe/types.d.ts +65 -1
- package/dist/dataframe/utils.d.ts +11 -3
- package/dist/datatypes/DataType.d.ts +2 -1
- package/dist/datatypes/index.d.ts +4 -3
- package/dist/datatypes/types.d.ts +42 -41
- package/dist/exceptions/index.d.ts +2 -0
- package/dist/exceptions/utils.d.ts +1 -0
- package/dist/functions/concat.d.ts +1 -2
- package/dist/functions/index.d.ts +3 -1
- package/dist/functions/read_csv.d.ts +8 -0
- package/dist/functions/read_json.d.ts +10 -0
- package/dist/index.js +6 -1
- package/dist/types.d.ts +34 -6
- package/dist/utils/array.d.ts +217 -0
- package/dist/utils/binary.d.ts +3 -0
- package/dist/utils/csv.d.ts +77 -0
- package/dist/utils/date.d.ts +21 -35
- package/dist/utils/guards.d.ts +11 -12
- package/dist/utils/index.d.ts +5 -2
- package/dist/utils/json.d.ts +120 -2
- package/dist/utils/list.d.ts +196 -2
- package/dist/utils/number.d.ts +47 -29
- package/dist/utils/object.d.ts +26 -0
- package/dist/utils/string.d.ts +7 -4
- package/package.json +6 -2
- package/dist/api.js +0 -18
- package/dist/bundle.min.js +0 -1
- package/dist/columnExpressions/ColumnExpr.js +0 -23
- package/dist/columnExpressions/ExprBase.js +0 -133
- package/dist/columnExpressions/constants.js +0 -5
- package/dist/columnExpressions/functions/all.js +0 -11
- package/dist/columnExpressions/functions/coalesce.js +0 -40
- package/dist/columnExpressions/functions/exclude.js +0 -13
- package/dist/columnExpressions/functions/lit.js +0 -22
- package/dist/columnExpressions/functions/when.js +0 -81
- package/dist/columnExpressions/index.js +0 -81
- package/dist/columnExpressions/mixins/AggregationExpr.js +0 -172
- package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -143
- package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -389
- package/dist/columnExpressions/mixins/ListExpr.js +0 -248
- package/dist/columnExpressions/mixins/LogicalExpr.js +0 -54
- package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -35
- package/dist/columnExpressions/mixins/StringExpr.js +0 -249
- package/dist/columnExpressions/mixins/TemporalExpr.js +0 -127
- package/dist/columnExpressions/mixins/WindowExpr.js +0 -281
- package/dist/columnExpressions/types.js +0 -2
- package/dist/dataframe/constants.js +0 -4
- package/dist/dataframe/dataframe.js +0 -749
- package/dist/dataframe/grouped/grouped.js +0 -113
- package/dist/dataframe/index.js +0 -20
- package/dist/dataframe/types.js +0 -2
- package/dist/dataframe/utils.js +0 -215
- package/dist/datatypes/DataType.js +0 -47
- package/dist/datatypes/index.js +0 -46
- package/dist/datatypes/types/Binary.d.ts +0 -9
- package/dist/datatypes/types/Binary.js +0 -18
- package/dist/datatypes/types/Boolean.d.ts +0 -9
- package/dist/datatypes/types/Boolean.js +0 -19
- package/dist/datatypes/types/Date.d.ts +0 -8
- package/dist/datatypes/types/Date.js +0 -21
- package/dist/datatypes/types/Datetime.d.ts +0 -8
- package/dist/datatypes/types/Datetime.js +0 -17
- package/dist/datatypes/types/Decimal.d.ts +0 -10
- package/dist/datatypes/types/Decimal.js +0 -28
- package/dist/datatypes/types/Duration.d.ts +0 -8
- package/dist/datatypes/types/Duration.js +0 -17
- package/dist/datatypes/types/Float32.d.ts +0 -8
- package/dist/datatypes/types/Float32.js +0 -17
- package/dist/datatypes/types/Float64.d.ts +0 -8
- package/dist/datatypes/types/Float64.js +0 -17
- package/dist/datatypes/types/Int16.d.ts +0 -8
- package/dist/datatypes/types/Int16.js +0 -17
- package/dist/datatypes/types/Int32.d.ts +0 -8
- package/dist/datatypes/types/Int32.js +0 -17
- package/dist/datatypes/types/Int64.d.ts +0 -8
- package/dist/datatypes/types/Int64.js +0 -17
- package/dist/datatypes/types/Int8.d.ts +0 -8
- package/dist/datatypes/types/Int8.js +0 -17
- package/dist/datatypes/types/List.d.ts +0 -10
- package/dist/datatypes/types/List.js +0 -31
- package/dist/datatypes/types/Null.d.ts +0 -9
- package/dist/datatypes/types/Null.js +0 -17
- package/dist/datatypes/types/Object.d.ts +0 -9
- package/dist/datatypes/types/Object.js +0 -17
- package/dist/datatypes/types/Struct.d.ts +0 -14
- package/dist/datatypes/types/Struct.js +0 -39
- package/dist/datatypes/types/Time.d.ts +0 -8
- package/dist/datatypes/types/Time.js +0 -29
- package/dist/datatypes/types/UInt16.d.ts +0 -8
- package/dist/datatypes/types/UInt16.js +0 -17
- package/dist/datatypes/types/UInt32.d.ts +0 -8
- package/dist/datatypes/types/UInt32.js +0 -17
- package/dist/datatypes/types/UInt64.d.ts +0 -8
- package/dist/datatypes/types/UInt64.js +0 -17
- package/dist/datatypes/types/UInt8.d.ts +0 -8
- package/dist/datatypes/types/UInt8.js +0 -17
- package/dist/datatypes/types/Utf8.d.ts +0 -10
- package/dist/datatypes/types/Utf8.js +0 -20
- package/dist/datatypes/types.js +0 -286
- package/dist/exceptions/index.js +0 -43
- package/dist/exceptions/utils.js +0 -9
- package/dist/functions/concat.js +0 -248
- package/dist/functions/index.js +0 -17
- package/dist/types.js +0 -2
- package/dist/utils/boolean.d.ts +0 -1
- package/dist/utils/boolean.js +0 -18
- package/dist/utils/date.js +0 -349
- package/dist/utils/guards.js +0 -143
- package/dist/utils/index.js +0 -21
- package/dist/utils/json.js +0 -33
- package/dist/utils/list.js +0 -128
- package/dist/utils/number.js +0 -223
- package/dist/utils/string.js +0 -120
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExprBase = exports.derive = exports.kleeneBinary = exports.kleeneUnary = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
const kleeneUnary = (fn) => {
|
|
7
|
-
return (vArray) => {
|
|
8
|
-
const height = vArray.length;
|
|
9
|
-
const result = new Array(height);
|
|
10
|
-
for (let i = 0; i < height; i++) {
|
|
11
|
-
const v = vArray[i];
|
|
12
|
-
result[i] = v == null ? null : fn(v);
|
|
13
|
-
}
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
exports.kleeneUnary = kleeneUnary;
|
|
18
|
-
const kleeneBinary = (expr, other, fn) => {
|
|
19
|
-
return (vArray, columns) => {
|
|
20
|
-
const height = vArray.length;
|
|
21
|
-
const rResolved = expr._resolve(other, columns, height);
|
|
22
|
-
const result = new Array(height);
|
|
23
|
-
if ((0, utils_1.isArrayOrTypedArray)(rResolved)) {
|
|
24
|
-
for (let i = 0; i < height; i++) {
|
|
25
|
-
const v = vArray[i];
|
|
26
|
-
const r = rResolved[i];
|
|
27
|
-
result[i] = (v == null || r == null) ? null : fn(v, r);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
for (let i = 0; i < height; i++) {
|
|
32
|
-
const v = vArray[i];
|
|
33
|
-
result[i] = (v == null || rResolved == null) ? null : fn(v, rResolved);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
exports.kleeneBinary = kleeneBinary;
|
|
40
|
-
const derive = (instance, nextOp) => {
|
|
41
|
-
const Constructor = instance.constructor;
|
|
42
|
-
const newInst = new Constructor(instance.colName || "");
|
|
43
|
-
Object.assign(newInst, instance);
|
|
44
|
-
newInst.ops = nextOp ? [...instance.ops, nextOp] : [...instance.ops];
|
|
45
|
-
return newInst;
|
|
46
|
-
};
|
|
47
|
-
exports.derive = derive;
|
|
48
|
-
class ExprBase {
|
|
49
|
-
ops = [];
|
|
50
|
-
outputName = "";
|
|
51
|
-
aggFn = null;
|
|
52
|
-
groupingOpsIndex;
|
|
53
|
-
partitionOpsIndex;
|
|
54
|
-
partitionBy = null;
|
|
55
|
-
_resolve(val, columns, height) {
|
|
56
|
-
if (val && typeof val === "object" && "evaluate" in val) {
|
|
57
|
-
if (val.isLiteral && val.ops.length === 1) {
|
|
58
|
-
return val.literalValue;
|
|
59
|
-
}
|
|
60
|
-
return val.evaluate(columns, height);
|
|
61
|
-
}
|
|
62
|
-
return val;
|
|
63
|
-
}
|
|
64
|
-
alias(name) {
|
|
65
|
-
const Constructor = this.constructor;
|
|
66
|
-
const newInst = new Constructor(this.colName || "");
|
|
67
|
-
Object.assign(newInst, this);
|
|
68
|
-
newInst.outputName = name;
|
|
69
|
-
return newInst;
|
|
70
|
-
}
|
|
71
|
-
cast(dataType) {
|
|
72
|
-
return (0, exports.derive)(this, (vArray) => {
|
|
73
|
-
const height = vArray.length;
|
|
74
|
-
const result = new Array(height);
|
|
75
|
-
for (let i = 0; i < height; i++) {
|
|
76
|
-
result[i] = dataType.coerce(vArray[i]);
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
debug(label) {
|
|
82
|
-
return (0, exports.derive)(this, (vArray) => {
|
|
83
|
-
console.log(`[DEBUG] ${label ? label + ': ' : ''}`, vArray);
|
|
84
|
-
return vArray;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
evaluate(columns, height) {
|
|
88
|
-
const name = this.colName;
|
|
89
|
-
let value = name && name !== constants_1.ALL_COLUMNS_MARKER
|
|
90
|
-
? (columns[name] || new Array(height).fill(null))
|
|
91
|
-
: new Array(height).fill(null);
|
|
92
|
-
const ops = this.ops;
|
|
93
|
-
const len = ops.length;
|
|
94
|
-
for (let i = 0; i < len; i++) {
|
|
95
|
-
value = ops[i](value, columns);
|
|
96
|
-
}
|
|
97
|
-
return value;
|
|
98
|
-
}
|
|
99
|
-
_evaluatePre(opsIndex, columns, height) {
|
|
100
|
-
const name = this.colName;
|
|
101
|
-
let value = name && name !== constants_1.ALL_COLUMNS_MARKER
|
|
102
|
-
? (columns[name] || new Array(height).fill(null))
|
|
103
|
-
: new Array(height).fill(null);
|
|
104
|
-
const ops = this.ops;
|
|
105
|
-
const idx = opsIndex !== undefined ? opsIndex : ops.length;
|
|
106
|
-
for (let i = 0; i < idx; i++) {
|
|
107
|
-
value = ops[i](value, columns);
|
|
108
|
-
}
|
|
109
|
-
return value;
|
|
110
|
-
}
|
|
111
|
-
_evaluatePost(opsIndex, aggregatedArray, columns) {
|
|
112
|
-
const ops = this.ops;
|
|
113
|
-
const idx = opsIndex !== undefined ? opsIndex : ops.length;
|
|
114
|
-
let value = aggregatedArray;
|
|
115
|
-
for (let i = idx; i < ops.length; i++) {
|
|
116
|
-
value = ops[i](value, columns);
|
|
117
|
-
}
|
|
118
|
-
return value;
|
|
119
|
-
}
|
|
120
|
-
evaluatePrePartition(columns, height) {
|
|
121
|
-
return this._evaluatePre(this.partitionOpsIndex, columns, height);
|
|
122
|
-
}
|
|
123
|
-
evaluatePostPartition(aggregatedArray, columns) {
|
|
124
|
-
return this._evaluatePost(this.partitionOpsIndex, aggregatedArray, columns);
|
|
125
|
-
}
|
|
126
|
-
evaluatePreGrouping(columns, height) {
|
|
127
|
-
return this._evaluatePre(this.groupingOpsIndex, columns, height);
|
|
128
|
-
}
|
|
129
|
-
evaluatePostGrouping(aggregatedArray, columns) {
|
|
130
|
-
return this._evaluatePost(this.groupingOpsIndex, aggregatedArray, columns);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
exports.ExprBase = ExprBase;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.all = all;
|
|
4
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
/**
|
|
7
|
-
* Creates an expression targeting all columns in the DataFrame.
|
|
8
|
-
*/
|
|
9
|
-
function all() {
|
|
10
|
-
return new ColumnExpr_1.ColumnExpr(constants_1.ALL_COLUMNS_MARKER);
|
|
11
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.coalesce = coalesce;
|
|
4
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
6
|
-
function coalesce(...exprs) {
|
|
7
|
-
const rawArgs = (exprs.length === 1 && Array.isArray(exprs[0]))
|
|
8
|
-
? exprs[0]
|
|
9
|
-
: exprs;
|
|
10
|
-
const expr = new ColumnExpr_1.ColumnExpr("*coalesce*");
|
|
11
|
-
expr.ops.push((_, columns) => {
|
|
12
|
-
const height = _.length;
|
|
13
|
-
const evaluateArg = (arg) => {
|
|
14
|
-
if (arg && typeof arg === "object" && "evaluate" in arg) {
|
|
15
|
-
return arg.evaluate(columns, height);
|
|
16
|
-
}
|
|
17
|
-
if (typeof arg === "string") {
|
|
18
|
-
return columns[arg] || new Array(height).fill(null);
|
|
19
|
-
}
|
|
20
|
-
return arg;
|
|
21
|
-
};
|
|
22
|
-
const evaluatedArrays = rawArgs.map(evaluateArg);
|
|
23
|
-
const result = new Array(height);
|
|
24
|
-
const exprCount = evaluatedArrays.length;
|
|
25
|
-
for (let i = 0; i < height; i++) {
|
|
26
|
-
let foundVal = null;
|
|
27
|
-
for (let j = 0; j < exprCount; j++) {
|
|
28
|
-
const arr = evaluatedArrays[j];
|
|
29
|
-
const val = (0, utils_1.isArrayOrTypedArray)(arr) ? arr[i] : arr;
|
|
30
|
-
if (val != null) {
|
|
31
|
-
foundVal = val;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
result[i] = foundVal;
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
});
|
|
39
|
-
return expr;
|
|
40
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exclude = exclude;
|
|
4
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
/**
|
|
7
|
-
* Creates an expression targeting all columns except the specified ones.
|
|
8
|
-
*/
|
|
9
|
-
function exclude(columns) {
|
|
10
|
-
const expr = new ColumnExpr_1.ColumnExpr(constants_1.ALL_COLUMNS_MARKER);
|
|
11
|
-
expr.excludedCols = Array.isArray(columns) ? columns : [columns];
|
|
12
|
-
return expr;
|
|
13
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lit = lit;
|
|
4
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
/**
|
|
7
|
-
* Creates a literal column expression that repeats the given value for all rows.
|
|
8
|
-
*/
|
|
9
|
-
function lit(value) {
|
|
10
|
-
const expr = new ColumnExpr_1.ColumnExpr(constants_1.LITERAL_MARKER);
|
|
11
|
-
expr.isLiteral = true;
|
|
12
|
-
expr.literalValue = value;
|
|
13
|
-
expr.ops.push((vArray) => {
|
|
14
|
-
const height = vArray.length;
|
|
15
|
-
const result = new Array(height);
|
|
16
|
-
for (let i = 0; i < height; i++) {
|
|
17
|
-
result[i] = value;
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
});
|
|
21
|
-
return expr;
|
|
22
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WhenThen = exports.When = exports.WhenThenChain = void 0;
|
|
4
|
-
exports.when = when;
|
|
5
|
-
const ColumnExpr_1 = require("../ColumnExpr");
|
|
6
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
class WhenThenChain {
|
|
8
|
-
predicates;
|
|
9
|
-
values;
|
|
10
|
-
constructor(predicates, values) {
|
|
11
|
-
this.predicates = predicates;
|
|
12
|
-
this.values = values;
|
|
13
|
-
}
|
|
14
|
-
then(value) {
|
|
15
|
-
return new WhenThen(this.predicates, this.values.concat(value));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.WhenThenChain = WhenThenChain;
|
|
19
|
-
class When {
|
|
20
|
-
predicates;
|
|
21
|
-
constructor(predicate) {
|
|
22
|
-
this.predicates = [predicate];
|
|
23
|
-
}
|
|
24
|
-
then(value) {
|
|
25
|
-
return new WhenThen(this.predicates, [value]);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.When = When;
|
|
29
|
-
class WhenThen extends ColumnExpr_1.ColumnExpr {
|
|
30
|
-
predicates;
|
|
31
|
-
values;
|
|
32
|
-
otherwiseValue;
|
|
33
|
-
constructor(predicates, values, otherwiseValue = null) {
|
|
34
|
-
super(typeof predicates === "string" ? predicates : "*when*");
|
|
35
|
-
this.predicates = Array.isArray(predicates) ? predicates : [];
|
|
36
|
-
this.values = values || [];
|
|
37
|
-
this.otherwiseValue = otherwiseValue;
|
|
38
|
-
this.ops.push((_, columns) => {
|
|
39
|
-
const height = _.length;
|
|
40
|
-
const evaluateArg = (arg) => {
|
|
41
|
-
if (arg && typeof arg === "object" && "evaluate" in arg) {
|
|
42
|
-
return arg.evaluate(columns, height);
|
|
43
|
-
}
|
|
44
|
-
if (typeof arg === "string" && (arg in columns)) {
|
|
45
|
-
return columns[arg];
|
|
46
|
-
}
|
|
47
|
-
return arg;
|
|
48
|
-
};
|
|
49
|
-
const evaluatedPreds = this.predicates.map(evaluateArg);
|
|
50
|
-
const evaluatedVals = this.values.map(evaluateArg);
|
|
51
|
-
const evaluatedOtherwise = evaluateArg(this.otherwiseValue);
|
|
52
|
-
const result = new Array(height);
|
|
53
|
-
const numConditions = evaluatedPreds.length;
|
|
54
|
-
for (let i = 0; i < height; i++) {
|
|
55
|
-
let matched = false;
|
|
56
|
-
for (let j = 0; j < numConditions; j++) {
|
|
57
|
-
const predVal = (0, utils_1.isArrayOrTypedArray)(evaluatedPreds[j]) ? evaluatedPreds[j][i] : evaluatedPreds[j];
|
|
58
|
-
if (predVal === true) {
|
|
59
|
-
result[i] = (0, utils_1.isArrayOrTypedArray)(evaluatedVals[j]) ? evaluatedVals[j][i] : evaluatedVals[j];
|
|
60
|
-
matched = true;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (!matched) {
|
|
65
|
-
result[i] = (0, utils_1.isArrayOrTypedArray)(evaluatedOtherwise) ? evaluatedOtherwise[i] : evaluatedOtherwise;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
when(predicate) {
|
|
72
|
-
return new WhenThenChain(this.predicates.concat(predicate), this.values);
|
|
73
|
-
}
|
|
74
|
-
otherwise(value) {
|
|
75
|
-
return new WhenThen(this.predicates, this.values, value);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.WhenThen = WhenThen;
|
|
79
|
-
function when(predicate) {
|
|
80
|
-
return new When(predicate);
|
|
81
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.resolveColumnSelectors = resolveColumnSelectors;
|
|
18
|
-
const ColumnExpr_1 = require("./ColumnExpr");
|
|
19
|
-
const constants_1 = require("./constants");
|
|
20
|
-
__exportStar(require("./constants"), exports);
|
|
21
|
-
__exportStar(require("./types"), exports);
|
|
22
|
-
__exportStar(require("./ExprBase"), exports);
|
|
23
|
-
__exportStar(require("./mixins/ArithmeticExpr"), exports);
|
|
24
|
-
__exportStar(require("./mixins/LogicalExpr"), exports);
|
|
25
|
-
__exportStar(require("./mixins/ComparisonExpr"), exports);
|
|
26
|
-
__exportStar(require("./mixins/StringExpr"), exports);
|
|
27
|
-
__exportStar(require("./mixins/AggregationExpr"), exports);
|
|
28
|
-
__exportStar(require("./mixins/WindowExpr"), exports);
|
|
29
|
-
__exportStar(require("./mixins/TemporalExpr"), exports);
|
|
30
|
-
__exportStar(require("./mixins/ListExpr"), exports);
|
|
31
|
-
__exportStar(require("./ColumnExpr"), exports);
|
|
32
|
-
__exportStar(require("./functions/lit"), exports);
|
|
33
|
-
__exportStar(require("./functions/all"), exports);
|
|
34
|
-
__exportStar(require("./functions/exclude"), exports);
|
|
35
|
-
__exportStar(require("./functions/coalesce"), exports);
|
|
36
|
-
__exportStar(require("./functions/when"), exports);
|
|
37
|
-
function resolveColumnSelectors(exprs, allKeys, keysToExcludeFromAll) {
|
|
38
|
-
const expanded = [];
|
|
39
|
-
const excludeSet = keysToExcludeFromAll ? new Set(keysToExcludeFromAll) : new Set();
|
|
40
|
-
for (const expr of exprs) {
|
|
41
|
-
if (typeof expr === "string") {
|
|
42
|
-
expanded.push(new ColumnExpr_1.ColumnExpr(expr));
|
|
43
|
-
}
|
|
44
|
-
else if (expr instanceof ColumnExpr_1.ColumnExpr && expr.colName === constants_1.ALL_COLUMNS_MARKER) {
|
|
45
|
-
const excluded = new Set(expr.excludedCols);
|
|
46
|
-
for (const key of allKeys) {
|
|
47
|
-
if (!excludeSet.has(key) && !excluded.has(key)) {
|
|
48
|
-
const concrete = new ColumnExpr_1.ColumnExpr(key);
|
|
49
|
-
concrete.ops = [...expr.ops];
|
|
50
|
-
concrete.aggFn = expr.aggFn;
|
|
51
|
-
concrete.partitionOpsIndex = expr.partitionOpsIndex;
|
|
52
|
-
concrete.groupingOpsIndex = expr.groupingOpsIndex;
|
|
53
|
-
concrete.partitionBy = expr.partitionBy;
|
|
54
|
-
if (expr.evaluateWindow) {
|
|
55
|
-
concrete.evaluateWindow = expr.evaluateWindow;
|
|
56
|
-
}
|
|
57
|
-
if (expr.outputName && expr.outputName !== constants_1.ALL_COLUMNS_MARKER) {
|
|
58
|
-
concrete.outputName = expr.outputName;
|
|
59
|
-
}
|
|
60
|
-
expanded.push(concrete);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (expr && typeof expr === 'object' && 'evaluate' in expr && !expr.colName) {
|
|
65
|
-
for (const key of allKeys) {
|
|
66
|
-
if (!excludeSet.has(key)) {
|
|
67
|
-
const concrete = new ColumnExpr_1.ColumnExpr(key);
|
|
68
|
-
concrete.ops = [...expr.ops];
|
|
69
|
-
concrete.aggFn = expr.aggFn;
|
|
70
|
-
concrete.groupingOpsIndex = expr.groupingOpsIndex;
|
|
71
|
-
concrete.partitionOpsIndex = expr.partitionOpsIndex;
|
|
72
|
-
expanded.push(concrete);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
expanded.push(expr);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return expanded;
|
|
81
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AggregationExpr = void 0;
|
|
4
|
-
const ExprBase_1 = require("../ExprBase");
|
|
5
|
-
const exceptions_1 = require("../../exceptions");
|
|
6
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
const AggregationExpr = (Base) => {
|
|
8
|
-
return class extends Base {
|
|
9
|
-
aggFn = this.aggFn || null;
|
|
10
|
-
_deriveAgg(fn) {
|
|
11
|
-
const newInst = (0, ExprBase_1.derive)(this);
|
|
12
|
-
newInst.aggFn = fn;
|
|
13
|
-
newInst.groupingOpsIndex = this.ops.length;
|
|
14
|
-
newInst.partitionOpsIndex = this.ops.length;
|
|
15
|
-
return newInst;
|
|
16
|
-
}
|
|
17
|
-
all() {
|
|
18
|
-
return this._deriveAgg(v => {
|
|
19
|
-
for (let i = 0; i < v.length; i++) {
|
|
20
|
-
if (!v[i])
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
all_null() {
|
|
27
|
-
return this._deriveAgg(v => {
|
|
28
|
-
for (let i = 0; i < v.length; i++) {
|
|
29
|
-
if (v[i] != null)
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
any() {
|
|
36
|
-
return this._deriveAgg(v => {
|
|
37
|
-
for (let i = 0; i < v.length; i++) {
|
|
38
|
-
if (v[i])
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
any_null() {
|
|
45
|
-
return this._deriveAgg(v => {
|
|
46
|
-
for (let i = 0; i < v.length; i++) {
|
|
47
|
-
if (v[i] == null)
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
avg() {
|
|
54
|
-
return this._deriveAgg(v => (0, utils_1.getListStats)(v).mean);
|
|
55
|
-
}
|
|
56
|
-
count(options = {}) {
|
|
57
|
-
if (options.includeNulls)
|
|
58
|
-
return this._deriveAgg(v => v.length);
|
|
59
|
-
return this._deriveAgg(v => (0, utils_1.getListStats)(v).count);
|
|
60
|
-
}
|
|
61
|
-
first() {
|
|
62
|
-
return this._deriveAgg(v => v[0] ?? null);
|
|
63
|
-
}
|
|
64
|
-
last() {
|
|
65
|
-
return this._deriveAgg(v => v[v.length - 1] ?? null);
|
|
66
|
-
}
|
|
67
|
-
max() {
|
|
68
|
-
return this._deriveAgg(v => (0, utils_1.getListStats)(v).max);
|
|
69
|
-
}
|
|
70
|
-
mean() {
|
|
71
|
-
return this.avg();
|
|
72
|
-
}
|
|
73
|
-
median() {
|
|
74
|
-
return this._deriveAgg(v => {
|
|
75
|
-
if (!(0, utils_1.isArrayOfType)(v, "number", { allowNulls: true }))
|
|
76
|
-
return null;
|
|
77
|
-
const len = v.length;
|
|
78
|
-
const nums = [];
|
|
79
|
-
for (let i = 0; i < len; i++) {
|
|
80
|
-
const val = v[i];
|
|
81
|
-
if (val != null) {
|
|
82
|
-
nums.push(val);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const numsLen = nums.length;
|
|
86
|
-
if (numsLen === 0)
|
|
87
|
-
return null;
|
|
88
|
-
nums.sort((a, b) => a - b);
|
|
89
|
-
const mid = Math.floor(numsLen / 2);
|
|
90
|
-
return numsLen % 2 !== 0
|
|
91
|
-
? nums[mid]
|
|
92
|
-
: (nums[mid - 1] + nums[mid]) / 2;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
min() {
|
|
96
|
-
return this._deriveAgg(v => (0, utils_1.getListStats)(v).min);
|
|
97
|
-
}
|
|
98
|
-
mode() {
|
|
99
|
-
return this._deriveAgg(v => {
|
|
100
|
-
if (!(0, utils_1.isArrayOrTypedArray)(v))
|
|
101
|
-
return null;
|
|
102
|
-
const len = v.length;
|
|
103
|
-
const counts = new Map();
|
|
104
|
-
let maxCount = 0;
|
|
105
|
-
for (let i = 0; i < len; i++) {
|
|
106
|
-
const val = v[i];
|
|
107
|
-
if (val == null)
|
|
108
|
-
continue;
|
|
109
|
-
const c = (counts.get(val) ?? 0) + 1;
|
|
110
|
-
counts.set(val, c);
|
|
111
|
-
if (c > maxCount)
|
|
112
|
-
maxCount = c;
|
|
113
|
-
}
|
|
114
|
-
if (maxCount === 0)
|
|
115
|
-
return null;
|
|
116
|
-
const modes = [];
|
|
117
|
-
for (const [val, c] of counts.entries()) {
|
|
118
|
-
if (c === maxCount) {
|
|
119
|
-
modes.push(val);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (modes.length === 0)
|
|
123
|
-
return null;
|
|
124
|
-
modes.sort((a, b) => {
|
|
125
|
-
if (a == null && b == null)
|
|
126
|
-
return 0;
|
|
127
|
-
if (a == null)
|
|
128
|
-
return 1;
|
|
129
|
-
if (b == null)
|
|
130
|
-
return -1;
|
|
131
|
-
if (a < b)
|
|
132
|
-
return -1;
|
|
133
|
-
if (a > b)
|
|
134
|
-
return 1;
|
|
135
|
-
return 0;
|
|
136
|
-
});
|
|
137
|
-
return modes[0];
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
n_unique() {
|
|
141
|
-
return this._deriveAgg(v => new Set(v).size);
|
|
142
|
-
}
|
|
143
|
-
quantile(q) {
|
|
144
|
-
if (q < 0 || q > 1)
|
|
145
|
-
throw new exceptions_1.ComputeError("Quantile q must be between 0 and 1");
|
|
146
|
-
return this._deriveAgg(v => {
|
|
147
|
-
const f = [];
|
|
148
|
-
for (let i = 0; i < v.length; i++) {
|
|
149
|
-
if (v[i] != null)
|
|
150
|
-
f.push(v[i]);
|
|
151
|
-
}
|
|
152
|
-
const fLen = f.length;
|
|
153
|
-
if (!fLen)
|
|
154
|
-
return null;
|
|
155
|
-
f.sort((a, b) => a - b);
|
|
156
|
-
const idx = (fLen - 1) * q;
|
|
157
|
-
const low = Math.floor(idx);
|
|
158
|
-
const high = Math.ceil(idx);
|
|
159
|
-
if (low === high)
|
|
160
|
-
return f[low];
|
|
161
|
-
return f[low] + (idx - low) * (f[high] - f[low]);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
std() {
|
|
165
|
-
return this._deriveAgg(v => (0, utils_1.getListStats)(v).std);
|
|
166
|
-
}
|
|
167
|
-
sum() {
|
|
168
|
-
return this._deriveAgg(v => (0, utils_1.getListStats)(v).sum);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
exports.AggregationExpr = AggregationExpr;
|