forked from databricks/databricks-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabricksSQLException.java
More file actions
99 lines (84 loc) · 3.65 KB
/
DatabricksSQLException.java
File metadata and controls
99 lines (84 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.databricks.jdbc.exception;
import static com.databricks.jdbc.telemetry.TelemetryHelper.exportFailureLog;
import com.databricks.jdbc.common.TelemetryLogLevel;
import com.databricks.jdbc.common.util.DatabricksThreadContextHolder;
import com.databricks.jdbc.model.telemetry.enums.DatabricksDriverErrorCode;
import java.sql.SQLException;
/** Top level exception for Databricks driver */
public class DatabricksSQLException extends SQLException {
public DatabricksSQLException(String reason, DatabricksDriverErrorCode internalError) {
this(reason, internalError.name());
}
public DatabricksSQLException(
String reason, DatabricksDriverErrorCode internalError, boolean silentExceptions) {
this(reason, internalError.name(), silentExceptions);
}
public DatabricksSQLException(
String reason, Throwable cause, DatabricksDriverErrorCode internalError) {
this(reason, cause, internalError.toString());
}
public DatabricksSQLException(String reason, Throwable cause, String sqlState) {
this(reason, sqlState, DatabricksVendorCode.getVendorCode(cause), cause);
}
// Chunk-download path: routes statementId + chunkIndex into the telemetry record so failures
// can be bucketed per chunk. Other constructors do not carry chunkIndex.
public DatabricksSQLException(
String reason, Throwable cause, String statementId, Long chunkIndex, String sqlState) {
super(reason, sqlState, DatabricksVendorCode.getVendorCode(cause), cause);
exportFailureLog(
DatabricksThreadContextHolder.getConnectionContext(),
sqlState,
reason,
statementId,
chunkIndex,
TelemetryLogLevel.ERROR);
}
public DatabricksSQLException(String reason, String sqlState) {
this(reason, sqlState, false);
}
public DatabricksSQLException(String reason, String sqlState, boolean silentExceptions) {
this(reason, sqlState, DatabricksVendorCode.getVendorCode(reason), silentExceptions);
}
public DatabricksSQLException(
String reason, String sqlState, DatabricksDriverErrorCode internalError) {
this(reason, sqlState, internalError, false);
}
public DatabricksSQLException(
String reason,
String sqlState,
DatabricksDriverErrorCode internalError,
boolean silentExceptions) {
super(reason, sqlState, internalError.getCode());
logTelemetryEvent(sqlState, reason, silentExceptions);
}
public DatabricksSQLException(String reason, String sqlState, int vendorCode) {
this(reason, sqlState, vendorCode, false);
}
public DatabricksSQLException(
String reason, String sqlState, int vendorCode, boolean silentExceptions) {
super(reason, sqlState, vendorCode);
logTelemetryEvent(sqlState, reason, silentExceptions);
}
public DatabricksSQLException(String reason, String sqlState, int vendorCode, Throwable cause) {
super(reason, sqlState, vendorCode, cause);
logTelemetryEvent(sqlState, reason, false);
}
private void logTelemetryEvent(String sqlState, String reason, boolean silentExceptions) {
if (!silentExceptions) {
exportFailureLog(
DatabricksThreadContextHolder.getConnectionContext(),
sqlState,
reason,
TelemetryLogLevel.ERROR);
} else {
// These are errors that are thrown to call a fallback method (e.g. metadata column not
// present in SEA response). Use TRACE so they are filtered out by the default telemetry
// log level (DEBUG) and only visible when telemetryLogLevel=TRACE is explicitly set.
exportFailureLog(
DatabricksThreadContextHolder.getConnectionContext(),
sqlState,
reason,
TelemetryLogLevel.TRACE);
}
}
}