@quereus/quereus 4.9.0 → 4.11.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/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +19 -4
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/statement.d.ts.map +1 -1
- package/dist/src/core/statement.js +74 -15
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
- package/dist/src/func/builtins/aggregate.js +85 -33
- package/dist/src/func/builtins/aggregate.js.map +1 -1
- package/dist/src/func/builtins/explain.d.ts.map +1 -1
- package/dist/src/func/builtins/explain.js +9 -2
- package/dist/src/func/builtins/explain.js.map +1 -1
- package/dist/src/func/builtins/scalar.d.ts.map +1 -1
- package/dist/src/func/builtins/scalar.js +4 -2
- package/dist/src/func/builtins/scalar.js.map +1 -1
- package/dist/src/func/registration.d.ts +6 -0
- package/dist/src/func/registration.d.ts.map +1 -1
- package/dist/src/func/registration.js +1 -0
- package/dist/src/func/registration.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/planner/building/constraint-builder.d.ts +3 -2
- package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
- package/dist/src/planner/building/constraint-builder.js +15 -24
- package/dist/src/planner/building/constraint-builder.js.map +1 -1
- package/dist/src/planner/building/delete.d.ts.map +1 -1
- package/dist/src/planner/building/delete.js +7 -24
- package/dist/src/planner/building/delete.js.map +1 -1
- package/dist/src/planner/building/foreign-key-builder.d.ts +3 -2
- package/dist/src/planner/building/foreign-key-builder.d.ts.map +1 -1
- package/dist/src/planner/building/foreign-key-builder.js +13 -17
- package/dist/src/planner/building/foreign-key-builder.js.map +1 -1
- package/dist/src/planner/building/insert.d.ts.map +1 -1
- package/dist/src/planner/building/insert.js +16 -32
- package/dist/src/planner/building/insert.js.map +1 -1
- package/dist/src/planner/building/mutation-context.d.ts +63 -0
- package/dist/src/planner/building/mutation-context.d.ts.map +1 -0
- package/dist/src/planner/building/mutation-context.js +126 -0
- package/dist/src/planner/building/mutation-context.js.map +1 -0
- package/dist/src/planner/building/update.d.ts.map +1 -1
- package/dist/src/planner/building/update.js +7 -24
- package/dist/src/planner/building/update.js.map +1 -1
- package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
- package/dist/src/planner/nodes/scalar.js +13 -1
- package/dist/src/planner/nodes/scalar.js.map +1 -1
- package/dist/src/runtime/emission-context.d.ts +14 -1
- package/dist/src/runtime/emission-context.d.ts.map +1 -1
- package/dist/src/runtime/emission-context.js +17 -5
- package/dist/src/runtime/emission-context.js.map +1 -1
- package/dist/src/runtime/emit/aggregate-setup.d.ts +44 -8
- package/dist/src/runtime/emit/aggregate-setup.d.ts.map +1 -1
- package/dist/src/runtime/emit/aggregate-setup.js +79 -15
- package/dist/src/runtime/emit/aggregate-setup.js.map +1 -1
- package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
- package/dist/src/runtime/emit/aggregate.js +21 -106
- package/dist/src/runtime/emit/aggregate.js.map +1 -1
- package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
- package/dist/src/runtime/emit/alter-table.js +11 -2
- package/dist/src/runtime/emit/alter-table.js.map +1 -1
- package/dist/src/runtime/emit/asof-scan.js +1 -1
- package/dist/src/runtime/emit/asof-scan.js.map +1 -1
- package/dist/src/runtime/emit/between.d.ts +2 -0
- package/dist/src/runtime/emit/between.d.ts.map +1 -1
- package/dist/src/runtime/emit/between.js +7 -8
- package/dist/src/runtime/emit/between.js.map +1 -1
- package/dist/src/runtime/emit/binary.d.ts +27 -5
- package/dist/src/runtime/emit/binary.d.ts.map +1 -1
- package/dist/src/runtime/emit/binary.js +266 -177
- package/dist/src/runtime/emit/binary.js.map +1 -1
- package/dist/src/runtime/emit/case.d.ts +34 -0
- package/dist/src/runtime/emit/case.d.ts.map +1 -1
- package/dist/src/runtime/emit/case.js +18 -11
- package/dist/src/runtime/emit/case.js.map +1 -1
- package/dist/src/runtime/emit/cast.d.ts +2 -0
- package/dist/src/runtime/emit/cast.d.ts.map +1 -1
- package/dist/src/runtime/emit/cast.js +7 -5
- package/dist/src/runtime/emit/cast.js.map +1 -1
- package/dist/src/runtime/emit/column-reference.d.ts +3 -1
- package/dist/src/runtime/emit/column-reference.d.ts.map +1 -1
- package/dist/src/runtime/emit/column-reference.js +6 -2
- package/dist/src/runtime/emit/column-reference.js.map +1 -1
- package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
- package/dist/src/runtime/emit/constraint-check.js +17 -7
- package/dist/src/runtime/emit/constraint-check.js.map +1 -1
- package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
- package/dist/src/runtime/emit/dml-executor.js +26 -1
- package/dist/src/runtime/emit/dml-executor.js.map +1 -1
- package/dist/src/runtime/emit/filter.d.ts +1 -1
- package/dist/src/runtime/emit/filter.js +1 -1
- package/dist/src/runtime/emit/hash-aggregate.d.ts.map +1 -1
- package/dist/src/runtime/emit/hash-aggregate.js +18 -88
- package/dist/src/runtime/emit/hash-aggregate.js.map +1 -1
- package/dist/src/runtime/emit/literal.d.ts +14 -1
- package/dist/src/runtime/emit/literal.d.ts.map +1 -1
- package/dist/src/runtime/emit/literal.js +33 -7
- package/dist/src/runtime/emit/literal.js.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts +7 -1
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.js +121 -32
- package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
- package/dist/src/runtime/emit/parameter.d.ts +3 -1
- package/dist/src/runtime/emit/parameter.d.ts.map +1 -1
- package/dist/src/runtime/emit/parameter.js +7 -2
- package/dist/src/runtime/emit/parameter.js.map +1 -1
- package/dist/src/runtime/emit/scalar-function.d.ts +29 -1
- package/dist/src/runtime/emit/scalar-function.d.ts.map +1 -1
- package/dist/src/runtime/emit/scalar-function.js +66 -16
- package/dist/src/runtime/emit/scalar-function.js.map +1 -1
- package/dist/src/runtime/emit/scalar-op.d.ts +63 -0
- package/dist/src/runtime/emit/scalar-op.d.ts.map +1 -0
- package/dist/src/runtime/emit/scalar-op.js +37 -0
- package/dist/src/runtime/emit/scalar-op.js.map +1 -0
- package/dist/src/runtime/emit/scan.d.ts.map +1 -1
- package/dist/src/runtime/emit/scan.js +19 -1
- package/dist/src/runtime/emit/scan.js.map +1 -1
- package/dist/src/runtime/emit/temporal-arithmetic.d.ts +18 -8
- package/dist/src/runtime/emit/temporal-arithmetic.d.ts.map +1 -1
- package/dist/src/runtime/emit/temporal-arithmetic.js +29 -311
- package/dist/src/runtime/emit/temporal-arithmetic.js.map +1 -1
- package/dist/src/runtime/emit/unary.d.ts +2 -0
- package/dist/src/runtime/emit/unary.d.ts.map +1 -1
- package/dist/src/runtime/emit/unary.js +125 -53
- package/dist/src/runtime/emit/unary.js.map +1 -1
- package/dist/src/runtime/emitters.d.ts +22 -0
- package/dist/src/runtime/emitters.d.ts.map +1 -1
- package/dist/src/runtime/emitters.js +29 -0
- package/dist/src/runtime/emitters.js.map +1 -1
- package/dist/src/runtime/scalar-fusion.d.ts +47 -0
- package/dist/src/runtime/scalar-fusion.d.ts.map +1 -0
- package/dist/src/runtime/scalar-fusion.js +275 -0
- package/dist/src/runtime/scalar-fusion.js.map +1 -0
- package/dist/src/runtime/strict-flags.d.ts +9 -0
- package/dist/src/runtime/strict-flags.d.ts.map +1 -1
- package/dist/src/runtime/strict-flags.js +9 -0
- package/dist/src/runtime/strict-flags.js.map +1 -1
- package/dist/src/runtime/strict-fork.js +2 -2
- package/dist/src/runtime/strict-fork.js.map +1 -1
- package/dist/src/runtime/strict-representation.d.ts +78 -0
- package/dist/src/runtime/strict-representation.d.ts.map +1 -0
- package/dist/src/runtime/strict-representation.js +159 -0
- package/dist/src/runtime/strict-representation.js.map +1 -0
- package/dist/src/schema/catalog.d.ts +25 -2
- package/dist/src/schema/catalog.d.ts.map +1 -1
- package/dist/src/schema/catalog.js +35 -2
- package/dist/src/schema/catalog.js.map +1 -1
- package/dist/src/schema/constraint-builder.d.ts +15 -2
- package/dist/src/schema/constraint-builder.d.ts.map +1 -1
- package/dist/src/schema/constraint-builder.js +21 -5
- package/dist/src/schema/constraint-builder.js.map +1 -1
- package/dist/src/schema/function.d.ts +15 -0
- package/dist/src/schema/function.d.ts.map +1 -1
- package/dist/src/schema/function.js.map +1 -1
- package/dist/src/schema/manager.d.ts +13 -0
- package/dist/src/schema/manager.d.ts.map +1 -1
- package/dist/src/schema/manager.js +44 -11
- package/dist/src/schema/manager.js.map +1 -1
- package/dist/src/schema/table.d.ts +43 -0
- package/dist/src/schema/table.d.ts.map +1 -1
- package/dist/src/schema/table.js +80 -0
- package/dist/src/schema/table.js.map +1 -1
- package/dist/src/types/builtin-types.d.ts.map +1 -1
- package/dist/src/types/builtin-types.js +17 -8
- package/dist/src/types/builtin-types.js.map +1 -1
- package/dist/src/types/temporal-ops.d.ts +119 -0
- package/dist/src/types/temporal-ops.d.ts.map +1 -0
- package/dist/src/types/temporal-ops.js +348 -0
- package/dist/src/types/temporal-ops.js.map +1 -0
- package/dist/src/types/temporal-types.d.ts.map +1 -1
- package/dist/src/types/temporal-types.js +8 -3
- package/dist/src/types/temporal-types.js.map +1 -1
- package/dist/src/util/coercion.d.ts +22 -7
- package/dist/src/util/coercion.d.ts.map +1 -1
- package/dist/src/util/coercion.js +28 -15
- package/dist/src/util/coercion.js.map +1 -1
- package/dist/src/util/comparison.d.ts +25 -0
- package/dist/src/util/comparison.d.ts.map +1 -1
- package/dist/src/util/comparison.js +25 -0
- package/dist/src/util/comparison.js.map +1 -1
- package/dist/src/util/key-tuple-codec.d.ts +12 -3
- package/dist/src/util/key-tuple-codec.d.ts.map +1 -1
- package/dist/src/util/key-tuple-codec.js.map +1 -1
- package/dist/src/util/numeric-canonical.d.ts +26 -0
- package/dist/src/util/numeric-canonical.d.ts.map +1 -0
- package/dist/src/util/numeric-canonical.js +66 -0
- package/dist/src/util/numeric-canonical.js.map +1 -0
- package/dist/src/vtab/module.d.ts +25 -0
- package/dist/src/vtab/module.d.ts.map +1 -1
- package/package.json +4 -3
|
@@ -1,323 +1,29 @@
|
|
|
1
|
-
import { StatusCode } from "../../common/types.js";
|
|
2
|
-
import { QuereusError } from "../../common/errors.js";
|
|
3
|
-
import { asRun } from "../types.js";
|
|
4
|
-
import { emitPlanNode } from "../emitters.js";
|
|
5
|
-
import { Temporal } from 'temporal-polyfill';
|
|
6
1
|
import { TIMESPAN_TYPE } from "../../types/temporal-types.js";
|
|
7
|
-
|
|
8
|
-
* Check if a value is a date string (YYYY-MM-DD format)
|
|
9
|
-
*/
|
|
10
|
-
function isDateValue(v) {
|
|
11
|
-
if (typeof v !== 'string')
|
|
12
|
-
return false;
|
|
13
|
-
// Simple check for ISO 8601 date format
|
|
14
|
-
return /^\d{4}-\d{2}-\d{2}$/.test(v);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Check if a value is a time string (HH:MM:SS format)
|
|
18
|
-
*/
|
|
19
|
-
function isTimeValue(v) {
|
|
20
|
-
if (typeof v !== 'string')
|
|
21
|
-
return false;
|
|
22
|
-
// Simple check for ISO 8601 time format
|
|
23
|
-
return /^\d{2}:\d{2}:\d{2}/.test(v);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Check if a value is a datetime string (ISO 8601 format)
|
|
27
|
-
*/
|
|
28
|
-
function isDateTimeValue(v) {
|
|
29
|
-
if (typeof v !== 'string')
|
|
30
|
-
return false;
|
|
31
|
-
// Check for ISO 8601 datetime format (with T separator)
|
|
32
|
-
return v.includes('T') && /^\d{4}-\d{2}-\d{2}T/.test(v);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Check if a value is a timespan/duration string (ISO 8601 duration format)
|
|
36
|
-
*/
|
|
37
|
-
function isTimespanValue(v) {
|
|
38
|
-
if (typeof v !== 'string')
|
|
39
|
-
return false;
|
|
40
|
-
// ISO 8601 duration starts with P (or -P for negative)
|
|
41
|
-
return v.startsWith('P') || v.startsWith('-P');
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Check if a Temporal.Duration contains calendar units (years, months, weeks)
|
|
45
|
-
* that cannot be converted to a single time unit without a relativeTo reference.
|
|
46
|
-
*/
|
|
47
|
-
function hasCalendarUnits(d) {
|
|
48
|
-
return d.years !== 0 || d.months !== 0 || d.weeks !== 0;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Scale each field of a duration by a factor.
|
|
52
|
-
* Works for both calendar and non-calendar durations.
|
|
53
|
-
*/
|
|
54
|
-
function scaleDuration(d, factor) {
|
|
55
|
-
return Temporal.Duration.from({
|
|
56
|
-
years: d.years * factor,
|
|
57
|
-
months: d.months * factor,
|
|
58
|
-
weeks: d.weeks * factor,
|
|
59
|
-
days: d.days * factor,
|
|
60
|
-
hours: d.hours * factor,
|
|
61
|
-
minutes: d.minutes * factor,
|
|
62
|
-
seconds: d.seconds * factor,
|
|
63
|
-
milliseconds: d.milliseconds * factor,
|
|
64
|
-
microseconds: d.microseconds * factor,
|
|
65
|
-
nanoseconds: d.nanoseconds * factor,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Divide a duration's fields by a divisor, cascading remainders to smaller units.
|
|
70
|
-
* Cascade chain: years→months(×12), weeks→days(×7), days→hours(×24),
|
|
71
|
-
* hours→minutes(×60), minutes→seconds(×60), seconds→ms(×1000),
|
|
72
|
-
* ms→μs(×1000), μs→ns(×1000).
|
|
73
|
-
* Note: months cannot cascade to days (variable month length).
|
|
74
|
-
*/
|
|
75
|
-
function divideDuration(d, divisor) {
|
|
76
|
-
// Cascade pairs: [field, next-field, conversion-factor]
|
|
77
|
-
const cascade = [
|
|
78
|
-
['years', 'months', 12],
|
|
79
|
-
// months→days gap: no fixed conversion
|
|
80
|
-
['weeks', 'days', 7],
|
|
81
|
-
['days', 'hours', 24],
|
|
82
|
-
['hours', 'minutes', 60],
|
|
83
|
-
['minutes', 'seconds', 60],
|
|
84
|
-
['seconds', 'milliseconds', 1000],
|
|
85
|
-
['milliseconds', 'microseconds', 1000],
|
|
86
|
-
['microseconds', 'nanoseconds', 1000],
|
|
87
|
-
];
|
|
88
|
-
// Build a mutable map of field values
|
|
89
|
-
const fields = {
|
|
90
|
-
years: d.years, months: d.months, weeks: d.weeks,
|
|
91
|
-
days: d.days, hours: d.hours, minutes: d.minutes,
|
|
92
|
-
seconds: d.seconds, milliseconds: d.milliseconds,
|
|
93
|
-
microseconds: d.microseconds, nanoseconds: d.nanoseconds,
|
|
94
|
-
};
|
|
95
|
-
for (const [field, nextField, factor] of cascade) {
|
|
96
|
-
const value = fields[field];
|
|
97
|
-
const quotient = Math.trunc(value / divisor);
|
|
98
|
-
const remainder = value - quotient * divisor;
|
|
99
|
-
fields[field] = quotient;
|
|
100
|
-
fields[nextField] += remainder * factor;
|
|
101
|
-
}
|
|
102
|
-
// Final field (nanoseconds) — just divide, truncate to integer
|
|
103
|
-
fields['nanoseconds'] = Math.trunc(fields['nanoseconds'] / divisor);
|
|
104
|
-
// Handle months independently (not part of cascade chain above for months→days)
|
|
105
|
-
// months was already accumulated from years cascade; now divide it
|
|
106
|
-
const monthQuotient = Math.trunc(fields['months'] / divisor);
|
|
107
|
-
const monthRemainder = fields['months'] - monthQuotient * divisor;
|
|
108
|
-
fields['months'] = monthQuotient;
|
|
109
|
-
// Fractional months can't be converted to days; truncate
|
|
110
|
-
if (monthRemainder !== 0) {
|
|
111
|
-
// Best-effort: drop sub-month remainder since we can't convert to days
|
|
112
|
-
}
|
|
113
|
-
return Temporal.Duration.from({
|
|
114
|
-
years: fields['years'],
|
|
115
|
-
months: fields['months'],
|
|
116
|
-
weeks: fields['weeks'],
|
|
117
|
-
days: fields['days'],
|
|
118
|
-
hours: fields['hours'],
|
|
119
|
-
minutes: fields['minutes'],
|
|
120
|
-
seconds: fields['seconds'],
|
|
121
|
-
milliseconds: fields['milliseconds'],
|
|
122
|
-
microseconds: fields['microseconds'],
|
|
123
|
-
nanoseconds: fields['nanoseconds'],
|
|
124
|
-
});
|
|
125
|
-
}
|
|
2
|
+
import { isTemporalKind, runTemporalCase, temporalKindOfValue, temporalOpCase, unsupportedTemporalOp, } from "../../types/temporal-ops.js";
|
|
126
3
|
/**
|
|
127
4
|
* Try to perform temporal arithmetic on two values.
|
|
128
5
|
* Returns the result if successful, or undefined if the values are not temporal types.
|
|
129
6
|
* Throws QuereusError if the operation is invalid.
|
|
7
|
+
*
|
|
8
|
+
* Which combinations exist, what each produces, and what each announces as its result
|
|
9
|
+
* type all live in one table (`types/temporal-ops.ts`) that the planner reads too. This
|
|
10
|
+
* function is the *value-sniffed* entry into that table: it derives both operand kinds
|
|
11
|
+
* from the runtime values, which is the defined behavior whenever the declared types
|
|
12
|
+
* cannot settle the case (a TEXT column holding a duration string, for instance).
|
|
130
13
|
*/
|
|
131
14
|
export function tryTemporalArithmetic(operator, v1, v2) {
|
|
132
15
|
if (v1 === null || v2 === null)
|
|
133
16
|
return null;
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const isV2Date = isDateValue(v2);
|
|
140
|
-
const isV2Time = isTimeValue(v2);
|
|
141
|
-
const isV2DateTime = isDateTimeValue(v2);
|
|
142
|
-
const isV2Timespan = isTimespanValue(v2);
|
|
143
|
-
// If neither operand is temporal, return undefined to signal non-temporal operation
|
|
144
|
-
const isV1Temporal = isV1Date || isV1Time || isV1DateTime || isV1Timespan;
|
|
145
|
-
const isV2Temporal = isV2Date || isV2Time || isV2DateTime || isV2Timespan;
|
|
146
|
-
if (!isV1Temporal && !isV2Temporal) {
|
|
17
|
+
const lk = temporalKindOfValue(v1);
|
|
18
|
+
const rk = temporalKindOfValue(v2);
|
|
19
|
+
// Neither operand looks temporal — signal "not a temporal operation" so the caller
|
|
20
|
+
// falls through to numeric arithmetic. ('number' is a kind, but not a temporal one.)
|
|
21
|
+
if (!isTemporalKind(lk) && !isTemporalKind(rk))
|
|
147
22
|
return undefined;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
(isV1Date || isV1DateTime) &&
|
|
153
|
-
(isV2Date || isV2DateTime)) {
|
|
154
|
-
// Parse both values as dates
|
|
155
|
-
const date1 = isV1DateTime
|
|
156
|
-
? Temporal.PlainDateTime.from(v1).toPlainDate()
|
|
157
|
-
: Temporal.PlainDate.from(v1);
|
|
158
|
-
const date2 = isV2DateTime
|
|
159
|
-
? Temporal.PlainDateTime.from(v2).toPlainDate()
|
|
160
|
-
: Temporal.PlainDate.from(v2);
|
|
161
|
-
const duration = date1.since(date2);
|
|
162
|
-
return duration.toString();
|
|
163
|
-
}
|
|
164
|
-
// TIME - TIME → TIMESPAN
|
|
165
|
-
if (operator === '-' && isV1Time && isV2Time) {
|
|
166
|
-
const time1 = Temporal.PlainTime.from(v1);
|
|
167
|
-
const time2 = Temporal.PlainTime.from(v2);
|
|
168
|
-
const duration = time1.since(time2);
|
|
169
|
-
return duration.toString();
|
|
170
|
-
}
|
|
171
|
-
// DATE + TIMESPAN → DATE
|
|
172
|
-
if (operator === '+' && isV1Date && isV2Timespan) {
|
|
173
|
-
const date = Temporal.PlainDate.from(v1);
|
|
174
|
-
const duration = Temporal.Duration.from(v2);
|
|
175
|
-
const result = date.add(duration);
|
|
176
|
-
return result.toString();
|
|
177
|
-
}
|
|
178
|
-
// TIMESPAN + DATE → DATE (commutative)
|
|
179
|
-
if (operator === '+' && isV1Timespan && isV2Date) {
|
|
180
|
-
const duration = Temporal.Duration.from(v1);
|
|
181
|
-
const date = Temporal.PlainDate.from(v2);
|
|
182
|
-
const result = date.add(duration);
|
|
183
|
-
return result.toString();
|
|
184
|
-
}
|
|
185
|
-
// DATE - TIMESPAN → DATE
|
|
186
|
-
if (operator === '-' && isV1Date && isV2Timespan) {
|
|
187
|
-
const date = Temporal.PlainDate.from(v1);
|
|
188
|
-
const duration = Temporal.Duration.from(v2);
|
|
189
|
-
const result = date.subtract(duration);
|
|
190
|
-
return result.toString();
|
|
191
|
-
}
|
|
192
|
-
// DATETIME + TIMESPAN → DATETIME
|
|
193
|
-
if (operator === '+' && isV1DateTime && isV2Timespan) {
|
|
194
|
-
const dt = Temporal.PlainDateTime.from(v1);
|
|
195
|
-
const duration = Temporal.Duration.from(v2);
|
|
196
|
-
const result = dt.add(duration);
|
|
197
|
-
return result.toString();
|
|
198
|
-
}
|
|
199
|
-
// TIMESPAN + DATETIME → DATETIME (commutative)
|
|
200
|
-
if (operator === '+' && isV1Timespan && isV2DateTime) {
|
|
201
|
-
const duration = Temporal.Duration.from(v1);
|
|
202
|
-
const dt = Temporal.PlainDateTime.from(v2);
|
|
203
|
-
const result = dt.add(duration);
|
|
204
|
-
return result.toString();
|
|
205
|
-
}
|
|
206
|
-
// DATETIME - TIMESPAN → DATETIME
|
|
207
|
-
if (operator === '-' && isV1DateTime && isV2Timespan) {
|
|
208
|
-
const dt = Temporal.PlainDateTime.from(v1);
|
|
209
|
-
const duration = Temporal.Duration.from(v2);
|
|
210
|
-
const result = dt.subtract(duration);
|
|
211
|
-
return result.toString();
|
|
212
|
-
}
|
|
213
|
-
// TIME + TIMESPAN → TIME
|
|
214
|
-
if (operator === '+' && isV1Time && isV2Timespan) {
|
|
215
|
-
const time = Temporal.PlainTime.from(v1);
|
|
216
|
-
const duration = Temporal.Duration.from(v2);
|
|
217
|
-
const result = time.add(duration);
|
|
218
|
-
return result.toString();
|
|
219
|
-
}
|
|
220
|
-
// TIMESPAN + TIME → TIME (commutative)
|
|
221
|
-
if (operator === '+' && isV1Timespan && isV2Time) {
|
|
222
|
-
const duration = Temporal.Duration.from(v1);
|
|
223
|
-
const time = Temporal.PlainTime.from(v2);
|
|
224
|
-
const result = time.add(duration);
|
|
225
|
-
return result.toString();
|
|
226
|
-
}
|
|
227
|
-
// TIME - TIMESPAN → TIME
|
|
228
|
-
if (operator === '-' && isV1Time && isV2Timespan) {
|
|
229
|
-
const time = Temporal.PlainTime.from(v1);
|
|
230
|
-
const duration = Temporal.Duration.from(v2);
|
|
231
|
-
const result = time.subtract(duration);
|
|
232
|
-
return result.toString();
|
|
233
|
-
}
|
|
234
|
-
// TIMESPAN + TIMESPAN → TIMESPAN
|
|
235
|
-
if (operator === '+' && isV1Timespan && isV2Timespan) {
|
|
236
|
-
const d1 = Temporal.Duration.from(v1);
|
|
237
|
-
const d2 = Temporal.Duration.from(v2);
|
|
238
|
-
const result = d1.add(d2);
|
|
239
|
-
return result.toString();
|
|
240
|
-
}
|
|
241
|
-
// TIMESPAN - TIMESPAN → TIMESPAN
|
|
242
|
-
if (operator === '-' && isV1Timespan && isV2Timespan) {
|
|
243
|
-
const d1 = Temporal.Duration.from(v1);
|
|
244
|
-
const d2 = Temporal.Duration.from(v2);
|
|
245
|
-
const result = d1.subtract(d2);
|
|
246
|
-
return result.toString();
|
|
247
|
-
}
|
|
248
|
-
// TIMESPAN * NUMBER → TIMESPAN
|
|
249
|
-
if (operator === '*' && isV1Timespan && typeof v2 === 'number') {
|
|
250
|
-
const duration = Temporal.Duration.from(v1);
|
|
251
|
-
if (hasCalendarUnits(duration)) {
|
|
252
|
-
return scaleDuration(duration, v2).toString();
|
|
253
|
-
}
|
|
254
|
-
const totalSeconds = duration.total({ unit: 'seconds' });
|
|
255
|
-
const newDuration = Temporal.Duration.from({ seconds: totalSeconds * v2 });
|
|
256
|
-
return newDuration.toString();
|
|
257
|
-
}
|
|
258
|
-
// NUMBER * TIMESPAN → TIMESPAN (commutative)
|
|
259
|
-
if (operator === '*' && typeof v1 === 'number' && isV2Timespan) {
|
|
260
|
-
const duration = Temporal.Duration.from(v2);
|
|
261
|
-
if (hasCalendarUnits(duration)) {
|
|
262
|
-
return scaleDuration(duration, v1).toString();
|
|
263
|
-
}
|
|
264
|
-
const totalSeconds = duration.total({ unit: 'seconds' });
|
|
265
|
-
const newDuration = Temporal.Duration.from({ seconds: totalSeconds * v1 });
|
|
266
|
-
return newDuration.toString();
|
|
267
|
-
}
|
|
268
|
-
// TIMESPAN / NUMBER → TIMESPAN
|
|
269
|
-
if (operator === '/' && isV1Timespan && typeof v2 === 'number') {
|
|
270
|
-
if (v2 === 0)
|
|
271
|
-
return null;
|
|
272
|
-
const duration = Temporal.Duration.from(v1);
|
|
273
|
-
if (hasCalendarUnits(duration)) {
|
|
274
|
-
return divideDuration(duration, v2).toString();
|
|
275
|
-
}
|
|
276
|
-
const totalSeconds = duration.total({ unit: 'seconds' });
|
|
277
|
-
const newDuration = Temporal.Duration.from({ seconds: totalSeconds / v2 });
|
|
278
|
-
return newDuration.toString();
|
|
279
|
-
}
|
|
280
|
-
// TIMESPAN / TIMESPAN → NUMBER (ratio)
|
|
281
|
-
if (operator === '/' && isV1Timespan && isV2Timespan) {
|
|
282
|
-
const d1 = Temporal.Duration.from(v1);
|
|
283
|
-
const d2 = Temporal.Duration.from(v2);
|
|
284
|
-
if (hasCalendarUnits(d1) || hasCalendarUnits(d2)) {
|
|
285
|
-
// Cannot compute a numeric ratio when calendar units are involved
|
|
286
|
-
// (months/years have variable lengths without a reference date)
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
const total1 = d1.total({ unit: 'seconds' });
|
|
290
|
-
const total2 = d2.total({ unit: 'seconds' });
|
|
291
|
-
if (total2 === 0)
|
|
292
|
-
return null;
|
|
293
|
-
return total1 / total2;
|
|
294
|
-
}
|
|
295
|
-
// If we get here, the operation is not supported
|
|
296
|
-
throw new QuereusError(`Unsupported temporal operation`, StatusCode.UNSUPPORTED);
|
|
297
|
-
}
|
|
298
|
-
catch (e) {
|
|
299
|
-
// Invalid temporal operation - return null
|
|
300
|
-
if (e instanceof QuereusError)
|
|
301
|
-
throw e;
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Emit temporal arithmetic operations
|
|
307
|
-
* Handles operations between temporal types (DATE, TIME, DATETIME, TIMESPAN)
|
|
308
|
-
*/
|
|
309
|
-
export function emitTemporalArithmetic(plan, ctx) {
|
|
310
|
-
const operator = plan.expression.operator;
|
|
311
|
-
function run(ctx, v1, v2) {
|
|
312
|
-
return tryTemporalArithmetic(operator, v1, v2) ?? null;
|
|
313
|
-
}
|
|
314
|
-
const leftExpr = emitPlanNode(plan.left, ctx);
|
|
315
|
-
const rightExpr = emitPlanNode(plan.right, ctx);
|
|
316
|
-
return {
|
|
317
|
-
params: [leftExpr, rightExpr],
|
|
318
|
-
run: asRun(run),
|
|
319
|
-
note: `${operator}(temporal)`
|
|
320
|
-
};
|
|
23
|
+
const entry = lk && rk ? temporalOpCase(operator, lk, rk) : undefined;
|
|
24
|
+
if (!entry)
|
|
25
|
+
unsupportedTemporalOp();
|
|
26
|
+
return runTemporalCase(entry, v1, v2);
|
|
321
27
|
}
|
|
322
28
|
/**
|
|
323
29
|
* Attempts to perform temporal comparison. Returns undefined if not a temporal comparison.
|
|
@@ -330,6 +36,18 @@ export function emitTemporalArithmetic(plan, ctx) {
|
|
|
330
36
|
* Note: DATE, TIME, and DATETIME use ISO 8601 format which compares correctly lexicographically,
|
|
331
37
|
* so they don't need special handling here.
|
|
332
38
|
*
|
|
39
|
+
* NOTE: deliberately NOT given the emit-time specialization `buildNumericOpSpec`'s temporal
|
|
40
|
+
* arm got. The shapes look alike, but the economics do not:
|
|
41
|
+
* - the per-row cost here is one `startsWith` per operand, not four regexes — TIMESPAN is
|
|
42
|
+
* the only temporal type whose text order differs from its semantic order, so it is the
|
|
43
|
+
* only one {@link tryTemporalCompare} probes for;
|
|
44
|
+
* - `buildComparisonOpSpec` already bypasses this function for the hot case: two operands
|
|
45
|
+
* of the same semantic-ordering type take the `sharedSemanticType` path
|
|
46
|
+
* (`=(compare-typed)`) and never reach the generic comparison run;
|
|
47
|
+
* - what is left is the mixed TIMESPAN-vs-TEXT/ANY shape, where runtime sniffing is the
|
|
48
|
+
* defined semantics and cannot be resolved from the declared types anyway.
|
|
49
|
+
* Revisit only if a profile shows the generic comparison run hot on temporal operands.
|
|
50
|
+
*
|
|
333
51
|
* @param operator The comparison operator (=, !=, <, <=, >, >=)
|
|
334
52
|
* @param v1 First value
|
|
335
53
|
* @param v2 Second value
|
|
@@ -367,7 +85,7 @@ export function tryTemporalComparison(operator, v1, v2) {
|
|
|
367
85
|
export function tryTemporalCompare(v1, v2) {
|
|
368
86
|
// Timespans are the only temporal type that needs special comparison logic
|
|
369
87
|
// because ISO 8601 duration strings don't compare correctly lexicographically
|
|
370
|
-
if (
|
|
88
|
+
if (temporalKindOfValue(v1) !== 'timespan' || temporalKindOfValue(v2) !== 'timespan')
|
|
371
89
|
return undefined;
|
|
372
90
|
return TIMESPAN_TYPE.compare(v1, v2);
|
|
373
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal-arithmetic.js","sourceRoot":"","sources":["../../../../src/runtime/emit/temporal-arithmetic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D;;GAEG;AACH,SAAS,WAAW,CAAC,CAAW;IAC/B,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACxC,wCAAwC;IACxC,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,CAAW;IAC/B,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;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CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAgB,EAAE,EAAY,EAAE,EAAY;IACjF,MAAM,GAAG,GAAG,kBAAkB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACvC,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAExC,QAAQ,QAAQ,EAAE,CAAC;QAClB,KAAK,GAAG,CAAC;QACT,KAAK,IAAI;YACR,OAAO,GAAG,KAAK,CAAC,CAAC;QAClB,KAAK,IAAI,CAAC;QACV,KAAK,IAAI;YACR,OAAO,GAAG,KAAK,CAAC,CAAC;QAClB,KAAK,GAAG;YACP,OAAO,GAAG,GAAG,CAAC,CAAC;QAChB,KAAK,IAAI;YACR,OAAO,GAAG,IAAI,CAAC,CAAC;QACjB,KAAK,GAAG;YACP,OAAO,GAAG,GAAG,CAAC,CAAC;QAChB,KAAK,IAAI;YACR,OAAO,GAAG,IAAI,CAAC,CAAC;QACjB;YACC,OAAO,SAAS,CAAC;IACnB,CAAC;AACF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAY,EAAE,EAAY;IAC5D,2EAA2E;IAC3E,8EAA8E;IAC9E,IAAI,mBAAmB,CAAC,EAAE,CAAC,KAAK,UAAU,IAAI,mBAAmB,CAAC,EAAE,CAAC,KAAK,UAAU;QAAE,OAAO,SAAS,CAAC;IACvG,OAAO,aAAa,CAAC,OAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Instruction } from "../types.js";
|
|
2
2
|
import type { UnaryOpNode } from "../../planner/nodes/scalar.js";
|
|
3
3
|
import type { EmissionContext } from "../emission-context.js";
|
|
4
|
+
import { type ScalarOpSpec } from "./scalar-op.js";
|
|
5
|
+
export declare function buildUnaryOpSpec(plan: UnaryOpNode): ScalarOpSpec;
|
|
4
6
|
export declare function emitUnaryOp(plan: UnaryOpNode, ctx: EmissionContext): Instruction;
|
|
5
7
|
//# sourceMappingURL=unary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unary.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/unary.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"unary.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/unary.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAyBjE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,CAoKhE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAEhF"}
|
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
import { StatusCode } from "../../common/types.js";
|
|
2
2
|
import { quereusError } from "../../common/errors.js";
|
|
3
|
-
import {
|
|
4
|
-
import { emitPlanNode } from "../emitters.js";
|
|
3
|
+
import { emitScalarOp } from "./scalar-op.js";
|
|
5
4
|
import { isTruthy } from "../../util/comparison.js";
|
|
5
|
+
import { canonicalizeInteger } from "../../util/numeric-canonical.js";
|
|
6
6
|
import { Temporal } from 'temporal-polyfill';
|
|
7
|
-
|
|
7
|
+
import { TIMESPAN_TYPE } from "../../types/temporal-types.js";
|
|
8
|
+
/**
|
|
9
|
+
* `~v = -v - 1` over the engine's arbitrary-precision integer domain.
|
|
10
|
+
*
|
|
11
|
+
* JS's `~` operator coerces through ToInt32 first, so it is only correct below 2^31:
|
|
12
|
+
* `~3000000000` evaluates to 1294967295 instead of -3000000001. Complement
|
|
13
|
+
* arithmetically instead and canonicalize the result (R1, util/numeric-canonical.ts) —
|
|
14
|
+
* `~(2^53 - 1)` leaves the safe range and must widen, `~(-2^53)` re-enters it and must
|
|
15
|
+
* narrow.
|
|
16
|
+
*
|
|
17
|
+
* A non-finite operand keeps the historical `~ToInt32(x)` result of -1; see the NaN
|
|
18
|
+
* note at the numeric-fast call site.
|
|
19
|
+
*/
|
|
20
|
+
function bitwiseNot(operand) {
|
|
21
|
+
const truncated = typeof operand === 'bigint' ? operand : Math.trunc(operand);
|
|
22
|
+
if (typeof truncated === 'number' && !Number.isFinite(truncated))
|
|
23
|
+
return -1;
|
|
24
|
+
const exact = canonicalizeInteger(truncated);
|
|
25
|
+
return canonicalizeInteger(typeof exact === 'bigint' ? -exact - 1n : -exact - 1);
|
|
26
|
+
}
|
|
27
|
+
export function buildUnaryOpSpec(plan) {
|
|
8
28
|
// Select the operation function at emit time
|
|
9
29
|
let run;
|
|
10
30
|
let note;
|
|
11
31
|
// Normalize operator to uppercase for case-insensitive matching
|
|
12
32
|
const operator = plan.expression.operator.toUpperCase();
|
|
33
|
+
// Plan-time operand type — drives the specialized arithmetic paths below.
|
|
34
|
+
const operandLogical = plan.operand.getType().logicalType;
|
|
13
35
|
switch (operator) {
|
|
14
36
|
case 'NOT':
|
|
15
37
|
run = (_ctx, operand) => {
|
|
@@ -60,65 +82,115 @@ export function emitUnaryOp(plan, ctx) {
|
|
|
60
82
|
};
|
|
61
83
|
note = 'IS NOT FALSE';
|
|
62
84
|
break;
|
|
63
|
-
case '-':
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
85
|
+
case '-': {
|
|
86
|
+
// Use plan-time type info to select a specialized run function, mirroring
|
|
87
|
+
// the binary arithmetic emitter's numeric-fast / temporal split.
|
|
88
|
+
if (operandLogical.isNumeric) {
|
|
89
|
+
run = (_ctx, operand) => {
|
|
90
|
+
if (operand === null)
|
|
91
|
+
return null;
|
|
92
|
+
// Bigint arm narrows the result back to number when it fits (R1);
|
|
93
|
+
// on canonical input negation preserves magnitude, so this only
|
|
94
|
+
// fires for a non-canonical bigint from a vtab/UDF.
|
|
95
|
+
return typeof operand === 'bigint' ? canonicalizeInteger(-operand) : -operand;
|
|
96
|
+
};
|
|
97
|
+
note = '-(numeric-fast)';
|
|
98
|
+
}
|
|
99
|
+
else if (operandLogical === TIMESPAN_TYPE) {
|
|
100
|
+
run = (_ctx, operand) => {
|
|
101
|
+
if (operand === null)
|
|
102
|
+
return null;
|
|
103
|
+
return Temporal.Duration.from(operand).negated().toString();
|
|
104
|
+
};
|
|
105
|
+
note = '-(timespan)';
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
run = (_ctx, operand) => {
|
|
109
|
+
if (operand === null)
|
|
110
|
+
return null;
|
|
111
|
+
// Check if it's a timespan (ISO 8601 duration string)
|
|
112
|
+
if (typeof operand === 'string' && (operand.startsWith('P') || operand.startsWith('-P'))) {
|
|
113
|
+
try {
|
|
114
|
+
const duration = Temporal.Duration.from(operand);
|
|
115
|
+
return duration.negated().toString();
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// Not a valid duration, fall through to numeric handling
|
|
119
|
+
}
|
|
72
120
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return isNaN(num) ? null : -num;
|
|
85
|
-
};
|
|
86
|
-
note = 'unary -';
|
|
121
|
+
// Numeric negation
|
|
122
|
+
if (typeof operand === 'number')
|
|
123
|
+
return -operand;
|
|
124
|
+
if (typeof operand === 'bigint')
|
|
125
|
+
return canonicalizeInteger(-operand);
|
|
126
|
+
// Try to convert to number
|
|
127
|
+
const num = Number(operand);
|
|
128
|
+
return isNaN(num) ? null : -num;
|
|
129
|
+
};
|
|
130
|
+
note = 'unary -';
|
|
131
|
+
}
|
|
87
132
|
break;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
133
|
+
}
|
|
134
|
+
case '+': {
|
|
135
|
+
if (operandLogical.isNumeric) {
|
|
136
|
+
// Already number/bigint — unary plus is the identity.
|
|
137
|
+
run = (_ctx, operand) => operand;
|
|
138
|
+
note = '+(numeric-fast)';
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
run = (_ctx, operand) => {
|
|
142
|
+
// Unary plus - convert to number if possible
|
|
143
|
+
if (operand === null)
|
|
144
|
+
return null;
|
|
145
|
+
if (typeof operand === 'number' || typeof operand === 'bigint')
|
|
146
|
+
return operand;
|
|
147
|
+
const plusNum = Number(operand);
|
|
148
|
+
return isNaN(plusNum) ? null : plusNum;
|
|
149
|
+
};
|
|
150
|
+
note = 'unary +';
|
|
151
|
+
}
|
|
99
152
|
break;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
153
|
+
}
|
|
154
|
+
case '~': {
|
|
155
|
+
if (operandLogical.isNumeric) {
|
|
156
|
+
// Already number/bigint — skip the Number() conversion attempt.
|
|
157
|
+
// NOTE: a NaN operand yields -1 here where the generic path below yields
|
|
158
|
+
// null. No numeric-typed expression can produce NaN today (arithmetic
|
|
159
|
+
// nulls out non-finite results, and REAL_TYPE.parse rejects 'NaN'); if a
|
|
160
|
+
// path ever admits NaN into a numeric-typed value, restore an isNaN check.
|
|
161
|
+
run = (_ctx, operand) => {
|
|
162
|
+
if (operand === null)
|
|
163
|
+
return null;
|
|
164
|
+
return bitwiseNot(operand);
|
|
165
|
+
};
|
|
166
|
+
note = '~(numeric-fast)';
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
run = (_ctx, operand) => {
|
|
170
|
+
if (operand === null)
|
|
171
|
+
return null;
|
|
172
|
+
if (typeof operand === 'bigint')
|
|
173
|
+
return bitwiseNot(operand);
|
|
174
|
+
// Convert to integer and apply bitwise NOT
|
|
175
|
+
const num = Number(operand);
|
|
176
|
+
if (isNaN(num))
|
|
177
|
+
return null;
|
|
178
|
+
return bitwiseNot(num);
|
|
179
|
+
};
|
|
180
|
+
note = 'bitwise ~';
|
|
181
|
+
}
|
|
113
182
|
break;
|
|
183
|
+
}
|
|
114
184
|
default:
|
|
115
185
|
quereusError(`Unsupported unary operator: ${plan.expression.operator}`, StatusCode.UNSUPPORTED, undefined, plan.expression);
|
|
116
186
|
}
|
|
117
|
-
const operandExpr = emitPlanNode(plan.operand, ctx);
|
|
118
187
|
return {
|
|
119
|
-
|
|
120
|
-
run
|
|
188
|
+
operands: [plan.operand],
|
|
189
|
+
run,
|
|
121
190
|
note
|
|
122
191
|
};
|
|
123
192
|
}
|
|
193
|
+
export function emitUnaryOp(plan, ctx) {
|
|
194
|
+
return emitScalarOp(buildUnaryOpSpec(plan), ctx);
|
|
195
|
+
}
|
|
124
196
|
//# sourceMappingURL=unary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unary.js","sourceRoot":"","sources":["../../../../src/runtime/emit/unary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"unary.js","sourceRoot":"","sources":["../../../../src/runtime/emit/unary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,YAAY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