diff --git a/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/JdbcConnection.java b/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/JdbcConnection.java index 205f193523..658271678a 100644 --- a/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/JdbcConnection.java +++ b/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/JdbcConnection.java @@ -27,6 +27,7 @@ import org.apache.arrow.adbc.core.AdbcConnection; import org.apache.arrow.adbc.core.AdbcException; import org.apache.arrow.adbc.core.AdbcStatement; +import org.apache.arrow.adbc.core.AdbcStatusCode; import org.apache.arrow.adbc.core.BulkIngestMode; import org.apache.arrow.adbc.core.IsolationLevel; import org.apache.arrow.adbc.core.StandardSchemas; @@ -121,6 +122,21 @@ public ArrowReader getObjects( @Override public Schema getTableSchema(String catalog, String dbSchema, String tableName) throws AdbcException { + // Check for existence + try (final ResultSet rs = + connection.getMetaData().getTables(catalog, dbSchema, tableName, /*tableTypes*/ null)) { + if (!rs.next()) { + throw new AdbcException( + JdbcDriverUtil.prefixExceptionMessage("Table not found: " + tableName), /*cause*/ + null, + AdbcStatusCode.NOT_FOUND, /*sqlState*/ + null, /*vendorCode*/ + 0); + } + } catch (SQLException e) { + throw JdbcDriverUtil.fromSqlException(e); + } + // Reconstruct the schema from the metadata // XXX: this may be inconsistent with reading the table final List fields = new ArrayList<>(); diff --git a/java/driver/validation/src/main/java/org/apache/arrow/adbc/driver/testsuite/AbstractConnectionMetadataTest.java b/java/driver/validation/src/main/java/org/apache/arrow/adbc/driver/testsuite/AbstractConnectionMetadataTest.java index 5d14339766..e2b377b8b7 100644 --- a/java/driver/validation/src/main/java/org/apache/arrow/adbc/driver/testsuite/AbstractConnectionMetadataTest.java +++ b/java/driver/validation/src/main/java/org/apache/arrow/adbc/driver/testsuite/AbstractConnectionMetadataTest.java @@ -18,6 +18,7 @@ package org.apache.arrow.adbc.driver.testsuite; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.ArrayList; import java.util.Arrays; @@ -28,8 +29,10 @@ import java.util.stream.IntStream; import org.apache.arrow.adbc.core.AdbcConnection; import org.apache.arrow.adbc.core.AdbcDatabase; +import org.apache.arrow.adbc.core.AdbcException; import org.apache.arrow.adbc.core.AdbcInfoCode; import org.apache.arrow.adbc.core.AdbcStatement; +import org.apache.arrow.adbc.core.AdbcStatusCode; import org.apache.arrow.adbc.core.BulkIngestMode; import org.apache.arrow.adbc.core.StandardSchemas; import org.apache.arrow.memory.BufferAllocator; @@ -306,6 +309,15 @@ public void getTableSchema() throws Exception { .isEqualTo(schema); } + @Test + public void getTableSchemaDoesNotExist() throws Exception { + final AdbcException thrown = + assertThrows( + AdbcException.class, + () -> connection.getTableSchema(/*catalog*/ null, /*dbSchema*/ null, "DOESNOTEXIST")); + assertThat(thrown.getStatus()).isEqualTo(AdbcStatusCode.NOT_FOUND); + } + @Test public void getTableTypes() throws Exception { try (final ArrowReader reader = connection.getTableTypes()) {