Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6c0d604
[Build] Run all tests on MySQL 8.4
shba24 Oct 24, 2026
cc70790
[Server] Return table columns in their declared order
shba24 Oct 24, 2026
d63d59e
[Server] Warn when a MySQL database compares text case-insensitively
shba24 Oct 24, 2026
4b2a438
[Build] Build MySQL test databases from a template, like PostgreSQL
shba24 Oct 24, 2026
1fe089f
[Server] Address review comments on the MySQL test harness
shba24 Oct 24, 2026
e08c15b
[Server] Run the MySQL Delta commit tests through the shared harness
shba24 Oct 24, 2026
ea0ad3b
[Server] Inject test databases with @TempDatabase
shba24 Oct 24, 2026
fd79c58
[Build] Pin the PostgreSQL and MySQL test images by digest
shba24 Oct 24, 2026
39d29f6
[Build] Explain the test-only server settings of the MySQL and Postgr…
shba24 Oct 24, 2026
b859fc3
[Server] Explain the isolation-level test and the MySQL template's ha…
shba24 Oct 24, 2026
4efa2fb
[Build] Run the index-limit test on MySQL
shba24 Oct 26, 2026
a4092d0
[Build] Clarify the test database harness comments
shba24 Oct 27, 2026
3ee212e
[Server] Check each database's isolation level in the lock re-read test
shba24 Oct 27, 2026
2ec4ce9
[Server] Describe the MySQL collation without claiming names are case…
shba24 Oct 28, 2026
ba61cf5
[Build] Drop the half-built MySQL database when cloning the template …
shba24 Oct 28, 2026
3eacb82
[Server] Submit the function parameters out of position order in the …
shba24 Oct 28, 2026
421f6d9
[Server] Leave the derived-table DELETE note to DeltaCommitRepository
shba24 Oct 28, 2026
f000906
[Build] Fail a MySQL test that leaks a transaction instead of hanging…
shba24 Oct 29, 2026
469b6fd
[Server] Do not fail startup when the MySQL collation check throws
shba24 Oct 29, 2026
ebec639
[Server] Warn about case-insensitive MySQL by reading the columns' co…
shba24 Oct 29, 2026
627bfc4
[Server] Tidy the MySQL collation check and document converting an ex…
shba24 Oct 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
# "All tests (Spark 4.0.0, Delta 4.3.1)"
# "[Non Blocking] Spark tests (Spark 4.2.0, Delta master-SNAPSHOT)"
# "All tests (Spark 4.0.0, Delta 4.3.1, POSTGRES_18)"
# "All tests (Spark 4.0.0, Delta 4.3.1, MYSQL_8)"
name: >-
${{ matrix.non-blocking && '[Non Blocking]' || '' }}
${{ matrix.validation-mode == 'spark-tests' && 'Spark tests' || 'All tests' }}
Expand All @@ -67,6 +68,13 @@ jobs:
test-database: "POSTGRES_18"
non-blocking: false
spark-source-build: false
- spark-version: "4.0.0"
delta-version: "4.3.1"
# Primary combo on MySQL 8.4: every test project runs on MySQL.
validation-mode: "all-tests"
test-database: "MYSQL_8"
non-blocking: false
spark-source-build: false
- spark-version: "4.1.0"
delta-version: "4.3.1"
validation-mode: "spark-tests"
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Conventions:

- **Read paths pass `readOnly = true`; write paths pass `false`.** A path that needs a specific isolation level passes it explicitly; it applies to that transaction only, and Hikari resets it when the connection returns to the pool.
- **DAOs extend `IdentifiableDAO`** (UUID id plus name), are annotated `@Entity @Table(name = "uc_...")`, use Lombok (`@Getter @Setter @SuperBuilder @NoArgsConstructor @AllArgsConstructor`), and expose static `from(XInfo)` and instance `toXInfo()` converters. Keep business logic out of DAOs.
- **Backends:** H2 by default (embedded, file-based). MySQL and PostgreSQL are supported for a persistent deployment, configured in `etc/conf/hibernate.properties` (point at your database and add the JDBC driver); see `docs/server/deployment.md`. Hibernate is configured in `persist/utils/HibernateConfigurator`. Tests run on H2 by default; `build/sbt -J-Xmx6G testPostgres18` (or `UC_TEST_DATABASE=POSTGRES_18`) runs them on PostgreSQL 18 in Docker, each test on its own database, and fails rather than skips when Docker is not available. `MySQLDeltaCommitsCRUDTest` starts its own MySQL container via Testcontainers. When adding schema, keep any index or column change safe across a server restart on an existing database, and portable across all three backends.
- **Backends:** H2 by default (embedded, file-based). MySQL and PostgreSQL are supported for a persistent deployment, configured in `etc/conf/hibernate.properties` (point at your database and add the JDBC driver); see `docs/server/deployment.md`. Hibernate is configured in `persist/utils/HibernateConfigurator`. Tests run on H2 by default; `build/sbt -J-Xmx6G testPostgres18` or `testMySQL8` (or `UC_TEST_DATABASE=POSTGRES_18` / `MYSQL_8`) runs them on PostgreSQL 18 or MySQL 8.4 in Docker, each test on its own database, and fails rather than skips when Docker is not available. When adding schema, keep any index or column change safe across a server restart on an existing database, and portable across all three backends.
- **Enforce invariants at the database level** (unique constraints) rather than only in code, where duplicate creation or races are possible.

