Skip to content

Commit ea72033

Browse files
hamersawclaude
andauthored
chore: remove RuntimeException string-parsing workaround for table-no… (#385)
…t-found errors Now that lance#6275 is merged and the release is brought into Spark, the namespace bridge properly throws LanceNamespaceException with ErrorCode.TABLE_NOT_FOUND, making the message-matching fallback unnecessary. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 97ee57b commit ea72033

2 files changed

Lines changed: 4 additions & 32 deletions

File tree

lance-spark-base_2.12/src/main/java/org/lance/spark/BaseLanceNamespaceSparkCatalog.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,22 +1192,8 @@ private Table loadTableInternal(
11921192
* Calls namespace.describeTable and translates table-not-found errors into Spark's {@link
11931193
* NoSuchTableException}.
11941194
*
1195-
* <p>Two catch blocks handle the error:
1196-
*
1197-
* <ol>
1198-
* <li>{@link LanceNamespaceException} with {@link ErrorCode#TABLE_NOT_FOUND} — catches the
1199-
* exception that the JNI bridge creates once the upstream lance-namespace-impls uses typed
1200-
* {@code NamespaceError::TableNotFound} (see lance PR #6267 / #6275). This also covers
1201-
* {@link TableNotFoundException} (a subclass of {@link LanceNamespaceException}).
1202-
* <li>{@link RuntimeException} with message matching — workaround for the current state where
1203-
* dir.rs and dir/manifest.rs use {@code Error::namespace_source(String)}, causing the JNI
1204-
* downcast to {@code NamespaceError} to fail and fall back to a raw RuntimeException. Two
1205-
* known message patterns: "Table does not exist: {name}" (dir.rs) and "Table '{name}' not
1206-
* found" (manifest.rs).
1207-
* </ol>
1208-
*
1209-
* <p>TODO: Remove the RuntimeException catch block once lance fixes dir.rs and manifest.rs to use
1210-
* {@code NamespaceError::TableNotFound}.
1195+
* <p>Catches {@link LanceNamespaceException} with {@link ErrorCode#TABLE_NOT_FOUND}, which covers
1196+
* {@link TableNotFoundException} (a subclass of {@link LanceNamespaceException}).
12111197
*
12121198
* <p>This helper should be used at call sites where {@code NoSuchTableException} is the expected
12131199
* outcome for missing tables (e.g. {@code loadTableInternal}, {@code stageReplace}). Call sites
@@ -1223,14 +1209,6 @@ private DescribeTableResponse describeTableOrThrow(DescribeTableRequest request,
12231209
throw new NoSuchTableException(ident);
12241210
}
12251211
throw e;
1226-
} catch (RuntimeException e) {
1227-
String msg = e.getMessage();
1228-
if (msg != null
1229-
&& (msg.contains("Table does not exist")
1230-
|| (msg.contains("Table") && msg.contains("not found")))) {
1231-
throw new NoSuchTableException(ident);
1232-
}
1233-
throw e;
12341212
}
12351213
}
12361214

lance-spark-base_2.12/src/test/java/org/lance/spark/BaseTestSparkDirectorySingleLevelNsNamespace.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@
2727
import static org.junit.jupiter.api.Assertions.assertFalse;
2828
import static org.junit.jupiter.api.Assertions.assertThrows;
2929

30-
/**
31-
* Tests for DirectoryNamespace in single-level namespace mode (no manifest). This exercises the
32-
* dir.rs "Table does not exist" error path, which is different from the manifest.rs "Table '...'
33-
* not found" path tested in {@link BaseTestSparkDirectoryNamespace}.
34-
*/
30+
/** Tests for DirectoryNamespace in single-level namespace mode (no manifest). */
3531
public abstract class BaseTestSparkDirectorySingleLevelNsNamespace {
3632
private SparkSession spark;
3733
private TableCatalog catalog;
@@ -66,14 +62,12 @@ void tearDown() {
6662
@Test
6763
public void testTableExistsReturnsFalseForNonExistentTable() {
6864
// In single-level mode, this goes through dir.rs check_table_status
69-
// which produces "Table does not exist: {table_name}"
7065
assertFalse(catalog.tableExists(Identifier.of(new String[] {"default"}, "non_existent_table")));
7166
}
7267

7368
@Test
7469
public void testLoadNonExistentTableThrowsNoSuchTableException() {
75-
// Verifies that the "Table does not exist" message from dir.rs
76-
// is correctly translated to NoSuchTableException
70+
// Verifies that a missing table is correctly translated to NoSuchTableException
7771
assertThrows(
7872
NoSuchTableException.class,
7973
() -> catalog.loadTable(Identifier.of(new String[] {"default"}, "non_existent_table")));

0 commit comments

Comments
 (0)