@databricks/sql 1.15.0 → 1.16.0-rc.1

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 (119) hide show
  1. package/dist/DBSQLClient.d.ts +3 -0
  2. package/dist/DBSQLClient.js +97 -56
  3. package/dist/DBSQLClient.js.map +1 -1
  4. package/dist/DBSQLLogger.d.ts +3 -0
  5. package/dist/DBSQLLogger.js +25 -0
  6. package/dist/DBSQLLogger.js.map +1 -1
  7. package/dist/DBSQLOperation.d.ts +36 -17
  8. package/dist/DBSQLOperation.js +133 -214
  9. package/dist/DBSQLOperation.js.map +1 -1
  10. package/dist/DBSQLParameter.d.ts +2 -0
  11. package/dist/DBSQLParameter.js +63 -7
  12. package/dist/DBSQLParameter.js.map +1 -1
  13. package/dist/DBSQLSession.d.ts +24 -17
  14. package/dist/DBSQLSession.js +45 -263
  15. package/dist/DBSQLSession.js.map +1 -1
  16. package/dist/connection/connections/HttpRetryPolicy.d.ts +3 -0
  17. package/dist/connection/connections/HttpRetryPolicy.js +116 -21
  18. package/dist/connection/connections/HttpRetryPolicy.js.map +1 -1
  19. package/dist/connection/connections/ThriftHttpConnection.js +18 -3
  20. package/dist/connection/connections/ThriftHttpConnection.js.map +1 -1
  21. package/dist/contracts/IBackend.d.ts +31 -0
  22. package/dist/contracts/IBackend.js +3 -0
  23. package/dist/contracts/IBackend.js.map +1 -0
  24. package/dist/contracts/IClientContext.d.ts +1 -0
  25. package/dist/contracts/IDBSQLClient.d.ts +31 -0
  26. package/dist/contracts/IDBSQLLogger.d.ts +17 -0
  27. package/dist/contracts/IDBSQLLogger.js.map +1 -1
  28. package/dist/contracts/IDBSQLSession.d.ts +24 -1
  29. package/dist/contracts/IOperation.d.ts +10 -1
  30. package/dist/contracts/IOperationBackend.d.ts +98 -0
  31. package/dist/contracts/IOperationBackend.js +3 -0
  32. package/dist/contracts/IOperationBackend.js.map +1 -0
  33. package/dist/contracts/ISessionBackend.d.ts +36 -0
  34. package/dist/contracts/ISessionBackend.js +3 -0
  35. package/dist/contracts/ISessionBackend.js.map +1 -0
  36. package/dist/contracts/InternalConnectionOptions.d.ts +72 -0
  37. package/dist/contracts/InternalConnectionOptions.js +3 -0
  38. package/dist/contracts/InternalConnectionOptions.js.map +1 -0
  39. package/dist/contracts/OperationStatus.d.ts +76 -0
  40. package/dist/contracts/OperationStatus.js +28 -0
  41. package/dist/contracts/OperationStatus.js.map +1 -0
  42. package/dist/contracts/ResultMetadata.d.ts +34 -0
  43. package/dist/contracts/ResultMetadata.js +16 -0
  44. package/dist/contracts/ResultMetadata.js.map +1 -0
  45. package/dist/errors/AuthenticationError.d.ts +1 -0
  46. package/dist/errors/AuthenticationError.js +4 -0
  47. package/dist/errors/AuthenticationError.js.map +1 -1
  48. package/dist/kernel/KernelArrowIpc.d.ts +54 -0
  49. package/dist/kernel/KernelArrowIpc.js +292 -0
  50. package/dist/kernel/KernelArrowIpc.js.map +1 -0
  51. package/dist/kernel/KernelArrowIpcDurationFix.d.ts +29 -0
  52. package/dist/kernel/KernelArrowIpcDurationFix.js +605 -0
  53. package/dist/kernel/KernelArrowIpcDurationFix.js.map +1 -0
  54. package/dist/kernel/KernelAuth.d.ts +300 -0
  55. package/dist/kernel/KernelAuth.js +463 -0
  56. package/dist/kernel/KernelAuth.js.map +1 -0
  57. package/dist/kernel/KernelBackend.d.ts +53 -0
  58. package/dist/kernel/KernelBackend.js +164 -0
  59. package/dist/kernel/KernelBackend.js.map +1 -0
  60. package/dist/kernel/KernelErrorMapping.d.ts +109 -0
  61. package/dist/kernel/KernelErrorMapping.js +249 -0
  62. package/dist/kernel/KernelErrorMapping.js.map +1 -0
  63. package/dist/kernel/KernelInputValidation.d.ts +16 -0
  64. package/dist/kernel/KernelInputValidation.js +49 -0
  65. package/dist/kernel/KernelInputValidation.js.map +1 -0
  66. package/dist/kernel/KernelLogging.d.ts +63 -0
  67. package/dist/kernel/KernelLogging.js +128 -0
  68. package/dist/kernel/KernelLogging.js.map +1 -0
  69. package/dist/kernel/KernelNativeLoader.d.ts +77 -0
  70. package/dist/kernel/KernelNativeLoader.js +178 -0
  71. package/dist/kernel/KernelNativeLoader.js.map +1 -0
  72. package/dist/kernel/KernelOperationBackend.d.ts +154 -0
  73. package/dist/kernel/KernelOperationBackend.js +640 -0
  74. package/dist/kernel/KernelOperationBackend.js.map +1 -0
  75. package/dist/kernel/KernelOperationLifecycle.d.ts +130 -0
  76. package/dist/kernel/KernelOperationLifecycle.js +245 -0
  77. package/dist/kernel/KernelOperationLifecycle.js.map +1 -0
  78. package/dist/kernel/KernelPositionalParams.d.ts +16 -0
  79. package/dist/kernel/KernelPositionalParams.js +120 -0
  80. package/dist/kernel/KernelPositionalParams.js.map +1 -0
  81. package/dist/kernel/KernelResultsProvider.d.ts +44 -0
  82. package/dist/kernel/KernelResultsProvider.js +102 -0
  83. package/dist/kernel/KernelResultsProvider.js.map +1 -0
  84. package/dist/kernel/KernelServerInfo.d.ts +44 -0
  85. package/dist/kernel/KernelServerInfo.js +73 -0
  86. package/dist/kernel/KernelServerInfo.js.map +1 -0
  87. package/dist/kernel/KernelSessionBackend.d.ts +100 -0
  88. package/dist/kernel/KernelSessionBackend.js +384 -0
  89. package/dist/kernel/KernelSessionBackend.js.map +1 -0
  90. package/dist/result/ArrowResultConverter.d.ts +31 -2
  91. package/dist/result/ArrowResultConverter.js +226 -14
  92. package/dist/result/ArrowResultConverter.js.map +1 -1
  93. package/dist/result/CloudFetchResultHandler.js +36 -8
  94. package/dist/result/CloudFetchResultHandler.js.map +1 -1
  95. package/dist/telemetry/DatabricksTelemetryExporter.js +34 -1
  96. package/dist/telemetry/DatabricksTelemetryExporter.js.map +1 -1
  97. package/dist/telemetry/telemetryTypeMappers.d.ts +1 -1
  98. package/dist/telemetry/telemetryTypeMappers.js +1 -1
  99. package/dist/telemetry/telemetryTypeMappers.js.map +1 -1
  100. package/dist/telemetry/types.d.ts +15 -0
  101. package/dist/thrift-backend/ThriftBackend.d.ts +17 -0
  102. package/dist/thrift-backend/ThriftBackend.js +80 -0
  103. package/dist/thrift-backend/ThriftBackend.js.map +1 -0
  104. package/dist/thrift-backend/ThriftOperationBackend.d.ts +70 -0
  105. package/dist/thrift-backend/ThriftOperationBackend.js +330 -0
  106. package/dist/thrift-backend/ThriftOperationBackend.js.map +1 -0
  107. package/dist/thrift-backend/ThriftSessionBackend.d.ts +36 -0
  108. package/dist/thrift-backend/ThriftSessionBackend.js +266 -0
  109. package/dist/thrift-backend/ThriftSessionBackend.js.map +1 -0
  110. package/dist/thrift-backend/wireSynthesis.d.ts +30 -0
  111. package/dist/thrift-backend/wireSynthesis.js +128 -0
  112. package/dist/thrift-backend/wireSynthesis.js.map +1 -0
  113. package/dist/version.d.ts +1 -1
  114. package/dist/version.js +1 -1
  115. package/dist/version.js.map +1 -1
  116. package/native/kernel/README.md +97 -0
  117. package/native/kernel/index.d.ts +1069 -0
  118. package/native/kernel/index.js +325 -0
  119. package/package.json +13 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KernelArrowIpc.js","sourceRoot":"","sources":["../../lib/kernel/KernelArrowIpc.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;;;;AAEjC,+CAAiH;AACjH,sEAA4F;AAC5F,2EAAiG;AACjG,gFAAwD;AAExD;;;GAGG;AACH,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,cAAc,CAAC,QAAgB;IAC7C,MAAM,MAAM,GAAG,IAAI,4BAAa,CAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,KAAK,MAAM,OAAO,IAAI,MAAM,EAAE;QAC5B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SAAS,CAAC;IAEzD,OAAO,2BAAO,CAAC,WAAW,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,yBAAyB,CAAC,WAA4B;IACpE,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACtD,MAAM,cAAc,GAAwB;YAC1C,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC;SAChC,CAAC;QACF,OAAO;YACL,UAAU,EAAE,KAAK,CAAC,IAAI;YACtB,QAAQ,EAAE;gBACR,KAAK,EAAE;oBACL;wBACE,cAAc;qBACf;iBACF;aACF;YACD,QAAQ,EAAE,KAAK,GAAG,CAAC;SACpB,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC;AAlBD,8DAkBC"}
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Metadata key written onto rewritten fields to preserve the original
4
+ * `Duration` time unit. Consumed by
5
+ * `lib/result/ArrowResultConverter.ts` Phase 1 to choose the correct
6
+ * scale when formatting INTERVAL DAY-TIME values.
7
+ */
8
+ export declare const DURATION_UNIT_METADATA_KEY = "databricks.arrow.duration_unit";
9
+ /**
10
+ * Walk an IPC stream payload and rewrite any `Duration` field in the
11
+ * schema message to `Int64` (preserving the original time unit in
12
+ * custom metadata). Subsequent record-batch messages are forwarded
13
+ * verbatim — the data layout matches the rewritten `Int64` type
14
+ * bit-for-bit.
15
+ *
16
+ * If the schema contains no `Duration` fields, the input buffer is
17
+ * returned unchanged (zero-copy fast path).
18
+ *
19
+ * The caller is expected to pass a complete IPC stream payload (the
20
+ * full byte buffer the kernel returned for one `fetchNextBatch` call,
21
+ * or the schema-only payload from `statement.schema()`). Multi-segment
22
+ * stream payloads are supported; we walk through each message until
23
+ * the buffer is exhausted.
24
+ *
25
+ * @param ipcBytes raw IPC stream bytes from the napi binding
26
+ * @returns either the original buffer (no rewrite needed) or a fresh
27
+ * buffer with the schema message replaced
28
+ */
29
+ export declare function rewriteDurationToInt64(ipcBytes: Buffer | Uint8Array): Buffer;
@@ -0,0 +1,605 @@
1
+ "use strict";
2
+ // Copyright (c) 2026 Databricks, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
22
+ }) : (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ o[k2] = m[k];
25
+ }));
26
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
27
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
28
+ }) : function(o, v) {
29
+ o["default"] = v;
30
+ });
31
+ var __importStar = (this && this.__importStar) || function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.rewriteDurationToInt64 = exports.DURATION_UNIT_METADATA_KEY = void 0;
40
+ /**
41
+ * Pre-process an Arrow IPC stream payload to make it consumable by
42
+ * `apache-arrow@13`, which predates the addition of the `Duration` type
43
+ * (FlatBuffer `Type` enum id 18) in version 14.
44
+ *
45
+ * The Databricks SQL server emits INTERVAL DAY-TIME columns as Arrow
46
+ * `Duration(MICROSECOND)` in the kernel IPC stream. apache-arrow@13's
47
+ * `decodeFieldType` (`node_modules/apache-arrow/ipc/metadata/message.js:339-397`)
48
+ * throws `Unrecognized type: "Duration" (18)` on the schema FlatBuffer
49
+ * before any record batch is read, breaking the entire kernel path for any
50
+ * result that contains an INTERVAL DAY-TIME column.
51
+ *
52
+ * Because the physical layout of an Arrow `Duration` column is
53
+ * **identical** to an Arrow `Int64` column (8 bytes of signed integer per
54
+ * row in the values buffer, plus the validity bitmap), we can losslessly
55
+ * rewrite the schema FlatBuffer to advertise `Int(bitWidth=64,
56
+ * signed=true)` in place of `Duration(unit)`. The record-batch body
57
+ * bytes pass through unchanged. We embed the original `Duration` time
58
+ * unit (`SECOND`/`MILLISECOND`/`MICROSECOND`/`NANOSECOND`) into the
59
+ * rewritten field's `custom_metadata` under the key
60
+ * `databricks.arrow.duration_unit`.
61
+ *
62
+ * **Scope on this layer (kernel execution + results, PR 2/3):** the rewrite's
63
+ * job here is purely to make the stream *decodable* by apache-arrow@13. The
64
+ * resulting Int64 surfaces to callers as a raw microsecond/nanosecond number
65
+ * on this layer. The consumer that reads the `duration_unit` marker and
66
+ * formats it back into the thrift-equivalent string (e.g.
67
+ * `"1 02:03:04.000000000"`) lands in PR 3/3 (#411) — verified against a live
68
+ * warehouse to produce byte-identical output to the Thrift path. Until that
69
+ * consumer merges, INTERVAL DAY-TIME columns are raw Int64 under kernel.
70
+ *
71
+ * Why this lives in its own file: the rewriter is the only place in the
72
+ * codebase that needs to construct FlatBuffers by hand using the
73
+ * `flatbuffers` library; isolating it keeps `KernelArrowIpc.ts` focused on
74
+ * the high-level Arrow-decoded views.
75
+ *
76
+ * @see lib/result/ArrowResultConverter.ts — the Phase-1 INTERVAL formatter
77
+ * (PR 3/3) reads the metadata key written here.
78
+ * @see findings/parity-mismatch/round5-implementation-2026-05-15.md —
79
+ * original failure mode (`Unrecognized type: "Duration" (18)`).
80
+ */
81
+ const flatbuffers = __importStar(require("flatbuffers"));
82
+ // We reach into apache-arrow's internal FlatBuffer accessor modules
83
+ // rather than the high-level Schema/Field classes because the latter
84
+ // throw on the `Duration` type id 18 (`apache-arrow@13` predates the
85
+ // `Duration` enum entry). The internal `fb/*` modules are generated
86
+ // FlatBuffer code and recognize every type id present in the
87
+ // FlatBuffer schema, including `Duration`, so we can decode the
88
+ // original schema and rebuild it with `Duration` rewritten to `Int64`.
89
+ // eslint-disable-next-line import/no-internal-modules
90
+ const message_1 = require("apache-arrow/fb/message");
91
+ // eslint-disable-next-line import/no-internal-modules
92
+ const message_header_1 = require("apache-arrow/fb/message-header");
93
+ // eslint-disable-next-line import/no-internal-modules
94
+ const schema_1 = require("apache-arrow/fb/schema");
95
+ // eslint-disable-next-line import/no-internal-modules
96
+ const field_1 = require("apache-arrow/fb/field");
97
+ // eslint-disable-next-line import/no-internal-modules
98
+ const key_value_1 = require("apache-arrow/fb/key-value");
99
+ // eslint-disable-next-line import/no-internal-modules
100
+ const type_1 = require("apache-arrow/fb/type");
101
+ // eslint-disable-next-line import/no-internal-modules
102
+ const duration_1 = require("apache-arrow/fb/duration");
103
+ // eslint-disable-next-line import/no-internal-modules
104
+ const int_1 = require("apache-arrow/fb/int");
105
+ // eslint-disable-next-line import/no-internal-modules
106
+ const time_unit_1 = require("apache-arrow/fb/time-unit");
107
+ /**
108
+ * Metadata key written onto rewritten fields to preserve the original
109
+ * `Duration` time unit. Consumed by
110
+ * `lib/result/ArrowResultConverter.ts` Phase 1 to choose the correct
111
+ * scale when formatting INTERVAL DAY-TIME values.
112
+ */
113
+ exports.DURATION_UNIT_METADATA_KEY = 'databricks.arrow.duration_unit';
114
+ const IPC_CONTINUATION_MARKER = 0xffffffff;
115
+ const TIME_UNIT_NAME = {
116
+ [time_unit_1.TimeUnit.SECOND]: 'SECOND',
117
+ [time_unit_1.TimeUnit.MILLISECOND]: 'MILLISECOND',
118
+ [time_unit_1.TimeUnit.MICROSECOND]: 'MICROSECOND',
119
+ [time_unit_1.TimeUnit.NANOSECOND]: 'NANOSECOND',
120
+ };
121
+ /**
122
+ * Walk an IPC stream payload and rewrite any `Duration` field in the
123
+ * schema message to `Int64` (preserving the original time unit in
124
+ * custom metadata). Subsequent record-batch messages are forwarded
125
+ * verbatim — the data layout matches the rewritten `Int64` type
126
+ * bit-for-bit.
127
+ *
128
+ * If the schema contains no `Duration` fields, the input buffer is
129
+ * returned unchanged (zero-copy fast path).
130
+ *
131
+ * The caller is expected to pass a complete IPC stream payload (the
132
+ * full byte buffer the kernel returned for one `fetchNextBatch` call,
133
+ * or the schema-only payload from `statement.schema()`). Multi-segment
134
+ * stream payloads are supported; we walk through each message until
135
+ * the buffer is exhausted.
136
+ *
137
+ * @param ipcBytes raw IPC stream bytes from the napi binding
138
+ * @returns either the original buffer (no rewrite needed) or a fresh
139
+ * buffer with the schema message replaced
140
+ */
141
+ function rewriteDurationToInt64(ipcBytes) {
142
+ const view = ipcBytes instanceof Buffer ? ipcBytes : Buffer.from(ipcBytes);
143
+ // First message must be the schema. If we can't find a schema message
144
+ // we leave the bytes alone — better to surface apache-arrow's normal
145
+ // error path than to mask a malformed stream.
146
+ const first = readMessageAt(view, 0);
147
+ if (!first) {
148
+ return view;
149
+ }
150
+ if (first.message.headerType() !== message_header_1.MessageHeader.Schema) {
151
+ return view;
152
+ }
153
+ const rewrittenSchema = maybeRewriteSchemaMessage(first.messageBytes);
154
+ if (!rewrittenSchema) {
155
+ // No Duration fields; nothing to do.
156
+ return view;
157
+ }
158
+ // Splice the rewritten schema back into the stream: continuation
159
+ // marker + new metadata length + new metadata bytes + everything after
160
+ // the original schema message (body of schema is empty per Arrow spec;
161
+ // record batches follow).
162
+ const outputs = [];
163
+ outputs.push(encodeContinuationAndLength(rewrittenSchema.byteLength));
164
+ outputs.push(rewrittenSchema);
165
+ // Schema messages have no body (bodyLength=0 always — Arrow spec).
166
+ // Forward everything after the schema's metadata bytes unchanged.
167
+ const tailStart = first.totalEnd;
168
+ if (tailStart < view.byteLength) {
169
+ outputs.push(view.subarray(tailStart));
170
+ }
171
+ return Buffer.concat(outputs);
172
+ }
173
+ exports.rewriteDurationToInt64 = rewriteDurationToInt64;
174
+ /**
175
+ * Read one IPC message at the given offset. Returns the parsed Message
176
+ * object and byte ranges, or `null` if the buffer is exhausted.
177
+ *
178
+ * IPC stream message format (post-0.15):
179
+ * [continuation: 0xFFFFFFFF (4 bytes LE)] [length: int32 LE]
180
+ * [metadata: flatbuffer Message of `length` bytes] [body: bodyLength bytes]
181
+ *
182
+ * Pre-0.15 streams omit the continuation marker — the first 4 bytes are
183
+ * the metadata length directly. apache-arrow handles both
184
+ * (`message.js:44-50`); we mirror that here.
185
+ */
186
+ function readMessageAt(view, start) {
187
+ if (start + 4 > view.byteLength) {
188
+ return null;
189
+ }
190
+ let cursor = start;
191
+ let metadataLength = view.readInt32LE(cursor);
192
+ cursor += 4;
193
+ // Continuation marker (0xFFFFFFFF reads as -1 as int32) — followed by
194
+ // the actual length.
195
+ if (metadataLength === -1) {
196
+ if (cursor + 4 > view.byteLength) {
197
+ return null;
198
+ }
199
+ metadataLength = view.readInt32LE(cursor);
200
+ cursor += 4;
201
+ }
202
+ // A zero or negative length (other than the -1 continuation sentinel
203
+ // handled above) is malformed. Reject by intent rather than relying on
204
+ // `subarray` clamping: a negative `metadataLength` would make
205
+ // `metadataEnd < cursor`, which silently passes the `> byteLength`
206
+ // upper-bound check below.
207
+ if (metadataLength <= 0) {
208
+ return null;
209
+ }
210
+ const metadataStart = cursor;
211
+ const metadataEnd = cursor + metadataLength;
212
+ if (metadataEnd > view.byteLength) {
213
+ return null;
214
+ }
215
+ const metadataBytes = view.subarray(metadataStart, metadataEnd);
216
+ const bb = new flatbuffers.ByteBuffer(metadataBytes);
217
+ const message = message_1.Message.getRootAsMessage(bb);
218
+ const bodyLength = Number(message.bodyLength());
219
+ // Same fail-closed intent as metadataLength: a negative body length
220
+ // (server-controlled) would make `bodyEnd < bodyStart` and slip past
221
+ // the upper-bound check.
222
+ if (bodyLength < 0) {
223
+ return null;
224
+ }
225
+ const bodyStart = metadataEnd;
226
+ const bodyEnd = bodyStart + bodyLength;
227
+ if (bodyEnd > view.byteLength) {
228
+ // Malformed; let apache-arrow surface the error downstream.
229
+ return null;
230
+ }
231
+ return {
232
+ message,
233
+ messageBytes: metadataBytes,
234
+ metadataStart,
235
+ metadataEnd,
236
+ bodyEnd,
237
+ totalEnd: bodyEnd,
238
+ };
239
+ }
240
+ /**
241
+ * If the schema message contains any `Duration` fields, returns a fresh
242
+ * FlatBuffer-encoded Message containing the rewritten schema. Otherwise
243
+ * returns `null` so the caller can short-circuit.
244
+ */
245
+ function maybeRewriteSchemaMessage(schemaMessageBytes) {
246
+ const bb = new flatbuffers.ByteBuffer(schemaMessageBytes);
247
+ const message = message_1.Message.getRootAsMessage(bb);
248
+ const fbSchema = message.header(new schema_1.Schema());
249
+ if (!fbSchema) {
250
+ return null;
251
+ }
252
+ // We rewrite only TOP-LEVEL Duration fields for M0 (Spark INTERVAL
253
+ // DAY-TIME surfaces as a top-level column). A Duration nested inside
254
+ // STRUCT/ARRAY/MAP is left untouched and apache-arrow@13 then throws
255
+ // `Unrecognized type: "Duration" (18)` when decoding the batch.
256
+ //
257
+ // This is a SHARED apache-arrow@13 limitation, NOT a kernel-specific gap:
258
+ // verified against a live warehouse, the Thrift backend throws the
259
+ // identical error for `array(INTERVAL '1' SECOND)` — so kernel matches Thrift
260
+ // here rather than diverging. Lifting it (recurse the rewrite into
261
+ // children) is deferred until there's a real-world nested-Duration payload
262
+ // to validate against, and would ideally land on both backends together.
263
+ let hasDuration = false;
264
+ const fieldsLength = fbSchema.fieldsLength();
265
+ for (let i = 0; i < fieldsLength; i += 1) {
266
+ const f = fbSchema.fields(i);
267
+ if (f && f.typeType() === type_1.Type.Duration) {
268
+ hasDuration = true;
269
+ break;
270
+ }
271
+ }
272
+ if (!hasDuration) {
273
+ return null;
274
+ }
275
+ // Re-encode the whole schema. This is more verbose than an in-place
276
+ // FlatBuffer patch, but it avoids relying on vtable layout details.
277
+ return rebuildSchemaWithDurationRewritten(message, fbSchema);
278
+ }
279
+ /**
280
+ * Full re-encode path: parse every field in the schema, substitute
281
+ * `Duration` with `Int64` (carrying the unit in custom metadata), and
282
+ * emit a fresh Message FlatBuffer. This handles arbitrary schemas
283
+ * correctly at the cost of decode+re-encode of all fields.
284
+ *
285
+ * For non-Duration fields we copy the *bytes* of the original
286
+ * `type` sub-table verbatim into the new builder — FlatBuffer
287
+ * sub-tables are self-contained address spaces, so this is safe.
288
+ */
289
+ function rebuildSchemaWithDurationRewritten(message, fbSchema) {
290
+ var _a, _b;
291
+ const builder = new flatbuffers.Builder(1024);
292
+ // Re-encode each field.
293
+ const fieldOffsets = [];
294
+ const fieldsLength = fbSchema.fieldsLength();
295
+ for (let i = 0; i < fieldsLength; i += 1) {
296
+ const field = fbSchema.fields(i);
297
+ if (!field) {
298
+ continue;
299
+ }
300
+ fieldOffsets.push(reEncodeField(builder, field));
301
+ }
302
+ // Re-encode top-level schema custom_metadata verbatim.
303
+ const schemaMetadataOffsets = [];
304
+ const schemaMetadataLength = fbSchema.customMetadataLength();
305
+ for (let i = 0; i < schemaMetadataLength; i += 1) {
306
+ const kv = fbSchema.customMetadata(i);
307
+ if (!kv) {
308
+ continue;
309
+ }
310
+ const keyStr = (_a = kv.key()) !== null && _a !== void 0 ? _a : '';
311
+ const valStr = (_b = kv.value()) !== null && _b !== void 0 ? _b : '';
312
+ const keyOff = builder.createString(keyStr);
313
+ const valOff = builder.createString(valStr);
314
+ key_value_1.KeyValue.startKeyValue(builder);
315
+ key_value_1.KeyValue.addKey(builder, keyOff);
316
+ key_value_1.KeyValue.addValue(builder, valOff);
317
+ schemaMetadataOffsets.push(key_value_1.KeyValue.endKeyValue(builder));
318
+ }
319
+ // Build the fields and metadata vectors, then the Schema, then the Message.
320
+ const fieldsVec = schema_1.Schema.createFieldsVector(builder, fieldOffsets);
321
+ const metadataVec = schemaMetadataOffsets.length > 0 ? schema_1.Schema.createCustomMetadataVector(builder, schemaMetadataOffsets) : 0;
322
+ // Preserve features vector — `features()` requires walking the
323
+ // bigint vector; for the kernel's payloads this is typically empty
324
+ // so we skip it. If a non-empty features vector appears, we drop it
325
+ // (Arrow features encode optional compression flags; the kernel
326
+ // emits uncompressed streams for the kernel path per
327
+ // `findings/rust-kernel/M0-kernel-async-readiness-2026-05-15.md`).
328
+ schema_1.Schema.startSchema(builder);
329
+ schema_1.Schema.addEndianness(builder, fbSchema.endianness());
330
+ schema_1.Schema.addFields(builder, fieldsVec);
331
+ if (metadataVec !== 0) {
332
+ schema_1.Schema.addCustomMetadata(builder, metadataVec);
333
+ }
334
+ const schemaOffset = schema_1.Schema.endSchema(builder);
335
+ // Wrap in a Message. version + headerType + header + bodyLength + custom_metadata.
336
+ message_1.Message.startMessage(builder);
337
+ message_1.Message.addVersion(builder, message.version());
338
+ message_1.Message.addHeaderType(builder, message_header_1.MessageHeader.Schema);
339
+ message_1.Message.addHeader(builder, schemaOffset);
340
+ message_1.Message.addBodyLength(builder, BigInt(0));
341
+ const newMessage = message_1.Message.endMessage(builder);
342
+ builder.finish(newMessage);
343
+ const bytes = builder.asUint8Array();
344
+ // The Arrow IPC spec requires each message to be 8-byte aligned so
345
+ // that subsequent record batches' body buffers stay aligned for SIMD
346
+ // reads. apache-arrow's MessageReader doesn't enforce this on read
347
+ // (it just trusts the metadata length), so any padding is fine.
348
+ // Round up the metadata bytes to a multiple of 8 by appending zero
349
+ // padding — this keeps the IPC stream spec-compliant.
350
+ const padded = padToAlignment(bytes, 8);
351
+ return Buffer.from(padded);
352
+ }
353
+ /**
354
+ * Re-encode a single Field. For `Duration` fields, substitute `Int64`
355
+ * and add `databricks.arrow.duration_unit` metadata. For all other
356
+ * types we re-encode via the appropriate type-sub-table-aware path —
357
+ * but to keep this rewriter compact we just walk the FlatBuffer-level
358
+ * accessors needed for the M0 primitive types and complex types Arrow
359
+ * surfaces from the kernel. Unknown types fall back to copying the
360
+ * raw type sub-table bytes via FlatBuffer's serialization (which
361
+ * always works because sub-tables are self-contained).
362
+ */
363
+ function reEncodeField(builder, field) {
364
+ var _a, _b, _c, _d;
365
+ const nameStr = (_a = field.name()) !== null && _a !== void 0 ? _a : '';
366
+ const nameOffset = builder.createString(nameStr);
367
+ // Re-encode children recursively (Struct/List/Map all carry children).
368
+ const childOffsets = [];
369
+ const childrenLength = field.childrenLength();
370
+ for (let i = 0; i < childrenLength; i += 1) {
371
+ const child = field.children(i);
372
+ if (child) {
373
+ childOffsets.push(reEncodeField(builder, child));
374
+ }
375
+ }
376
+ const childrenVec = childOffsets.length > 0 ? field_1.Field.createChildrenVector(builder, childOffsets) : 0;
377
+ // Re-encode custom_metadata (preserving everything). For Duration
378
+ // fields we'll add our marker on top.
379
+ const metadataOffsets = [];
380
+ const metadataLength = field.customMetadataLength();
381
+ for (let i = 0; i < metadataLength; i += 1) {
382
+ const kv = field.customMetadata(i);
383
+ if (!kv) {
384
+ continue;
385
+ }
386
+ const keyStr = (_b = kv.key()) !== null && _b !== void 0 ? _b : '';
387
+ const valStr = (_c = kv.value()) !== null && _c !== void 0 ? _c : '';
388
+ const keyOff = builder.createString(keyStr);
389
+ const valOff = builder.createString(valStr);
390
+ key_value_1.KeyValue.startKeyValue(builder);
391
+ key_value_1.KeyValue.addKey(builder, keyOff);
392
+ key_value_1.KeyValue.addValue(builder, valOff);
393
+ metadataOffsets.push(key_value_1.KeyValue.endKeyValue(builder));
394
+ }
395
+ const originalTypeType = field.typeType();
396
+ let typeType = originalTypeType;
397
+ let typeOffset = 0;
398
+ if (originalTypeType === type_1.Type.Duration) {
399
+ // Read the original Duration unit. Substitute Int(64, signed) and
400
+ // append a custom_metadata entry recording the original unit.
401
+ const durationTable = field.type(new duration_1.Duration());
402
+ const unit = durationTable ? durationTable.unit() : time_unit_1.TimeUnit.MICROSECOND;
403
+ const unitName = (_d = TIME_UNIT_NAME[unit]) !== null && _d !== void 0 ? _d : 'MICROSECOND';
404
+ const keyOff = builder.createString(exports.DURATION_UNIT_METADATA_KEY);
405
+ const valOff = builder.createString(unitName);
406
+ key_value_1.KeyValue.startKeyValue(builder);
407
+ key_value_1.KeyValue.addKey(builder, keyOff);
408
+ key_value_1.KeyValue.addValue(builder, valOff);
409
+ metadataOffsets.push(key_value_1.KeyValue.endKeyValue(builder));
410
+ typeType = type_1.Type.Int;
411
+ typeOffset = int_1.Int.createInt(builder, 64, true);
412
+ }
413
+ else {
414
+ // Copy the original type sub-table by re-encoding it from the
415
+ // FlatBuffer-level accessor. Sub-tables are self-contained, but
416
+ // the builder API requires us to write each known type with its
417
+ // generated `createXxx`. For M0, the kernel emits a fixed set of
418
+ // top-level types (matching the SQL datatype table in
419
+ // `findings/rust-kernel/datatype-emission-and-block-on-2026-05-15.md`).
420
+ // We re-encode each known type sub-table; unsupported types fall
421
+ // through to a generic offset-only copy (zero-byte type sub-table),
422
+ // which apache-arrow's `decodeFieldType` accepts for the
423
+ // children-only types (List, Struct, Null).
424
+ typeOffset = reEncodeTypeSubtable(builder, field, originalTypeType);
425
+ }
426
+ const metadataVec = metadataOffsets.length > 0 ? field_1.Field.createCustomMetadataVector(builder, metadataOffsets) : 0;
427
+ field_1.Field.startField(builder);
428
+ field_1.Field.addName(builder, nameOffset);
429
+ field_1.Field.addNullable(builder, field.nullable());
430
+ field_1.Field.addTypeType(builder, typeType);
431
+ if (typeOffset !== 0) {
432
+ field_1.Field.addType(builder, typeOffset);
433
+ }
434
+ if (childrenVec !== 0) {
435
+ field_1.Field.addChildren(builder, childrenVec);
436
+ }
437
+ if (metadataVec !== 0) {
438
+ field_1.Field.addCustomMetadata(builder, metadataVec);
439
+ }
440
+ // Note: dictionary encoding is not re-emitted. The kernel doesn't
441
+ // emit dictionary-encoded columns for M0; if it ever does, this
442
+ // rewriter would need to copy the DictionaryEncoding sub-table too.
443
+ return field_1.Field.endField(builder);
444
+ }
445
+ /**
446
+ * Re-encode a Field's type sub-table by reading it from the original
447
+ * FlatBuffer (via the apache-arrow generated accessors) and writing it
448
+ * into the new builder. Supports the full M0 type matrix:
449
+ * primitives: Null, Int (all widths), FloatingPoint (Float16/32/64),
450
+ * Bool, Utf8, Binary, Decimal, Date, Time, Timestamp, Interval
451
+ * complex: List (header only), Struct (header only), Map, FixedSizeList,
452
+ * FixedSizeBinary, Union
453
+ * Children-only types (Struct, List, Null) emit an empty sub-table.
454
+ */
455
+ function reEncodeTypeSubtable(builder, field, typeType) {
456
+ // Lazy imports to avoid cyclic resolution and to keep this file's
457
+ // top-of-module imports tight. These are zero-cost — Node caches
458
+ // them after the first require.
459
+ /* eslint-disable @typescript-eslint/no-var-requires, global-require, import/no-internal-modules */
460
+ const { Null } = require('apache-arrow/fb/null');
461
+ const { FloatingPoint } = require('apache-arrow/fb/floating-point');
462
+ const { Binary } = require('apache-arrow/fb/binary');
463
+ const { Utf8 } = require('apache-arrow/fb/utf8');
464
+ const { Bool } = require('apache-arrow/fb/bool');
465
+ const { Decimal } = require('apache-arrow/fb/decimal');
466
+ const { Date: DateTbl } = require('apache-arrow/fb/date');
467
+ const { Time } = require('apache-arrow/fb/time');
468
+ const { Timestamp } = require('apache-arrow/fb/timestamp');
469
+ const { Interval } = require('apache-arrow/fb/interval');
470
+ const { List } = require('apache-arrow/fb/list');
471
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- `Struct_` is apache-arrow's generated FlatBuffers export name.
472
+ const { Struct_ } = require('apache-arrow/fb/struct-');
473
+ const { Union } = require('apache-arrow/fb/union');
474
+ const { FixedSizeBinary } = require('apache-arrow/fb/fixed-size-binary');
475
+ const { FixedSizeList } = require('apache-arrow/fb/fixed-size-list');
476
+ const { Map: MapTbl } = require('apache-arrow/fb/map');
477
+ /* eslint-enable @typescript-eslint/no-var-requires, global-require, import/no-internal-modules */
478
+ switch (typeType) {
479
+ case type_1.Type.NONE:
480
+ case type_1.Type.Null: {
481
+ // Null has no fields; emit an empty table.
482
+ const t = new Null();
483
+ field.type(t);
484
+ Null.startNull(builder);
485
+ return Null.endNull(builder);
486
+ }
487
+ case type_1.Type.Int: {
488
+ const t = field.type(new int_1.Int());
489
+ if (!t) {
490
+ return int_1.Int.createInt(builder, 32, true);
491
+ }
492
+ return int_1.Int.createInt(builder, t.bitWidth(), t.isSigned());
493
+ }
494
+ case type_1.Type.FloatingPoint: {
495
+ const t = field.type(new FloatingPoint());
496
+ return FloatingPoint.createFloatingPoint(builder, t.precision());
497
+ }
498
+ case type_1.Type.Binary: {
499
+ Binary.startBinary(builder);
500
+ return Binary.endBinary(builder);
501
+ }
502
+ case type_1.Type.Utf8: {
503
+ Utf8.startUtf8(builder);
504
+ return Utf8.endUtf8(builder);
505
+ }
506
+ case type_1.Type.Bool: {
507
+ Bool.startBool(builder);
508
+ return Bool.endBool(builder);
509
+ }
510
+ case type_1.Type.Decimal: {
511
+ const t = field.type(new Decimal());
512
+ return Decimal.createDecimal(builder, t.precision(), t.scale(), t.bitWidth());
513
+ }
514
+ case type_1.Type.Date: {
515
+ const t = field.type(new DateTbl());
516
+ return DateTbl.createDate(builder, t.unit());
517
+ }
518
+ case type_1.Type.Time: {
519
+ const t = field.type(new Time());
520
+ return Time.createTime(builder, t.unit(), t.bitWidth());
521
+ }
522
+ case type_1.Type.Timestamp: {
523
+ const t = field.type(new Timestamp());
524
+ const tz = t.timezone();
525
+ const tzOffset = tz ? builder.createString(tz) : 0;
526
+ Timestamp.startTimestamp(builder);
527
+ Timestamp.addUnit(builder, t.unit());
528
+ if (tzOffset !== 0) {
529
+ Timestamp.addTimezone(builder, tzOffset);
530
+ }
531
+ return Timestamp.endTimestamp(builder);
532
+ }
533
+ case type_1.Type.Interval: {
534
+ const t = field.type(new Interval());
535
+ return Interval.createInterval(builder, t.unit());
536
+ }
537
+ case type_1.Type.List: {
538
+ List.startList(builder);
539
+ return List.endList(builder);
540
+ }
541
+ case type_1.Type.Struct_: {
542
+ Struct_.startStruct_(builder);
543
+ return Struct_.endStruct_(builder);
544
+ }
545
+ case type_1.Type.Union: {
546
+ const t = field.type(new Union());
547
+ // typeIds is an int32 vector — copy it.
548
+ const typeIdsArr = t.typeIdsArray();
549
+ let typeIdsOffset = 0;
550
+ if (typeIdsArr) {
551
+ typeIdsOffset = Union.createTypeIdsVector(builder, Array.from(typeIdsArr));
552
+ }
553
+ Union.startUnion(builder);
554
+ Union.addMode(builder, t.mode());
555
+ if (typeIdsOffset !== 0) {
556
+ Union.addTypeIds(builder, typeIdsOffset);
557
+ }
558
+ return Union.endUnion(builder);
559
+ }
560
+ case type_1.Type.FixedSizeBinary: {
561
+ const t = field.type(new FixedSizeBinary());
562
+ return FixedSizeBinary.createFixedSizeBinary(builder, t.byteWidth());
563
+ }
564
+ case type_1.Type.FixedSizeList: {
565
+ const t = field.type(new FixedSizeList());
566
+ return FixedSizeList.createFixedSizeList(builder, t.listSize());
567
+ }
568
+ case type_1.Type.Map: {
569
+ const t = field.type(new MapTbl());
570
+ return MapTbl.createMap(builder, t.keysSorted());
571
+ }
572
+ default:
573
+ // Unknown / newer types (LargeBinary, LargeUtf8, LargeList,
574
+ // RunEndEncoded, ...). The kernel doesn't emit these for M0;
575
+ // emit an empty sub-table and let apache-arrow's normal error
576
+ // path fire when it tries to decode an unrecognized type id.
577
+ return 0;
578
+ }
579
+ }
580
+ /**
581
+ * Prefix the given FlatBuffer message bytes with the IPC stream
582
+ * framing: the continuation marker (0xFFFFFFFF) followed by the
583
+ * little-endian int32 metadata length.
584
+ */
585
+ function encodeContinuationAndLength(metadataLength) {
586
+ const out = Buffer.alloc(8);
587
+ out.writeInt32LE(IPC_CONTINUATION_MARKER | 0, 0); // -1
588
+ out.writeInt32LE(metadataLength, 4);
589
+ return out;
590
+ }
591
+ /**
592
+ * Pad `bytes` with trailing zeros so its length is a multiple of
593
+ * `alignment`. Returns the original buffer when it is already
594
+ * aligned.
595
+ */
596
+ function padToAlignment(bytes, alignment) {
597
+ const remainder = bytes.byteLength % alignment;
598
+ if (remainder === 0) {
599
+ return bytes;
600
+ }
601
+ const padded = new Uint8Array(bytes.byteLength + (alignment - remainder));
602
+ padded.set(bytes, 0);
603
+ return padded;
604
+ }
605
+ //# sourceMappingURL=KernelArrowIpcDurationFix.js.map