cobed95 commented on code in PR #4945: URL: https://github.com/apache/polaris/pull/4945#discussion_r3626972394
########## persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperationsSchemaTest.java: ########## @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.persistence.relational.jdbc; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.InputStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import javax.sql.DataSource; +import org.h2.jdbcx.JdbcConnectionPool; +import org.junit.jupiter.api.Test; + +/** + * End-to-end tests against a real H2 database showing that the persistence code is agnostic of the + * database schema: the schema is created and selected entirely through the datasource (here via + * H2's {@code INIT=} URL setting, the equivalent of the PostgreSQL driver's {@code currentSchema} + * connection property plus a DBA-created schema), and the unqualified SQL generated by the + * persistence layer resolves against it. + */ +class DatasourceOperationsSchemaTest { + + private static DataSource createDataSource(String schemaName) { + String url = "jdbc:h2:mem:schema_test_" + UUID.randomUUID() + ";DB_CLOSE_DELAY=-1"; + if (schemaName != null) { + url += ";INIT=CREATE SCHEMA IF NOT EXISTS " + schemaName + "\\;SET SCHEMA " + schemaName; + } + return JdbcConnectionPool.create(url, "sa", ""); + } + + private static InputStream openSchemaScript() { + return DatasourceOperations.class.getClassLoader().getResourceAsStream("h2/schema-v5.sql"); + } + + /** Schemas holding an ENTITIES table, as reported by the database catalog. */ + private static List<String> schemasContainingEntitiesTable(DataSource dataSource) + throws SQLException { + List<String> schemas = new ArrayList<>(); + try (Connection connection = dataSource.getConnection(); + PreparedStatement statement = + connection.prepareStatement( + "SELECT table_schema FROM information_schema.tables WHERE table_name = 'ENTITIES'")) { Review Comment: Done in [142c64cc4](https://github.com/apache/polaris/pull/4945/commits/142c64cc4) — bounded the lookup with `LIMIT 1` and return the single row. Thanks! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