## Error handling
Expand Down
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,7 @@ lazy val server = (project in file("server"))
"javax.xml.bind" % "jaxb-api" % "2.3.1" % Test,

// Integration testing
"org.testcontainers" % "mysql" % testcontainersVersion % Test,
"org.testcontainers" % "junit-jupiter" % testcontainersVersion % Test,
"com.mysql" % "mysql-connector-j" % "8.4.0" % Test,

// CLI dependencies
"commons-cli" % "commons-cli" % "1.7.0"
Expand Down Expand Up @@ -666,6 +664,8 @@ lazy val testDatabaseDependencies = Seq(
"org.testcontainers" % "testcontainers" % testcontainersVersion % Test,
"org.testcontainers" % "postgresql" % testcontainersVersion % Test,
"org.postgresql" % "postgresql" % postgresqlVersion % Test,
"org.testcontainers" % "mysql" % testcontainersVersion % Test,
"com.mysql" % "mysql-connector-j" % "8.4.0" % Test,
)

/*
Expand Down Expand Up @@ -899,3 +899,4 @@ val generate = taskKey[Unit]("generate code from APIs")
def testOnDatabase(database: String): String =
s"""; set every Test / envVars := Map("UC_TEST_DATABASE" -> "$database") ; test"""
addCommandAlias("testPostgres18", testOnDatabase("POSTGRES_18"))
addCommandAlias("testMySQL8", testOnDatabase("MYSQL_8"))
16 changes: 16 additions & 0 deletions docs/server/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ This guide outlines how to deploy the Unity Catalog server.
docker-compose -f etc/db/mysql-example.yml up -d
```

- Unity Catalog compares storage paths exactly, so two paths that differ only in case are
different locations. PostgreSQL and H2 compare text exactly by default, but MySQL's default
collation ignores case. Create the database with a binary collation. The example file already does this for `ucdb` when it creates a
new data volume; for your own server run:

```sql
CREATE DATABASE ucdb CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin;
```

The server logs a warning at startup if any text column in the database uses a case-insensitive
collation.

For an existing database, `ALTER DATABASE ... COLLATE` changes only the default for tables created
later. Convert each existing table instead, for example
`ALTER TABLE <table> CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin;`.

- Modify the `etc/conf/hibernate.properties` file with your MySQL connection details:

```properties
Expand Down
2 changes: 2 additions & 0 deletions etc/db/mysql-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ services:
db:
image: mysql:8.4.1
restart: always
# Case-sensitive text comparison, like PostgreSQL and H2.
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_0900_bin
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ucdb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Lob;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -86,10 +87,12 @@ public class FunctionInfoDAO extends IdentifiableDAO {

@OneToMany(mappedBy = "function", cascade = CascadeType.ALL, orphanRemoval = true)
@SQLRestriction("input_or_return = 0")
@OrderBy("position")
private List<FunctionParameterInfoDAO> inputParams;

@OneToMany(mappedBy = "function", cascade = CascadeType.ALL, orphanRemoval = true)
@SQLRestriction("input_or_return = 1")
@OrderBy("position")
private List<FunctionParameterInfoDAO> returnParams;

public static FunctionInfoDAO from(FunctionInfo functionInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import lombok.Getter;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
Expand Down Expand Up @@ -71,6 +77,44 @@ public HibernateConfigurator(Properties hibernateProperties) {
dataSource.close();
throw t;
}
warnIfMySqlIsCaseInsensitive(hibernateProperties);
}

/**
* Storage paths compare exactly, but MySQL's default collation ignores case. Warns when any text
* column in the connected MySQL schema has a case-insensitive ({@code _ci}) collation. A failed
* check never fails startup.
*/
private void warnIfMySqlIsCaseInsensitive(Properties properties) {
if (!properties.getProperty("hibernate.connection.url", "").startsWith("jdbc:mysql")) {
return;
}
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
ResultSet collations =
statement.executeQuery(
"SELECT DISTINCT COLLATION_NAME FROM information_schema.COLUMNS "
+ "WHERE TABLE_SCHEMA = DATABASE() AND COLLATION_NAME IS NOT NULL")) {
Set<String> caseInsensitive = new TreeSet<>();
while (collations.next()) {
String collation = collations.getString(1);
if (collation.endsWith("_ci")) {
caseInsensitive.add(collation);
}
}
if (!caseInsensitive.isEmpty()) {
LOGGER.warn(
"The MySQL database compares text case-insensitively (collation {}), so storage paths"
+ " that differ only in case are treated as the same. Create the"
+ " database with COLLATE utf8mb4_0900_bin; see the MySQL section of"
+ " docs/server/deployment.md.",
caseInsensitive);
}
} catch (SQLException | RuntimeException e) {
// Only a warning is lost, and an exception here would leak the pool: the constructor does not
// close it after this point.
LOGGER.warn("Could not check whether the MySQL database compares text case-insensitively", e);
}
}

