Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Any failed Thrift `FetchResults` call or CloudFetch download makes the operation terminal: later reads rethrow the original fetch error, and callers must re-execute the statement (`FetchResults` is not retried). Cleanup runs in the background under the existing close retry budget, logs failures safely, and shares its request with `close()`; argument handling and kernel behavior are unchanged.

- The Thrift token federation exchange (`enableTokenFederation`) now goes through the connection's agent, so `proxy`, `checkServerCertificate`, `customCaCert` and `clientCert`/`clientKey` apply to it. Previously it connected directly with Node's default agent, so behind a required proxy the exchange failed and the driver fell back to the original token. (#611)
- Kernel backend: a failed status poll while waiting for a statement (a `runAsync: true` statement, or a default execution that outlives the server's inline wait) and a failed result fetch in `hasMoreRows()` now throw the mapped driver error, such as `HiveDriverError: HTTP 500: Internal Server Error` once retries on HTTP 5xx run out, instead of a raw `Error` whose message is the internal `__databricks_error__:{...}` envelope. As in `fetchChunk()`, a failed fetch in `hasMoreRows()` also closes the statement. (#608)
- Honor `cloudFetchConcurrentDownloads` when opening kernel sessions, with a default window of 16 and explicit chunk-setting overrides. Values other than positive safe integers raise `HiveDriverError` at session open.
Expand Down
17 changes: 16 additions & 1 deletion lib/result/RowSetProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export enum FetchType {
Logs = 1,
}

const fetchArgumentErrors = new WeakSet<Error>();

export function isFetchArgumentError(error: unknown): boolean {
return error instanceof Error && fetchArgumentErrors.has(error);
}

/**
* Rough byte count for a single `TColumn`. Used only for telemetry — exact
* wire size isn't worth a deserialization pass. Fixed-width values are
Expand Down Expand Up @@ -150,10 +156,19 @@ export default class RowSetProvider implements IResultsProvider<TRowSet | undefi

const driver = await this.context.getDriver();
const startTime = Date.now();
let maxRows: Int64;
try {
maxRows = new Int64(limit);
} catch (error) {
if (error instanceof Error) {
fetchArgumentErrors.add(error);
}
throw error;
}
const response = await driver.fetchResults({
operationHandle: this.operationHandle,
orientation: this.fetchOrientation,
maxRows: new Int64(limit),
maxRows,
fetchType: FetchType.Data,
});
const latencyMs = Date.now() - startTime;
Expand Down
63 changes: 56 additions & 7 deletions lib/thrift-backend/ThriftOperationBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Status from '../dto/Status';
import { LogLevel } from '../contracts/IDBSQLLogger';
import OperationStateError, { OperationStateErrorCode } from '../errors/OperationStateError';
import IResultsProvider from '../result/IResultsProvider';
import RowSetProvider from '../result/RowSetProvider';
import RowSetProvider, { isFetchArgumentError } from '../result/RowSetProvider';
import JsonResultHandler from '../result/JsonResultHandler';
import ArrowResultHandler from '../result/ArrowResultHandler';
import CloudFetchResultHandler from '../result/CloudFetchResultHandler';
Expand Down Expand Up @@ -105,6 +105,12 @@ export default class ThriftOperationBackend implements IOperationBackend {

private resultHandler?: ResultSlicer<any>;

private fetchFailed = false;

private fetchError?: unknown;

private closePromise?: Promise<Status>;

constructor({
handle,
directResults,
Expand Down Expand Up @@ -168,6 +174,7 @@ export default class ThriftOperationBackend implements IOperationBackend {
disableBuffering?: boolean;
isClosed?: () => boolean;
}): Promise<Array<object>> {
this.failIfFetchFailed();
const resultHandler = await this.getResultHandler();

// All the library code is Promise-based, however, since Promises are microtasks,
Expand All @@ -194,20 +201,50 @@ export default class ThriftOperationBackend implements IOperationBackend {
return [];
}

const rows = await resultHandler.fetchNext({ limit, disableBuffering });
if (this.functionCatalog === undefined) {
return rows;
}
try {
const rows = await resultHandler.fetchNext({ limit, disableBuffering });
if (this.functionCatalog === undefined) {
return rows;
}

// Native GetFunctions leaves FUNCTION_CAT empty; match JDBC and kernel.
return rows.map((row) => (row === null ? row : { ...row, FUNCTION_CAT: this.functionCatalog }));
// Native GetFunctions leaves FUNCTION_CAT empty; match JDBC and kernel.
return rows.map((row) => (row === null ? row : { ...row, FUNCTION_CAT: this.functionCatalog }));
} catch (error) {
if (isFetchArgumentError(error)) {
throw error;
}
if (!this.fetchFailed) {
this.fetchError = error;
this.fetchFailed = true;
this.close()
.catch((closeError) => {
const cause = typeof closeError?.message === 'string' ? closeError.message : String(closeError);
this.context
.getLogger()
.log(
LogLevel.warn,
`Thrift fetch-error cleanup: close() failed for operation ${this.id}; the server-side ` +
`statement may leak until the session is closed. Cause: ${cause}`,
);
})
.catch(() => undefined);
}
throw error;
}
}

public async hasMore(): Promise<boolean> {
this.failIfFetchFailed();
const resultHandler = await this.getResultHandler();
return resultHandler.hasMore();
}

private failIfFetchFailed(): void {
if (this.fetchFailed) {
throw this.fetchError;
}
}

public async status(progress: boolean): Promise<OperationStatus> {
const response = await this.thriftStatusResponse(progress);
return this.adaptOperationStatus(response);
Expand Down Expand Up @@ -355,6 +392,18 @@ export default class ThriftOperationBackend implements IOperationBackend {
}

public async close(): Promise<Status> {
if (!this.closePromise) {
this.closePromise = this.closeInternal().catch((error) => {
if (!this.fetchFailed && !this.isFinished()) {
this.closePromise = undefined;
}
throw error;
});
}
return this.closePromise;
}

private async closeInternal(): Promise<Status> {
this.context.getLogger().log(LogLevel.debug, `Closing operation with id: ${this.id}`);
const driver = await this.context.getDriver();
const response =
Expand Down
Loading
Loading