|
16 | 16 | package io.delta.kernel.internal;
|
17 | 17 |
|
18 | 18 | import java.sql.Timestamp;
|
19 |
| -import java.util.Optional; |
20 | 19 |
|
21 |
| -import io.delta.kernel.expressions.Expression; |
| 20 | +import io.delta.kernel.exceptions.KernelException; |
22 | 21 |
|
| 22 | +/** |
| 23 | + * Contains methods to create user-facing Delta exceptions. |
| 24 | + */ |
23 | 25 | public final class DeltaErrors {
|
24 | 26 | private DeltaErrors() {}
|
25 | 27 |
|
26 |
| - // TODO update to be user-facing exception with future exception framework |
27 |
| - // (see delta-io/delta#2231) & document in method docs as needed (Table::getSnapshotAtVersion) |
28 |
| - public static RuntimeException nonReconstructableStateException( |
29 |
| - String tablePath, long version) { |
| 28 | + public static KernelException versionBeforeFirstAvailableCommit( |
| 29 | + String tablePath, long versionToLoad, long earliestVersion) { |
30 | 30 | String message = String.format(
|
31 |
| - "%s: Unable to reconstruct state at version %s as the transaction log has been " + |
32 |
| - "truncated due to manual deletion or the log retention policy and checkpoint " + |
33 |
| - "retention policy.", |
| 31 | + "%s: Cannot load table version %s as the transaction log has been truncated due to " + |
| 32 | + "manual deletion or the log/checkpoint retention policy. The earliest available " + |
| 33 | + "version is %s.", |
34 | 34 | tablePath,
|
35 |
| - version); |
36 |
| - return new RuntimeException(message); |
| 35 | + versionToLoad, |
| 36 | + earliestVersion); |
| 37 | + return new KernelException(message); |
37 | 38 | }
|
38 | 39 |
|
39 |
| - // TODO update to be user-facing exception with future exception framework |
40 |
| - // (see delta-io/delta#2231) & document in method docs as needed (Table::getSnapshotAtVersion) |
41 |
| - public static RuntimeException nonExistentVersionException( |
| 40 | + public static KernelException versionAfterLatestCommit( |
42 | 41 | String tablePath, long versionToLoad, long latestVersion) {
|
43 | 42 | String message = String.format(
|
44 |
| - "%s: Trying to load a non-existent version %s. The latest version available is %s", |
| 43 | + "%s: Cannot load table version %s as it does not exist. " + |
| 44 | + "The latest available version is %s.", |
45 | 45 | tablePath,
|
46 | 46 | versionToLoad,
|
47 | 47 | latestVersion);
|
48 |
| - return new RuntimeException(message); |
| 48 | + return new KernelException(message); |
49 | 49 | }
|
50 | 50 |
|
51 |
| - // TODO update to be user-facing exception with future exception framework |
52 |
| - // (see delta-io/delta#2231) & document in method docs as needed |
53 |
| - // (Table::getSnapshotAtTimestamp) |
54 |
| - public static RuntimeException timestampEarlierThanTableFirstCommitException( |
55 |
| - String tablePath, long providedTimestamp, long commitTimestamp) { |
| 51 | + public static KernelException timestampBeforeFirstAvailableCommit( |
| 52 | + String tablePath, |
| 53 | + long providedTimestamp, |
| 54 | + long earliestCommitTimestamp, |
| 55 | + long earliestCommitVersion) { |
56 | 56 | String message = String.format(
|
57 |
| - "%s: The provided timestamp %s ms (%s) is before the earliest version available. " + |
58 |
| - "Please use a timestamp greater than or equal to %s ms (%s)", |
| 57 | + "%s: The provided timestamp %s ms (%s) is before the earliest available version %s. " + |
| 58 | + "Please use a timestamp greater than or equal to %s ms (%s).", |
59 | 59 | tablePath,
|
60 | 60 | providedTimestamp,
|
61 | 61 | formatTimestamp(providedTimestamp),
|
62 |
| - commitTimestamp, |
63 |
| - formatTimestamp(commitTimestamp)); |
64 |
| - return new RuntimeException(message); |
| 62 | + earliestCommitVersion, |
| 63 | + earliestCommitTimestamp, |
| 64 | + formatTimestamp(earliestCommitTimestamp)); |
| 65 | + return new KernelException(message); |
65 | 66 | }
|
66 | 67 |
|
67 |
| - // TODO update to be user-facing exception with future exception framework |
68 |
| - // (see delta-io/delta#2231) & document in method docs as needed |
69 |
| - // (Table::getSnapshotAtTimestamp) |
70 |
| - public static RuntimeException timestampLaterThanTableLastCommit( |
71 |
| - String tablePath, long providedTimestamp, long commitTimestamp, long commitVersion) { |
72 |
| - String commitTimestampStr = formatTimestamp(commitTimestamp); |
| 68 | + public static KernelException timestampAfterLatestCommit( |
| 69 | + String tablePath, |
| 70 | + long providedTimestamp, |
| 71 | + long latestCommitTimestamp, |
| 72 | + long latestCommitVersion) { |
73 | 73 | String message = String.format(
|
74 |
| - "%s: The provided timestamp %s ms (%s) is after the latest commit with " + |
75 |
| - "timestamp %s ms (%s). If you wish to query this version of the table please " + |
76 |
| - "either provide the version %s or use the exact timestamp of the last " + |
77 |
| - "commit %s ms (%s)", |
| 74 | + "%s: The provided timestamp %s ms (%s) is after the latest available version %s. " + |
| 75 | + "Please use a timestamp less than or equal to %s ms (%s).", |
78 | 76 | tablePath,
|
79 | 77 | providedTimestamp,
|
80 | 78 | formatTimestamp(providedTimestamp),
|
81 |
| - commitTimestamp, |
82 |
| - commitTimestampStr, |
83 |
| - commitVersion, |
84 |
| - commitTimestamp, |
85 |
| - commitTimestampStr); |
86 |
| - return new RuntimeException(message); |
| 79 | + latestCommitVersion, |
| 80 | + latestCommitTimestamp, |
| 81 | + formatTimestamp(latestCommitTimestamp)); |
| 82 | + return new KernelException(message); |
87 | 83 | }
|
88 | 84 |
|
89 |
| - // TODO: Change the exception to proper type as part of the exception framework |
90 |
| - // (see delta-io/delta#2231) |
91 |
| - /** |
92 |
| - * Exception thrown when the expression evaluator doesn't support the given expression. |
93 |
| - * @param expression |
94 |
| - * @param reason Optional additional reason for why the expression is not supported. |
95 |
| - * @return |
96 |
| - */ |
97 |
| - public static UnsupportedOperationException unsupportedExpression( |
98 |
| - Expression expression, |
99 |
| - Optional<String> reason) { |
| 85 | + /* ------------------------ PROTOCOL EXCEPTIONS ----------------------------- */ |
| 86 | + |
| 87 | + public static KernelException unsupportedReaderProtocol( |
| 88 | + String tablePath, int tableReaderVersion) { |
100 | 89 | String message = String.format(
|
101 |
| - "Expression evaluator doesn't support the expression: %s.%s", |
102 |
| - expression, |
103 |
| - reason.map(r -> " Reason: " + r).orElse("")); |
104 |
| - return new UnsupportedOperationException(message); |
| 90 | + "Unsupported Delta protocol reader version: table `%s` requires reader version %s " + |
| 91 | + "which is unsupported by this version of Delta Kernel.", |
| 92 | + tablePath, |
| 93 | + tableReaderVersion); |
| 94 | + return new KernelException(message); |
105 | 95 | }
|
106 | 96 |
|
107 |
| - public static UnsupportedOperationException unsupportedReaderProtocol(int readVersion) { |
108 |
| - throw new UnsupportedOperationException( |
109 |
| - "Unsupported reader protocol version: " + readVersion); |
| 97 | + public static KernelException unsupportedReaderFeature( |
| 98 | + String tablePath, String readerFeature) { |
| 99 | + String message = String.format( |
| 100 | + "Unsupported Delta reader feature: table `%s` requires reader table feature \"%s\" " + |
| 101 | + "which is unsupported by this version of Delta Kernel.", |
| 102 | + tablePath, |
| 103 | + readerFeature); |
| 104 | + return new KernelException(message); |
110 | 105 | }
|
111 | 106 |
|
112 |
| - public static UnsupportedOperationException unsupportedReadFeature( |
113 |
| - int readProtocolVersion, |
114 |
| - String readFeature) { |
115 |
| - throw new UnsupportedOperationException(String.format( |
116 |
| - "Unsupported reader protocol version: %s with feature: %s", |
117 |
| - readProtocolVersion, readFeature)); |
| 107 | + public static KernelException unsupportedWriterProtocol( |
| 108 | + String tablePath, int tableWriterVersion) { |
| 109 | + String message = String.format( |
| 110 | + "Unsupported Delta protocol writer version: table `%s` requires writer version %s " + |
| 111 | + "which is unsupported by this version of Delta Kernel.", |
| 112 | + tablePath, |
| 113 | + tableWriterVersion); |
| 114 | + return new KernelException(message); |
118 | 115 | }
|
119 | 116 |
|
120 |
| - public static UnsupportedOperationException unsupportedWriterProtocol(int writeVersion) { |
121 |
| - throw new UnsupportedOperationException( |
122 |
| - "Unsupported writer protocol version: " + writeVersion); |
| 117 | + public static KernelException unsupportedWriterFeature( |
| 118 | + String tablePath, String writerFeature) { |
| 119 | + String message = String.format( |
| 120 | + "Unsupported Delta writer feature: table `%s` requires writer table feature \"%s\" " + |
| 121 | + "which is unsupported by this version of Delta Kernel.", |
| 122 | + tablePath, |
| 123 | + writerFeature); |
| 124 | + return new KernelException(message); |
123 | 125 | }
|
124 | 126 |
|
125 |
| - public static UnsupportedOperationException unsupportedWriteFeature( |
126 |
| - int writeProtocolVersion, |
127 |
| - String writeFeature) { |
128 |
| - throw new UnsupportedOperationException(String.format( |
129 |
| - "Unsupported writer protocol version: %s with feature: %s", |
130 |
| - writeProtocolVersion, writeFeature)); |
| 127 | + public static KernelException columnInvariantsNotSupported() { |
| 128 | + String message = "This version of Delta Kernel does not support writing to tables with " + |
| 129 | + "column invariants present."; |
| 130 | + return new KernelException(message); |
131 | 131 | }
|
132 | 132 |
|
| 133 | + /* ------------------------ HELPER METHODS ----------------------------- */ |
| 134 | + |
133 | 135 | private static String formatTimestamp(long millisSinceEpochUTC) {
|
134 | 136 | return new Timestamp(millisSinceEpochUTC).toInstant().toString();
|
135 | 137 | }
|
|
0 commit comments