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.
Files changed (142) hide show
  1. package/README.md +203 -38
  2. package/dist/api.d.ts +16 -8
  3. package/dist/columnExpressions/ColumnExpr.d.ts +26 -364
  4. package/dist/columnExpressions/ExprBase.d.ts +8 -11
  5. package/dist/columnExpressions/constants.d.ts +2 -0
  6. package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
  7. package/dist/columnExpressions/functions/element.d.ts +5 -0
  8. package/dist/columnExpressions/functions/implode.d.ts +3 -0
  9. package/dist/columnExpressions/functions/lit.d.ts +3 -1
  10. package/dist/columnExpressions/functions/seq_range.d.ts +31 -0
  11. package/dist/columnExpressions/functions/when.d.ts +2 -2
  12. package/dist/columnExpressions/index.d.ts +6 -3
  13. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +25 -50
  14. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +43 -67
  15. package/dist/columnExpressions/mixins/ArrayExpr.d.ts +39 -0
  16. package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +31 -60
  17. package/dist/columnExpressions/mixins/ListExpr.d.ts +16 -40
  18. package/dist/columnExpressions/mixins/LogicalExpr.d.ts +7 -33
  19. package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +6 -31
  20. package/dist/columnExpressions/mixins/StringExpr.d.ts +7 -32
  21. package/dist/columnExpressions/mixins/StructExpr.d.ts +16 -0
  22. package/dist/columnExpressions/mixins/TemporalExpr.d.ts +4 -30
  23. package/dist/columnExpressions/mixins/WindowExpr.d.ts +27 -49
  24. package/dist/columnExpressions/types.d.ts +1 -0
  25. package/dist/columnExpressions/utils.d.ts +4 -0
  26. package/dist/constants.d.ts +11 -0
  27. package/dist/dataframe/constants.d.ts +3 -0
  28. package/dist/dataframe/dataframe.d.ts +28 -11
  29. package/dist/dataframe/grouped/grouped.d.ts +2 -3
  30. package/dist/dataframe/types.d.ts +65 -1
  31. package/dist/dataframe/utils.d.ts +11 -3
  32. package/dist/datatypes/DataType.d.ts +2 -1
  33. package/dist/datatypes/index.d.ts +4 -3
  34. package/dist/datatypes/types.d.ts +42 -41
  35. package/dist/exceptions/index.d.ts +2 -0
  36. package/dist/exceptions/utils.d.ts +1 -0
  37. package/dist/functions/concat.d.ts +1 -2
  38. package/dist/functions/index.d.ts +3 -1
  39. package/dist/functions/read_csv.d.ts +8 -0
  40. package/dist/functions/read_json.d.ts +10 -0
  41. package/dist/index.js +6 -1
  42. package/dist/types.d.ts +34 -6
  43. package/dist/utils/array.d.ts +217 -0
  44. package/dist/utils/binary.d.ts +3 -0
  45. package/dist/utils/csv.d.ts +77 -0
  46. package/dist/utils/date.d.ts +21 -35
  47. package/dist/utils/guards.d.ts +11 -12
  48. package/dist/utils/index.d.ts +5 -2
  49. package/dist/utils/json.d.ts +120 -2
  50. package/dist/utils/list.d.ts +196 -2
  51. package/dist/utils/number.d.ts +47 -29
  52. package/dist/utils/object.d.ts +26 -0
  53. package/dist/utils/string.d.ts +7 -4
  54. package/package.json +6 -2
  55. package/dist/api.js +0 -18
  56. package/dist/bundle.min.js +0 -1
  57. package/dist/columnExpressions/ColumnExpr.js +0 -23
  58. package/dist/columnExpressions/ExprBase.js +0 -133
  59. package/dist/columnExpressions/constants.js +0 -5
  60. package/dist/columnExpressions/functions/all.js +0 -11
  61. package/dist/columnExpressions/functions/coalesce.js +0 -40
  62. package/dist/columnExpressions/functions/exclude.js +0 -13
  63. package/dist/columnExpressions/functions/lit.js +0 -22
  64. package/dist/columnExpressions/functions/when.js +0 -81
  65. package/dist/columnExpressions/index.js +0 -81
  66. package/dist/columnExpressions/mixins/AggregationExpr.js +0 -172
  67. package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -143
  68. package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -389
  69. package/dist/columnExpressions/mixins/ListExpr.js +0 -248
  70. package/dist/columnExpressions/mixins/LogicalExpr.js +0 -54
  71. package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -35
  72. package/dist/columnExpressions/mixins/StringExpr.js +0 -249
  73. package/dist/columnExpressions/mixins/TemporalExpr.js +0 -127
  74. package/dist/columnExpressions/mixins/WindowExpr.js +0 -281
  75. package/dist/columnExpressions/types.js +0 -2
  76. package/dist/dataframe/constants.js +0 -4
  77. package/dist/dataframe/dataframe.js +0 -749
  78. package/dist/dataframe/grouped/grouped.js +0 -113
  79. package/dist/dataframe/index.js +0 -20
  80. package/dist/dataframe/types.js +0 -2
  81. package/dist/dataframe/utils.js +0 -215
  82. package/dist/datatypes/DataType.js +0 -47
  83. package/dist/datatypes/index.js +0 -46
  84. package/dist/datatypes/types/Binary.d.ts +0 -9
  85. package/dist/datatypes/types/Binary.js +0 -18
  86. package/dist/datatypes/types/Boolean.d.ts +0 -9
  87. package/dist/datatypes/types/Boolean.js +0 -19
  88. package/dist/datatypes/types/Date.d.ts +0 -8
  89. package/dist/datatypes/types/Date.js +0 -21
  90. package/dist/datatypes/types/Datetime.d.ts +0 -8
  91. package/dist/datatypes/types/Datetime.js +0 -17
  92. package/dist/datatypes/types/Decimal.d.ts +0 -10
  93. package/dist/datatypes/types/Decimal.js +0 -28
  94. package/dist/datatypes/types/Duration.d.ts +0 -8
  95. package/dist/datatypes/types/Duration.js +0 -17
  96. package/dist/datatypes/types/Float32.d.ts +0 -8
  97. package/dist/datatypes/types/Float32.js +0 -17
  98. package/dist/datatypes/types/Float64.d.ts +0 -8
  99. package/dist/datatypes/types/Float64.js +0 -17
  100. package/dist/datatypes/types/Int16.d.ts +0 -8
  101. package/dist/datatypes/types/Int16.js +0 -17
  102. package/dist/datatypes/types/Int32.d.ts +0 -8
  103. package/dist/datatypes/types/Int32.js +0 -17
  104. package/dist/datatypes/types/Int64.d.ts +0 -8
  105. package/dist/datatypes/types/Int64.js +0 -17
  106. package/dist/datatypes/types/Int8.d.ts +0 -8
  107. package/dist/datatypes/types/Int8.js +0 -17
  108. package/dist/datatypes/types/List.d.ts +0 -10
  109. package/dist/datatypes/types/List.js +0 -31
  110. package/dist/datatypes/types/Null.d.ts +0 -9
  111. package/dist/datatypes/types/Null.js +0 -17
  112. package/dist/datatypes/types/Object.d.ts +0 -9
  113. package/dist/datatypes/types/Object.js +0 -17
  114. package/dist/datatypes/types/Struct.d.ts +0 -14
  115. package/dist/datatypes/types/Struct.js +0 -39
  116. package/dist/datatypes/types/Time.d.ts +0 -8
  117. package/dist/datatypes/types/Time.js +0 -29
  118. package/dist/datatypes/types/UInt16.d.ts +0 -8
  119. package/dist/datatypes/types/UInt16.js +0 -17
  120. package/dist/datatypes/types/UInt32.d.ts +0 -8
  121. package/dist/datatypes/types/UInt32.js +0 -17
  122. package/dist/datatypes/types/UInt64.d.ts +0 -8
  123. package/dist/datatypes/types/UInt64.js +0 -17
  124. package/dist/datatypes/types/UInt8.d.ts +0 -8
  125. package/dist/datatypes/types/UInt8.js +0 -17
  126. package/dist/datatypes/types/Utf8.d.ts +0 -10
  127. package/dist/datatypes/types/Utf8.js +0 -20
  128. package/dist/datatypes/types.js +0 -286
  129. package/dist/exceptions/index.js +0 -43
  130. package/dist/exceptions/utils.js +0 -9
  131. package/dist/functions/concat.js +0 -248
  132. package/dist/functions/index.js +0 -17
  133. package/dist/types.js +0 -2
  134. package/dist/utils/boolean.d.ts +0 -1
  135. package/dist/utils/boolean.js +0 -18
  136. package/dist/utils/date.js +0 -349
  137. package/dist/utils/guards.js +0 -143
  138. package/dist/utils/index.js +0 -21
  139. package/dist/utils/json.js +0 -33
  140. package/dist/utils/list.js +0 -128
  141. package/dist/utils/number.js +0 -223
  142. package/dist/utils/string.js +0 -120
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArithmeticExpr = void 0;
4
- const ExprBase_1 = require("../ExprBase");
5
- const utils_1 = require("../../utils");
6
- const ArithmeticExpr = (Base) => {
7
- return class extends Base {
8
- abs() {
9
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => Math.abs(v)));
10
- }
11
- acos() {
12
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => (v < -1 || v > 1) ? null : Math.acos(v)));
13
- }
14
- acosh() {
15
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v < 1 ? null : Math.acosh(v)));
16
- }
17
- add(val) {
18
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v + r));
19
- }
20
- asin() {
21
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => (v < -1 || v > 1) ? null : Math.asin(v)));
22
- }
23
- asinh() {
24
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.asinh));
25
- }
26
- atan() {
27
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.atan));
28
- }
29
- atanh() {
30
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => (v <= -1 || v >= 1) ? null : Math.atanh(v)));
31
- }
32
- cbrt() {
33
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.cbrt));
34
- }
35
- ceil() {
36
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.ceil));
37
- }
38
- clip(lower = null, upper = null) {
39
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => {
40
- if (lower !== null && upper !== null) {
41
- return (0, utils_1.clamp)({ val: v, min: lower, max: upper });
42
- }
43
- else if (lower !== null) {
44
- return Math.max(v, lower);
45
- }
46
- else if (upper !== null) {
47
- return Math.min(v, upper);
48
- }
49
- return v;
50
- }));
51
- }
52
- cos() {
53
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.cos));
54
- }
55
- cosh() {
56
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.cosh));
57
- }
58
- degrees() {
59
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v * (180 / Math.PI)));
60
- }
61
- div(val) {
62
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : v / r));
63
- }
64
- exp() {
65
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.exp));
66
- }
67
- expm1() {
68
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.expm1));
69
- }
70
- floor() {
71
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.floor));
72
- }
73
- floordiv(val) {
74
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : Math.floor(v / r)));
75
- }
76
- hypot(val) {
77
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => Math.hypot(v, r)));
78
- }
79
- log(base = Math.E) {
80
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v <= 0 ? null : (base === Math.E ? Math.log(v) : Math.log(v) / Math.log(base))));
81
- }
82
- log1p() {
83
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v <= -1 ? null : Math.log1p(v)));
84
- }
85
- mod(val) {
86
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : v % r));
87
- }
88
- mul(val) {
89
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v * r));
90
- }
91
- negate() {
92
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => -v));
93
- }
94
- pow(val) {
95
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => Math.pow(v, r)));
96
- }
97
- radians() {
98
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v * (Math.PI / 180)));
99
- }
100
- rand(seed, { min = 0, max = 1, integer = false } = {}) {
101
- return (0, ExprBase_1.derive)(this, (vArray) => {
102
- const len = vArray.length;
103
- const out = new Float64Array(len);
104
- const rnd = seed !== undefined ? (0, utils_1.mulberry32)(seed) : Math.random;
105
- const range = max - min;
106
- for (let i = 0; i < len; i++) {
107
- const raw = rnd();
108
- out[i] = integer ? Math.floor(raw * (range + 1)) + min : raw * range + min;
109
- }
110
- return out;
111
- });
112
- }
113
- round(decimals = 0) {
114
- const factor = Math.pow(10, decimals);
115
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => Math.round(v * factor) / factor));
116
- }
117
- sign() {
118
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.sign));
119
- }
120
- sin() {
121
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.sin));
122
- }
123
- sinh() {
124
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.sinh));
125
- }
126
- sqrt() {
127
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v < 0 ? null : Math.sqrt(v)));
128
- }
129
- sub(val) {
130
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v - r));
131
- }
132
- tan() {
133
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.tan));
134
- }
135
- tanh() {
136
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.tanh));
137
- }
138
- trunc() {
139
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.trunc));
140
- }
141
- };
142
- };
143
- exports.ArithmeticExpr = ArithmeticExpr;
@@ -1,389 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComparisonExpr = void 0;
4
- const ExprBase_1 = require("../ExprBase");
5
- const utils_1 = require("../../utils");
6
- function getCacheKey(val) {
7
- if (val == null) {
8
- return val;
9
- }
10
- if (val instanceof Date) {
11
- return `d:${val.getTime()}`;
12
- }
13
- if (val instanceof Uint8Array) {
14
- return `u:${val.toString()}`;
15
- }
16
- if (typeof val === "object" || typeof val === "function") {
17
- return String(val);
18
- }
19
- return val;
20
- }
21
- const ComparisonExpr = (Base) => {
22
- return class extends Base {
23
- between(lower, upper, closed = "both") {
24
- return (0, ExprBase_1.derive)(this, (vArray, columns) => {
25
- const height = vArray.length;
26
- const lResolved = this._resolve(lower, columns, height);
27
- const uResolved = this._resolve(upper, columns, height);
28
- const result = new Array(height);
29
- const isLArray = (0, utils_1.isArrayOrTypedArray)(lResolved);
30
- const isUArray = (0, utils_1.isArrayOrTypedArray)(uResolved);
31
- for (let i = 0; i < height; i++) {
32
- const v = vArray[i];
33
- const l = isLArray ? lResolved[i] : lResolved;
34
- const u = isUArray ? uResolved[i] : uResolved;
35
- if (v == null || l == null || u == null) {
36
- result[i] = null;
37
- }
38
- else {
39
- const geLower = closed === "both" || closed === "left" ? v >= l : v > l;
40
- const leUpper = closed === "both" || closed === "right" ? v <= u : v < u;
41
- result[i] = geLower && leUpper;
42
- }
43
- }
44
- return result;
45
- });
46
- }
47
- eq(val) {
48
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v === r));
49
- }
50
- eq_missing(val) {
51
- return (0, ExprBase_1.derive)(this, (vArray, columns) => {
52
- const height = vArray.length;
53
- const rResolved = this._resolve(val, columns, height);
54
- const result = new Array(height);
55
- if ((0, utils_1.isArrayOrTypedArray)(rResolved)) {
56
- for (let i = 0; i < height; i++) {
57
- const v = vArray[i];
58
- const r = rResolved[i];
59
- if (v == null && r == null)
60
- result[i] = true;
61
- else if (v == null || r == null)
62
- result[i] = false;
63
- else
64
- result[i] = v === r;
65
- }
66
- }
67
- else {
68
- for (let i = 0; i < height; i++) {
69
- const v = vArray[i];
70
- if (v == null && rResolved == null)
71
- result[i] = true;
72
- else if (v == null || rResolved == null)
73
- result[i] = false;
74
- else
75
- result[i] = v === rResolved;
76
- }
77
- }
78
- return result;
79
- });
80
- }
81
- ge(val) {
82
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v >= r));
83
- }
84
- gt(val) {
85
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v > r));
86
- }
87
- has_nulls() {
88
- return this._deriveAgg((v) => {
89
- for (let i = 0; i < v.length; i++) {
90
- if (v[i] == null)
91
- return true;
92
- }
93
- return false;
94
- });
95
- }
96
- is_close(other, options = {}) {
97
- const { abs_tol = 1e-8, rel_tol = 1e-8, nans_equal = false } = options;
98
- return (0, ExprBase_1.derive)(this, (vArray, columns) => {
99
- const height = vArray.length;
100
- const otherVal = this._resolve(other, columns, height);
101
- const isOtherArray = (0, utils_1.isArrayOrTypedArray)(otherVal);
102
- const result = new Array(height);
103
- for (let i = 0; i < height; i++) {
104
- const v = vArray[i];
105
- const o = isOtherArray ? otherVal[i] : otherVal;
106
- if (v == null || o == null) {
107
- result[i] = null;
108
- }
109
- else if (Number.isNaN(v) || Number.isNaN(o)) {
110
- if (nans_equal && Number.isNaN(v) && Number.isNaN(o)) {
111
- result[i] = true;
112
- }
113
- else {
114
- result[i] = false;
115
- }
116
- }
117
- else if (!Number.isFinite(v) || !Number.isFinite(o)) {
118
- result[i] = (v === o);
119
- }
120
- else {
121
- const absDiff = Math.abs(v - o);
122
- const threshold = Math.max(rel_tol * Math.max(Math.abs(v), Math.abs(o)), abs_tol);
123
- result[i] = absDiff <= threshold;
124
- }
125
- }
126
- return result;
127
- });
128
- }
129
- is_duplicated() {
130
- return (0, ExprBase_1.derive)(this, (vArray) => {
131
- const height = vArray.length;
132
- const counts = new Map();
133
- const keys = new Array(height);
134
- for (let i = 0; i < height; i++) {
135
- const k = getCacheKey(vArray[i]);
136
- keys[i] = k;
137
- counts.set(k, (counts.get(k) || 0) + 1);
138
- }
139
- const result = new Array(height);
140
- for (let i = 0; i < height; i++) {
141
- result[i] = (counts.get(keys[i]) || 0) > 1;
142
- }
143
- return result;
144
- });
145
- }
146
- is_empty(options = {}) {
147
- const { ignoreNulls = false } = options;
148
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => {
149
- if (typeof v === "string") {
150
- return v.length === 0;
151
- }
152
- if ((0, utils_1.isArrayOrTypedArray)(v)) {
153
- if (ignoreNulls) {
154
- const len = v.length;
155
- let nonNullCount = 0;
156
- for (let i = 0; i < len; i++) {
157
- if (v[i] != null) {
158
- nonNullCount++;
159
- }
160
- }
161
- return nonNullCount === 0;
162
- }
163
- return v.length === 0;
164
- }
165
- return null;
166
- }));
167
- }
168
- is_finite() {
169
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Number.isFinite));
170
- }
171
- is_first_distinct() {
172
- return (0, ExprBase_1.derive)(this, (vArray) => {
173
- const height = vArray.length;
174
- const seen = new Set();
175
- const result = new Array(height);
176
- for (let i = 0; i < height; i++) {
177
- const k = getCacheKey(vArray[i]);
178
- if (seen.has(k)) {
179
- result[i] = false;
180
- }
181
- else {
182
- seen.add(k);
183
- result[i] = true;
184
- }
185
- }
186
- return result;
187
- });
188
- }
189
- is_in(values) {
190
- return (0, ExprBase_1.derive)(this, (vArray, columns) => {
191
- const height = vArray.length;
192
- const result = new Array(height);
193
- if (values && typeof values === 'object' && 'evaluate' in values) {
194
- const resolved = values.evaluate(columns, height);
195
- for (let i = 0; i < height; i++) {
196
- const v = vArray[i];
197
- if (v == null) {
198
- result[i] = null;
199
- }
200
- else {
201
- const candidates = resolved[i];
202
- const set = new Set();
203
- if ((0, utils_1.isArrayOrTypedArray)(candidates)) {
204
- const cLen = candidates.length;
205
- for (let j = 0; j < cLen; j++) {
206
- set.add(getCacheKey(candidates[j]));
207
- }
208
- }
209
- else {
210
- set.add(getCacheKey(candidates));
211
- }
212
- result[i] = set.has(getCacheKey(v));
213
- }
214
- }
215
- }
216
- else {
217
- const arr = (0, utils_1.isArrayOrTypedArray)(values) ? values : [];
218
- const set = new Set();
219
- const arrLen = arr.length;
220
- for (let j = 0; j < arrLen; j++) {
221
- set.add(getCacheKey(arr[j]));
222
- }
223
- for (let i = 0; i < height; i++) {
224
- const v = vArray[i];
225
- result[i] = v == null ? null : set.has(getCacheKey(v));
226
- }
227
- }
228
- return result;
229
- });
230
- }
231
- is_infinite() {
232
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v === Infinity || v === -Infinity));
233
- }
234
- is_last_distinct() {
235
- return (0, ExprBase_1.derive)(this, (vArray) => {
236
- const height = vArray.length;
237
- const seen = new Set();
238
- const result = new Array(height);
239
- for (let i = height - 1; i >= 0; i--) {
240
- const k = getCacheKey(vArray[i]);
241
- if (seen.has(k)) {
242
- result[i] = false;
243
- }
244
- else {
245
- seen.add(k);
246
- result[i] = true;
247
- }
248
- }
249
- return result;
250
- });
251
- }
252
- is_n_distinct(n) {
253
- return this._deriveAgg((v) => {
254
- const set = new Set();
255
- const len = v.length;
256
- for (let i = 0; i < len; i++) {
257
- set.add(getCacheKey(v[i]));
258
- }
259
- return set.size === n;
260
- });
261
- }
262
- is_nan() {
263
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Number.isNaN));
264
- }
265
- is_not_nan() {
266
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => !Number.isNaN(v)));
267
- }
268
- is_not_null() {
269
- return (0, ExprBase_1.derive)(this, (vArray) => {
270
- const height = vArray.length;
271
- const result = new Array(height);
272
- for (let i = 0; i < height; i++) {
273
- result[i] = vArray[i] != null;
274
- }
275
- return result;
276
- });
277
- }
278
- is_null() {
279
- return (0, ExprBase_1.derive)(this, (vArray) => {
280
- const height = vArray.length;
281
- const result = new Array(height);
282
- for (let i = 0; i < height; i++) {
283
- result[i] = vArray[i] == null;
284
- }
285
- return result;
286
- });
287
- }
288
- is_unique() {
289
- return (0, ExprBase_1.derive)(this, (vArray) => {
290
- const height = vArray.length;
291
- const counts = new Map();
292
- const keys = new Array(height);
293
- for (let i = 0; i < height; i++) {
294
- const k = getCacheKey(vArray[i]);
295
- keys[i] = k;
296
- counts.set(k, (counts.get(k) || 0) + 1);
297
- }
298
- const result = new Array(height);
299
- for (let i = 0; i < height; i++) {
300
- result[i] = counts.get(keys[i]) === 1;
301
- }
302
- return result;
303
- });
304
- }
305
- le(val) {
306
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v <= r));
307
- }
308
- lt(val) {
309
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v < r));
310
- }
311
- ne(val) {
312
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v !== r));
313
- }
314
- ne_missing(val) {
315
- return (0, ExprBase_1.derive)(this, (vArray, columns) => {
316
- const height = vArray.length;
317
- const rResolved = this._resolve(val, columns, height);
318
- const result = new Array(height);
319
- if ((0, utils_1.isArrayOrTypedArray)(rResolved)) {
320
- for (let i = 0; i < height; i++) {
321
- const v = vArray[i];
322
- const r = rResolved[i];
323
- if (v == null && r == null)
324
- result[i] = false;
325
- else if (v == null || r == null)
326
- result[i] = true;
327
- else
328
- result[i] = v !== r;
329
- }
330
- }
331
- else {
332
- for (let i = 0; i < height; i++) {
333
- const v = vArray[i];
334
- if (v == null && rResolved == null)
335
- result[i] = false;
336
- else if (v == null || rResolved == null)
337
- result[i] = true;
338
- else
339
- result[i] = v !== rResolved;
340
- }
341
- }
342
- return result;
343
- });
344
- }
345
- not_in(values) {
346
- return (0, ExprBase_1.derive)(this, (vArray, columns) => {
347
- const height = vArray.length;
348
- const result = new Array(height);
349
- if (values && typeof values === 'object' && 'evaluate' in values) {
350
- const resolved = values.evaluate(columns, height);
351
- for (let i = 0; i < height; i++) {
352
- const v = vArray[i];
353
- if (v == null) {
354
- result[i] = null;
355
- }
356
- else {
357
- const candidates = resolved[i];
358
- const set = new Set();
359
- if ((0, utils_1.isArrayOrTypedArray)(candidates)) {
360
- const cLen = candidates.length;
361
- for (let j = 0; j < cLen; j++) {
362
- set.add(getCacheKey(candidates[j]));
363
- }
364
- }
365
- else {
366
- set.add(getCacheKey(candidates));
367
- }
368
- result[i] = !set.has(getCacheKey(v));
369
- }
370
- }
371
- }
372
- else {
373
- const arr = (0, utils_1.isArrayOrTypedArray)(values) ? values : [];
374
- const set = new Set();
375
- const arrLen = arr.length;
376
- for (let j = 0; j < arrLen; j++) {
377
- set.add(getCacheKey(arr[j]));
378
- }
379
- for (let i = 0; i < height; i++) {
380
- const v = vArray[i];
381
- result[i] = v == null ? null : !set.has(getCacheKey(v));
382
- }
383
- }
384
- return result;
385
- });
386
- }
387
- };
388
- };
389
- exports.ComparisonExpr = ComparisonExpr;