private static HikariDataSource createDataSource(Properties hibernateProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import io.unitycatalog.server.persist.model.Privileges;
import io.unitycatalog.server.persist.utils.HibernateConfigurator;
import io.unitycatalog.server.testdatabase.TempDatabase;
import io.unitycatalog.server.testdatabase.TestDatabase;
import io.unitycatalog.server.testdatabase.TestDatabases;
import io.unitycatalog.server.utils.ServerProperties;
import io.unitycatalog.server.utils.ServerProperties.Property;
import java.time.Duration;
Expand All @@ -33,23 +33,18 @@ public class JCasbinAuthorizerMultiInstanceTest {
private static final String TEST_REFRESH_INTERVAL = "PT0.05S";

private HibernateConfigurator hibernateConfigurator;
private TestDatabase testDatabase;
@TempDatabase private TestDatabase testDatabase;
private final List<JCasbinAuthorizer> replicas = new ArrayList<>();

@BeforeEach
void setUp() {
Properties properties = new Properties();
properties.setProperty(Property.SERVER_ENV.getKey(), "test");
testDatabase = TestDatabases.newDatabase();
hibernateConfigurator =
testDatabase.openHibernateConfigurator(new ServerProperties(properties));
hibernateConfigurator = testDatabase.hibernateConfigurator();
}

@AfterEach
void tearDown() {
replicas.forEach(JCasbinAuthorizer::close);
replicas.clear();
testDatabase.close();
}

private ServerProperties properties(boolean refreshEnabled, String interval) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import io.unitycatalog.server.persist.model.Privileges;
import io.unitycatalog.server.persist.utils.HibernateConfigurator;
import io.unitycatalog.server.testdatabase.TempDatabase;
import io.unitycatalog.server.testdatabase.TestDatabase;
import io.unitycatalog.server.testdatabase.TestDatabases;
import io.unitycatalog.server.utils.ServerProperties;
import io.unitycatalog.server.utils.ServerProperties.Property;
import java.sql.Connection;
Expand All @@ -21,7 +21,7 @@
public class JCasbinAuthorizerTest {
private UnityCatalogAuthorizer authenticator;
private HibernateConfigurator hibernateConfigurator;
private TestDatabase testDatabase;
@TempDatabase private TestDatabase testDatabase;

@BeforeEach
void setUp() throws Exception {
Expand All @@ -30,8 +30,7 @@ void setUp() throws Exception {
// Single-instance tests do not need background polling.
properties.setProperty(Property.POLICY_REFRESH_ENABLED.getKey(), "false");
ServerProperties serverProperties = new ServerProperties(properties);
testDatabase = TestDatabases.newDatabase();
hibernateConfigurator = testDatabase.openHibernateConfigurator(serverProperties);
hibernateConfigurator = testDatabase.hibernateConfigurator();
authenticator = new JCasbinAuthorizer(hibernateConfigurator, serverProperties);
}

Expand All @@ -44,7 +43,6 @@ void tearDown() {
throw new RuntimeException(e);
}
}
testDatabase.close();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import io.unitycatalog.server.persist.utils.FileOperations;
import io.unitycatalog.server.persist.utils.HibernateConfigurator;
import io.unitycatalog.server.service.credential.CloudCredentialVendor;
import io.unitycatalog.server.testdatabase.TempDatabase;
import io.unitycatalog.server.testdatabase.TestDatabase;
import io.unitycatalog.server.testdatabase.TestDatabases;
import io.unitycatalog.server.utils.ServerProperties;
import io.unitycatalog.server.utils.ServerProperties.Property;
import java.io.IOException;
Expand All @@ -33,7 +33,7 @@ public abstract class BaseServerTest {
protected HibernateConfigurator hibernateConfigurator;

/** This test's database on the backend selected by UC_TEST_DATABASE. */
protected TestDatabase testDatabase;
@TempDatabase protected TestDatabase testDatabase;

protected CloudCredentialVendor cloudCredentialVendor;

Expand Down Expand Up @@ -84,14 +84,6 @@ protected FileOperations decorateFileOperations(FileOperations fileOperations) {
return fileOperations;
}

/**
* Subclasses can override this to customize the hibernate properties before the session factory
* is created. They start as this test's database from {@link TestDatabases}; a subclass that
* points the server at its own database also sets {@code hibernate.hbm2ddl.auto} so each test
* gets a fresh schema.
*/
protected void setUpHibernateProperties(Properties hibernateProperties) {}

@SneakyThrows
@BeforeEach
public void setUp() {
Expand All @@ -111,10 +103,7 @@ public void setUp() {
setUpProperties();
ServerProperties initServerProperties = new ServerProperties(serverProperties);
setUpCredentialOperations(initServerProperties);
testDatabase = TestDatabases.newDatabase();
Properties hibernateProperties = testDatabase.hibernateProperties(initServerProperties);
setUpHibernateProperties(hibernateProperties);
hibernateConfigurator = testDatabase.openHibernateConfigurator(hibernateProperties);
hibernateConfigurator = testDatabase.hibernateConfigurator();
startServerOnFreePorts(initServerProperties);
}
}
Expand Down Expand Up @@ -170,23 +159,13 @@ private static int[] findTwoAvailablePorts() throws IOException {

@AfterEach
public void tearDown() {
// No cleanup queries: each test's database is dropped below, or, for a subclass with its own
// database, its create-drop schema is dropped when the configurator closes.
try {
if (unityCatalogServer != null) {
// close() rather than stop() so a server that built its own SessionFactory releases it;
// this harness injects one, so the server leaves it open; testDatabase.close() closes it.
unityCatalogServer.close();
// Null out so tearDown is idempotent if a subclass @AfterEach also invokes it.
unityCatalogServer = null;
}
} finally {
// Runs even if setUp() failed. Closes the configurator and removes the database, so it must
// follow unityCatalogServer.close().
if (testDatabase != null) {
testDatabase.close();
testDatabase = null;
}
// The server closes here; its database is dropped afterwards (see TempDatabase).
if (unityCatalogServer != null) {
// close() rather than stop() so a server that built its own SessionFactory releases it;
// this harness injects one, so the server leaves it open.
unityCatalogServer.close();
// Null out so tearDown is idempotent if a subclass @AfterEach also invokes it.
unityCatalogServer = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ protected void assertFunction(FunctionInfo functionInfo, String functionName) {
assertThat(functionInfo.getFunctionId()).isNotNull();
}

private static FunctionParameterInfo functionParameter(String name, int position) {
return new FunctionParameterInfo()
.name(name)
.typeName(ColumnTypeName.INT)
.typeText("int")
.typeJson("{\"type\":\"int\"}")
.position(position);
}

@Test
public void testFunctionCRUD() throws ApiException {
assertThatThrownBy(() -> functionOperations.getFunction(FUNCTION_FULL_NAME))
Expand All @@ -72,6 +81,9 @@ public void testFunctionCRUD() throws ApiException {
new FunctionParameterInfos()
.parameters(
List.of(
// Submitted out of position order, so only ordering by position returns
// them in order
functionParameter("gamma", 3),
new FunctionParameterInfo()
.name("param1")
.typeName(ColumnTypeName.INT)
Expand All @@ -82,7 +94,9 @@ public void testFunctionCRUD() throws ApiException {
+ "\"metadata\":{\"comment\":\""
+ "x".repeat(300)
+ "\"}}")
.position(0)));
.position(0),
functionParameter("beta", 2),
functionParameter("zeta", 1)));
CreateFunction createFunction =
new CreateFunction()
.name(FUNCTION_NAME)
Expand Down Expand Up @@ -184,7 +198,14 @@ public void testFunctionCRUD() throws ApiException {
// Get function
System.out.println("Testing get function..");
FunctionInfo retrievedFunctionInfo = functionOperations.getFunction(FUNCTION_FULL_NAME);
assertThat(retrievedFunctionInfo).isEqualTo(functionInfo);
// The create response keeps the order it was given; get returns the parameters by position.
assertThat(retrievedFunctionInfo)
.usingRecursiveComparison()
.ignoringCollectionOrderInFields("inputParams.parameters")
.isEqualTo(functionInfo);
assertThat(retrievedFunctionInfo.getInputParams().getParameters())
.extracting(FunctionParameterInfo::getPosition)
.isSorted();

// now update the parent catalog
UpdateCatalog updateCatalog = new UpdateCatalog().newName(CATALOG_NEW_NAME);
Expand Down
Loading
Loading