Skip to content

Commit 8d6d819

Browse files
samikshya-dbclaude
andcommitted
Refactor telemetry type mappers to separate file
- Create lib/telemetry/telemetryTypeMappers.ts - Move mapOperationTypeToTelemetryType (renamed from mapOperationTypeToProto) - Move mapResultFormatToTelemetryType (renamed from mapResultFormatToProto) - Keep all telemetry-specific mapping functions in one place Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 90fb7cd commit 8d6d819

2 files changed

Lines changed: 73 additions & 55 deletions

File tree

lib/DBSQLOperation.ts

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { OperationChunksIterator, OperationRowsIterator } from './utils/Operatio
3636
import HiveDriverError from './errors/HiveDriverError';
3737
import IClientContext from './contracts/IClientContext';
3838
import ExceptionClassifier from './telemetry/ExceptionClassifier';
39+
import { mapOperationTypeToTelemetryType, mapResultFormatToTelemetryType } from './telemetry/telemetryTypeMappers';
3940

4041
interface DBSQLOperationConstructorOptions {
4142
handle: TOperationHandle;
@@ -52,59 +53,6 @@ async function delay(ms?: number): Promise<void> {
5253
});
5354
}
5455

55-
/**
56-
* Map Thrift TOperationType to proto Operation.Type enum string.
57-
*/
58-
function mapOperationTypeToProto(operationType?: TOperationType): string | undefined {
59-
if (operationType === undefined) {
60-
return undefined;
61-
}
62-
63-
switch (operationType) {
64-
case TOperationType.EXECUTE_STATEMENT:
65-
return 'EXECUTE_STATEMENT';
66-
case TOperationType.GET_TYPE_INFO:
67-
return 'LIST_TYPE_INFO';
68-
case TOperationType.GET_CATALOGS:
69-
return 'LIST_CATALOGS';
70-
case TOperationType.GET_SCHEMAS:
71-
return 'LIST_SCHEMAS';
72-
case TOperationType.GET_TABLES:
73-
return 'LIST_TABLES';
74-
case TOperationType.GET_TABLE_TYPES:
75-
return 'LIST_TABLE_TYPES';
76-
case TOperationType.GET_COLUMNS:
77-
return 'LIST_COLUMNS';
78-
case TOperationType.GET_FUNCTIONS:
79-
return 'LIST_FUNCTIONS';
80-
case TOperationType.UNKNOWN:
81-
default:
82-
return 'TYPE_UNSPECIFIED';
83-
}
84-
}
85-
86-
/**
87-
* Map Thrift TSparkRowSetType to proto ExecutionResult.Format enum string.
88-
*/
89-
function mapResultFormatToProto(resultFormat?: TSparkRowSetType): string | undefined {
90-
if (resultFormat === undefined) {
91-
return undefined;
92-
}
93-
94-
switch (resultFormat) {
95-
case TSparkRowSetType.ARROW_BASED_SET:
96-
return 'INLINE_ARROW';
97-
case TSparkRowSetType.COLUMN_BASED_SET:
98-
return 'COLUMNAR_INLINE';
99-
case TSparkRowSetType.ROW_BASED_SET:
100-
return 'INLINE_JSON';
101-
case TSparkRowSetType.URL_BASED_SET:
102-
return 'EXTERNAL_LINKS';
103-
default:
104-
return 'FORMAT_UNSPECIFIED';
105-
}
106-
}
107-
10856
export default class DBSQLOperation implements IOperation {
10957
private readonly context: IClientContext;
11058

@@ -569,7 +517,7 @@ export default class DBSQLOperation implements IOperation {
569517
telemetryEmitter.emitStatementStart({
570518
statementId: this.id,
571519
sessionId: this.sessionId || '',
572-
operationType: mapOperationTypeToProto(this.operationHandle.operationType),
520+
operationType: mapOperationTypeToTelemetryType(this.operationHandle.operationType),
573521
});
574522
} catch (error: any) {
575523
this.context.getLogger().log(LogLevel.debug, `Error emitting statement.start event: ${error.message}`);
@@ -594,7 +542,7 @@ export default class DBSQLOperation implements IOperation {
594542
if (!this.metadata && !this.cancelled) {
595543
await this.getMetadata();
596544
}
597-
resultFormat = mapResultFormatToProto(this.metadata?.resultFormat);
545+
resultFormat = mapResultFormatToTelemetryType(this.metadata?.resultFormat);
598546
} catch (error) {
599547
// If metadata fetch fails, continue without it
600548
resultFormat = undefined;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright (c) 2025 Databricks Contributors
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+
*/
16+
17+
import { TOperationType, TSparkRowSetType } from '../../thrift/TCLIService_types';
18+
19+
/**
20+
* Map Thrift TOperationType to telemetry Operation.Type enum string.
21+
*/
22+
export function mapOperationTypeToTelemetryType(operationType?: TOperationType): string | undefined {
23+
if (operationType === undefined) {
24+
return undefined;
25+
}
26+
27+
switch (operationType) {
28+
case TOperationType.EXECUTE_STATEMENT:
29+
return 'EXECUTE_STATEMENT';
30+
case TOperationType.GET_TYPE_INFO:
31+
return 'LIST_TYPE_INFO';
32+
case TOperationType.GET_CATALOGS:
33+
return 'LIST_CATALOGS';
34+
case TOperationType.GET_SCHEMAS:
35+
return 'LIST_SCHEMAS';
36+
case TOperationType.GET_TABLES:
37+
return 'LIST_TABLES';
38+
case TOperationType.GET_TABLE_TYPES:
39+
return 'LIST_TABLE_TYPES';
40+
case TOperationType.GET_COLUMNS:
41+
return 'LIST_COLUMNS';
42+
case TOperationType.GET_FUNCTIONS:
43+
return 'LIST_FUNCTIONS';
44+
case TOperationType.UNKNOWN:
45+
default:
46+
return 'TYPE_UNSPECIFIED';
47+
}
48+
}
49+
50+
/**
51+
* Map Thrift TSparkRowSetType to telemetry ExecutionResult.Format enum string.
52+
*/
53+
export function mapResultFormatToTelemetryType(resultFormat?: TSparkRowSetType): string | undefined {
54+
if (resultFormat === undefined) {
55+
return undefined;
56+
}
57+
58+
switch (resultFormat) {
59+
case TSparkRowSetType.ARROW_BASED_SET:
60+
return 'INLINE_ARROW';
61+
case TSparkRowSetType.COLUMN_BASED_SET:
62+
return 'COLUMNAR_INLINE';
63+
case TSparkRowSetType.ROW_BASED_SET:
64+
return 'INLINE_JSON';
65+
case TSparkRowSetType.URL_BASED_SET:
66+
return 'EXTERNAL_LINKS';
67+
default:
68+
return 'FORMAT_UNSPECIFIED';
69+
}
70+
}

0 commit comments

Comments
 (0)