Skip to content

[Python][Server] Keep element types in OSS type_json for ARRAY and MAP parameters - #2013

Merged
yili-db merged 3 commits into
unitycatalog:mainfrom
maharanay22:fix-oss-type-json-element-types
Oct 22, 2026
Merged

yili-db merged 3 commits into
unitycatalog:mainfrom
maharanay22:fix-oss-type-json-element-types

Conversation

@maharanay22

@maharanay22 maharanay22 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

Description of changes

The OSS client stored type_json using only the base type name, so list[int] was saved as {"type": "array"} and dict[str, float] as {"type": "map"}. type_text was already correct (ARRAY<LONG>, MAP<STRING, DOUBLE>). The toolkits build tool schemas from type_json, so OpenAI tools got "items": {} and "additionalProperties": true, and the inner types were lost

type_json is now built from the SQL type as nested Spark style JSON (elementType / containsNull for arrays, keyType / valueType / valueContainsNull for maps), which is the format uc_type_json_to_pydantic_type already reads. Scalar types are unchanged. I build it from the SQL type text so type_text and type_json always agree. Map types are split with the existing _split_generic_types, which now also ignores commas inside (), so keys and values like DECIMAL(38, 18) work. That also fixes _parse_sql_data_type for types like MAP<STRING, DECIMAL(38, 18)>, which used to drop the value type

The server stored uc_function_params.type_json as varchar(255), and the nested type JSON of a parameter like dict[str, list[dict[str, list[float]]]] is longer than that, so registering it failed with a 500. The column now uses the same length as uc_columns.type_json. With hibernate.hbm2ddl.auto=update, Hibernate widened the column of an existing H2 database on startup in my test, so there is no manual migration step. I could not check MySQL and PostgreSQL locally

Behavior changes:

  • A dict with a non-string key, like dict[int, float], now gets "keyType": "long", and loading it raises "Only support STRING key type for MAP", the same as a Databricks function with a MAP<BIGINT, ...> parameter. Before, it loaded as a plain dict. JSON object keys are always strings, so those keys never reached the function as ints anyway
  • OpenAI strict mode now looks at the element types. Before, every array and map counted as strict because type_json was a bare "array" or "map". Now list[datetime.date] or dict[str, Decimal] makes the tool strict=false, the same as a Databricks function with those types, while list[int] stays strict

Testing

  • core/tests/core/test_callable_utils_oss.py checks the generated type_json for list[int], list[list[int]], dict[str, list[float]], dict[Decimal, int], dict[int, float], list[date] and str, checks that the result builds a model that accepts valid input and rejects a wrong leaf type at each level, that non-string map keys raise the TypeError, and that list[date] is non-strict while the others stay strict. These fail on main and pass with this change

      • BaseFunctionCRUDTest.testFunctionCRUD now gives param1 a type_json longer than 255 characters, and its existing get assertion checks it comes back unchanged. It fails with a 500 before the column change and passes after
  • Against a local UC server, registering nested_weights(weights: dict[str, list[dict[str, list[float]]]]) failed with Value too long for column "TYPE_JSON CHARACTER VARYING(255)" before the column change, and after it the function registers, its 369 character type_json comes back unchanged and it executes

  • Against a local UC server, the OpenAI tool for total(xs: list[int], weights: dict[str, float]) now shows integer items and number values instead of empty types

  • The core test suite and the OSS client tests against a local server give the same results before and after, apart from the new tests. The only failures are Windows only (no fork for the sandbox executor) and also happen on main

  • ruff check, ruff format --check and build/sbt javafmtCheck pass

I used an AI assistant to help investigate and test this, and I reviewed every change myself

…ters

create_parameter_info built type_json from the base type name only, so
a list[int] parameter was stored as {"type": "array"} and a
dict[str, float] parameter as {"type": "map"}, even though type_text was
ARRAY<LONG> and MAP<STRING, DOUBLE>. The toolkits read type_json, so the
generated tool schemas lost the element and value types ("items": {}
and "additionalProperties": true) and did not validate them. Build the
Spark-style nested type JSON (elementType/containsNull and
keyType/valueType/valueContainsNull) from the parameter's SQL type, the
shape that uc_type_json_to_pydantic_type already parses.

Signed-off-by: Maha Rana Yadavalli <[email protected]>
@yili-db

yili-db commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Thanks for the fix, the nested shape matches what uc_type_json_to_pydantic_type reads. Main concern is that the larger type_json no longer fits the server column; a few smaller notes inline.

type_json_dict = {
"name": param_info["name"],
"type": param_info["base_type_name"].lower(),
"type": _sql_type_to_type_json(param_info["sql_type"]),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Have you tried registering a function with a nested collection against a real server? FunctionParameterInfoDAO.typeJson is @Column(name = "type_json") with no length, so it is varchar(255), and this value now carries the whole type tree plus the name and comment. dict[str, list[dict[str, list[float]]]] with the comment "Weights per key." is already ~370 chars, so registration that works today would fail on H2/PostgreSQL (and MySQL strict mode).

Can we widen the column to match ColumnInfoDAO (@Column(name = "type_json", length = 16777215), not @Lob)? Please also add a server test that creates/gets a function whose parameter type_json is longer than 255 chars and checks it round-trips unchanged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right. I registered nested_weights(weights: dict[str, list[dict[str, list[float]]]]) with the comment "Weights per key." against a local server and it failed with Value too long for column "TYPE_JSON CHARACTER VARYING(255)", since the type_json is 369 chars. The same function registers fine on main because type_json is just "map" there

I widened FunctionParameterInfoDAO.typeJson to length = 16777215 like ColumnInfoDAO, and added testFunctionParameterTypeJsonLongerThanDefaultVarchar to BaseFunctionCRUDTest. It creates a function whose parameter type_json is longer than 255 chars and checks that get returns it unchanged. It fails with the same 500 before the DAO change and passes after

For existing databases, I started the fixed server on the checked-in etc/db/h2db.mv.db, where the column was VARCHAR(255), and Hibernate's update widened it on startup, so the registration then worked. Hibernate 6.5's table migrator alters a column when the length differs, and the H2, PostgreSQL and MySQL dialects all support that, so I didn't add manual ALTER notes. That doesn't match the note #1824 added for uc_properties, though. I could only check H2 since I don't have Docker for the MySQL and PostgreSQL containers, so I'm happy to add the statements to deployment.md if you'd rather be safe (ai assisted)

type_json_dict = {
"name": param_info["name"],
"type": param_info["base_type_name"].lower(),
"type": _sql_type_to_type_json(param_info["sql_type"]),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] One more behavior change worth calling out in the description: collections used to be a bare "array" / "map", both in JSON_SCHEMA_TYPE, so they counted as strict. Now the leaf is checked, so list[datetime.date] or dict[str, Decimal] flips the OpenAI tool to strict=false. Probably more correct (matches Databricks-sourced type_json), but can you mention it and add a test that list[date] is non-strict while list[int] stays strict?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I added it to the description. The new test_generate_function_info_strictness_follows_element_type checks that with strict=True a list[date] parameter comes out non-strict while list[int], list[list[int]] and dict[str, list[float]] stay strict. The list[date] case fails on main (ai assisted)

)


def _split_map_types(inner: str) -> Tuple[str, str]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] callable_utils.py already has _split_generic_types doing the same depth-tracking split (it ignores (), so it has the DECIMAL(38, 18) bug you fixed here). Can we reuse/fix that one instead of adding a second splitter?

Also, did you consider building type_json from the Python type in the same walk as python_type_to_sql_type, rather than re-parsing the SQL string it just produced? Both would still agree by construction, without a parser.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The OSS code now uses _split_generic_types, and I changed it to also track () so DECIMAL(38, 18) doesn't get split in the middle. That also fixes _parse_sql_data_type for a type like MAP<STRING, DECIMAL(38, 18)>, which used to lose the value type

I looked at building type_json from the Python type, but that needs a second recursive walk over type hints next to python_type_to_sql_type, plus the Optional handling in validate_type_hint, or a change to what python_type_to_sql_type returns for all its callers. Parsing the SQL type keeps one type mapping and is now about 20 lines, so I kept it. This still merges cleanly with #1988 (ai assisted)

]


def test_generate_function_info_type_json_round_trips_to_typed_schema():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] What proves the one deliberate behavior change? rates is dropped by *_, so nothing asserts that dict[Decimal, int] / dict[int, float] now raise "Only support STRING key type for MAP". Can we assert that TypeError, and look parameters up by name rather than position?

Also, weights={"a": "x"} below only shows the value must be a list; {"a": ["x"]} would actually test the float leaf. A deeper case like list[list[int]] would be nice too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. The tests now look parameters up by name, check that dict[Decimal, int] and dict[int, float] both raise TypeError matching "Only support STRING key type for MAP", use {"a": ["x"]} so the float leaf is what fails, and add list[list[int]] to both the type_json and the validation checks (ai assisted)

…plitter

Widen uc_function_params.type_json to the same length as uc_columns.type_json
so the nested type JSON of collection parameters fits, and add a server test
that a parameter type_json over 255 characters round-trips.

Reuse _split_generic_types for MAP types and make it skip commas inside
parentheses, so DECIMAL(38, 18) keys and values split correctly.

Extend the OSS tests: look parameters up by name, cover list[list[int]],
the float leaf of dict[str, list[float]], the TypeError for non-string map
keys, and strict mode for list[date] vs list[int].

Signed-off-by: Maha Rana Yadavalli <[email protected]>
@maharanay22
maharanay22 requested a review from openinx as a code owner October 20, 2026 02:35
@maharanay22 maharanay22 changed the title [Python] Keep element types in OSS type_json for ARRAY and MAP parameters [Python][Server] Keep element types in OSS type_json for ARRAY and MAP parameters Oct 20, 2026

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Thanks, all four earlier comments are addressed. Two small follow-ups inline.

}

@Test
public void testFunctionParameterTypeJsonLongerThanDefaultVarchar() throws ApiException {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Can we avoid a third copy of the CreateFunction builder? Making param1's typeJson in testFunctionCRUD longer than 255 chars would cover this, since its get already asserts isEqualTo(functionInfo). E.g. a 300-char metadata.comment inside the typeJson string (not .comment(...), since the param comment column is still varchar(255)):

.typeJson(
    "{\"name\":\"param1\",\"type\":\"int\",\"nullable\":false,"
        + "\"metadata\":{\"comment\":\"" + "x".repeat(300) + "\"}}")

A one-line comment there saying why it is long would keep the intent visible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I removed the separate test and made param1's typeJson in testFunctionCRUD over 255 chars with a 300 char metadata comment, plus a one-line comment saying why. The existing get assertion covers the round trip, and the test fails with the varchar(255) error without the DAO change (ai assisted)

depth = 0
for ch in s:
if ch == "<":
if ch in "<(":

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] The description says this also fixes _parse_sql_data_type for MAP<STRING, DECIMAL(38, 18)> (it used to come out as dict[str, decimal(38]). Can you add ("MAP<STRING, DECIMAL(38, 18)>", "dict[str, decimal(38, 18)]") to test_parse_full_sql_data_type_for_return_types so that is locked in?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it to test_parse_full_sql_data_type_for_return_types. With the old <-only depth tracking it fails with dict[str, decimal(38], and it passes now (ai assisted)

…ck in DECIMAL map value parsing

Make param1's type_json in testFunctionCRUD longer than 255 characters with a
long metadata comment instead of keeping a separate test with its own
CreateFunction builder. The existing get assertion checks it round-trips.

Add MAP<STRING, DECIMAL(38, 18)> to the return type parsing test so the
parenthesis-aware split in _split_generic_types stays covered.

Signed-off-by: Maha Rana Yadavalli <[email protected]>
@yili-db

yili-db commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db
yili-db merged commit 4c512b8 into unitycatalog:main Oct 22, 2026
24 of 25 checks passed
yili-db pushed a commit that referenced this pull request Nov 7, 2026
…2045)

## 🥞 Stacked PR
Use this
[link](https://github.com/unitycatalog/unitycatalog/pull/2045/files) to
review incremental changes.
-
[**stack/uc-flyway-schema**](#2045)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2045/files)]
← _this PR_
-
[stack/uc-upgrade-adopt](#2112)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2112/files/dfe03066ca3f748f42b916b6908d7ad23e50b7af..187be0b86367b2fe7cb3db852b33039bb534bbfe)]
-
[stack/uc-upgrade-merge-checks](#2113)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2113/files/b2982d514290d5a7cbb70010c31686d681f732d0..837c49999da9d021a385b5878dd5724f902b8ac0)]
-
[stack/uc-upgrade-retry](#2114)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2114/files/86b2b75709c1378fb7d199dabf453033849885c1..6aed4147e2b76bc45b076c5d1769a85461d9aaaf)]
-
[stack/uc-upgrade-check-schema](#2115)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2115/files/8ba3b07ae080f5d07518392679ddba696074afab..b7a8d07fbeae61d80e3518336ad7290b20cd6770)]
-
[stack/uc-sample-database-built](#2116)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2116/files/6a59493c75da317dfde80776cd29f6ae030eeabf..4221ea5224ceaf8b1122c0b00ba41eeaa6003840)]
-
[stack/uc-flyway-owns-schema](#2117)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2117/files/ccb5e69e8b53596d6f2925797970c9828505edba..b1e7a896aa2e48163e9a750265d99abf69c52371)]
-
[stack/uc-hibernate-fallback](#2118)
[[Files
changed](https://github.com/unitycatalog/unitycatalog/pull/2118/files/861ca93eabac0bee2f40ebd4d0976dfd964929cf..0ed55964bab3e0d505fc330f41cdf00c48ff40b9)]

---------
This PR adds Unity Catalog's database schema as Flyway steps, and a
command that you run by hand to apply them: `bin/start-uc-server
--upgrade-schema`. The command is optional for now. The server still
sets up and updates its schema with Hibernate when it starts.

This PR now only adds the steps and the manual command. The rest of what
this PR held at the last review moved to the next PRs of the stack:
adopting existing databases to #2112, the merge checks and contributor
rules to #2113, the built sample database to #2116, and the start-time
schema check, the Hibernate refusals, the Helm init container and the
step-built test schemas to #2117. "What moved out of this PR" in the
details lists each piece.

### What you see

- The schema is a list of steps for each supported database: H2,
PostgreSQL and MySQL. Step 1 is the schema of release 0.7.0. Step 2
widens the function parameter type column (#2013).
- `bin/start-uc-server --upgrade-schema` applies the steps that are not
applied yet, records each one in the `uc_schema_history` table, and
exits without starting the server. It exits with 0 and prints `The
database schema is at version 2.` on success, and exits with 1 and
prints the reason otherwise.
- It sets up an empty database, also one that holds only other
applications' tables, which it leaves alone. It upgrades a database that
it set up earlier.
- It refuses, and changes nothing, in these cases:
- The database has Unity Catalog's tables but no schema history, for
example one that a server set up at start. The message says that
adopting such a database is not supported yet; #2112 adds it.
  - The database's schema is newer than this release.
- Flyway's check of the schema history fails, for example after a failed
step.
- The configuration uses H2 in server mode, `hibernate.default_schema`
or `hibernate.default_catalog`, an in-memory database, or a database
other than H2, PostgreSQL and MySQL, or a configuration file is missing.
- On PostgreSQL and MySQL, a run lock lets only one command apply steps
at a time. A second command waits for the first.
- The new page `docs/server/upgrades.md` describes the command, backups,
the lock, and the messages.

### What doesn't change yet

- Server start still runs Hibernate's `update`
(`hibernate.hbm2ddl.auto=update` in `etc/conf/hibernate.properties`),
and the Helm chart still sets it. The steps build the same schema that
Hibernate builds from the entities, so on a database that the steps set
up, Hibernate changes nothing.
- The test suite still builds its schemas with Hibernate, and the sample
database `etc/db/h2db.mv.db` is the same as on `main`.
- #2117 makes the steps the only way the schema changes.

### Tests

Ran locally on H2: compiled all modules and their tests with checkstyle,
and ran the schema migration tests, the option parser, Hibernate
configurator and key mapper tests, and the catalog SDK tests (46
passed). The four run-lock tests skip on H2, which takes no run lock;
they ran locally on PostgreSQL 18 and MySQL 8 only at the top of the
stack (#2118). CI runs the full suite on H2, PostgreSQL 18 and MySQL 8.

<details><summary><b>📐 Design notes &amp; details</b></summary>

### Design

- `SchemaMigrator` classifies the database from its `uc_*` tables only:
`EMPTY` (no `uc_*` table), `CURRENT`, `PENDING`, `AHEAD`, or
`UNVERSIONED_UC` (Unity Catalog's tables without history). Other
applications' tables, such as Casbin's, don't count, so the steps run
next to them. On a database with only other tables, Flyway records a
baseline at version 0, below step 1, so that step 1 runs.
- `upgradeSchema()` is a plain Flyway run under the run lock: refuse
`AHEAD` and `UNVERSIONED_UC`, validate the history, migrate, then check
that the database ends `CURRENT` with a valid history. Retrying a run
that stopped part way comes in #2114.
- Every statement of step 1 skips what is already there (for example
`create table if not exists`), so that a later run can run it again
after a run that stopped in the middle. #2114 relies on this.
- The run lock covers the whole run, from classifying the database to
the last step; Flyway's own lock is taken per step. PostgreSQL uses
`pg_advisory_lock` on a fixed key, and MySQL uses `GET_LOCK` on a name
derived from the database name. H2 takes no lock, because one process
opens an H2 file; for the same reason H2 in server mode (`AUTO_SERVER`,
`jdbc:h2:tcp:`, `jdbc:h2:ssl:`) is refused. The lock lives on one
database session, so a pooler in transaction mode (PgBouncer `pool_mode
= transaction`) is not supported for the command. A failed lock release
closes the connection underneath the pooled one, which ends the session
and so releases the lock.
- The migrator opens its own pool of 4 connections (the lock's
connection, Flyway's two on PostgreSQL, and one for reading the schema)
and closes it at the end, so the server's pool size doesn't limit it.
- The database kind comes from the name that its JDBC driver reports,
not from the URL, so wrapping drivers (`jdbc:aws-wrapper:`,
`jdbc:p6spy:`) and pools set up with
`hibernate.hikari.dataSourceClassName` work.
- Metadata lookups pass the configured schema as an exact pattern
(`exactPattern`), since `_` and `%` are wildcards there and `uc_a` would
also match `ucxa`.
- `hibernate.default_schema` and `hibernate.default_catalog` are
refused, also from JVM system properties, because Flyway uses the
connection's schema. Set the schema in the JDBC URL instead. In this PR
only the command refuses them; #2117 adds the same refusal at server
start.
- `HibernateConfigurator` gains only helpers here: `hikariConfig()` (the
pool settings without opening a pool), `requireSchemaFromConnection()`,
and a `setupHibernateProperties()` overload that takes the file path.
- Build: the shaded jar merges Flyway's ServiceLoader file; other
service files are still dropped. The launcher classpath leaves out the
project's class directory, because the jar holds the same steps and
Flyway would find each one twice.
- `BaselineMatchesEntitiesTest` checks that the steps build the schema
that Hibernate builds from the entities. It runs in the normal suite
here; #2113 moves it behind `UC_TEST_MIGRATION_CHECKS=true` with the
other step checks.
- Test plumbing for the migrator tests: `@TempDatabase(empty = true)`,
`TestDatabase.dataSource()`, `newEmptyDatabase`, and H2 file databases.
The normal suite still builds its schema with Hibernate's `update`.
- `deployment.md`: the MySQL collation advice now changes the database
default together with every table, so that tables that later steps
create also get the binary collation.

### Test coverage

- `SchemaMigratorTest`: an empty database, one with only the
authorization rules table, one next to another application's tables, a
wrapping driver, a pool set up by data source class, a versioned
database with a pending step, reading only the configured schema, and
the refusals of a database without history, a newer schema, a failed
step, and H2 server mode. Run-lock tests on PostgreSQL and MySQL: two
runs on an empty database take turns, a refused lock, and a lock that is
not released.
- `SchemaGateTest`: the command sets up the configured database, and
refuses a missing `server.properties` or `hibernate.properties`, an
in-memory database and `hibernate.default_schema`.
- `OptionParserTest`: `--upgrade-schema`.
- Local runs: the runs listed above were on this branch before its last
merge of `main`, which brought in #1902, #2063, #2084, #2085, #2086 and
#2111. CI runs on the merged head.

### What moved out of this PR

Compared with the head at the last review (ae832c1):

- To #2117:
- Running the steps at server start. It is now a start-time check
(`requireCurrentSchema()`) that refuses a database not at this release's
schema; the command applies the steps.
- The Hibernate schema-action refusals in `HibernateConfigurator`
(`requireNoSchemaChanges`, `isSchemaAction`, `isNone`,
`withSchemaUpdatesOff`, the constructor checks, and
`setupHibernateProperties` turning `update` into `none`).
  - `etc/conf/hibernate.properties` without `update`.
- The removal of `hibernate.hbm2ddl.auto=update` from the Helm chart's
`_config.tpl`. This PR reverts ae832c1's last commit, so the chart is as
on `main`.
- Building every test database's schema with the steps:
`TemplateDatabases`, `TestDatabases.h2`/`runSteps`, `MySqlDatabases`,
`TestDatabase` with `hbm2ddl` set to `none`, `KeyMapperTest` with
`@TempDatabase`, and the `BaseAccessControlCRUDTest` comment.
- `HibernateConfiguratorTest.neverLetsHibernateChangeTheSchema` and
`refusesHibernatesOwnDefaultSchema`, and the start-time tests in
`SchemaGateTest`.
- To #2112:
- Adopting a 0.7.0 database as version 1 (`BASELINE_VERSION`,
`baselineFor`). It now adopts only on an exact schema match.
  - `ADOPTED_RELEASE` and `adoptsABaselineDatabase`.
- The real-release tests: `RealUpgradeTest`, `OldServer`, `DataSet`,
`TestServer`, `upgrade-tests.yml`, and the Vert.x test dependency.
  - `SchemaSnapshot`, which moves to the main code.
- To #2116: the migrated `etc/db/h2db.mv.db` and the
`PopulateTestDatabase` call that ran the steps. The sample database is
now built (`SampleDatabase`); this PR keeps `main`'s file.
- To #2113: the schema-change rules in `AGENTS.md`, `CODE_REVIEW.md` and
the AI reviewer's `REVIEW.md`.
- Removed, not moved:
- `BEFORE_BASELINE`, `BASELINE_TABLES`, `missingBaselineTables` and
`refusesADatabaseFromBeforeTheBaselineRelease`. #2112's schema
comparison replaces them; its refusal says that a database from before
0.7.0 must be started on a 0.7.0 server first.
- `NOT_UC` and `refusesADatabaseOfAnotherApplication`.
`setsUpADatabaseNextToAnotherApplicationsTables` replaces them: other
applications' tables are left alone.
- The H2 lock inside the JVM, `acceptsHibernatesNoneActionObject`, and
the schema-versions table in `upgrades.md`.
- Kept in this PR: `exactPattern` and the fix that reads only the
configured schema's tables (a80afaa), the H2 server-mode refusal, the
lock tests, `refusesADatabaseWithAFailedStep`, `migrate()` (now named
`upgradeSchema()`), the pool size (now 4 instead of 3), and step 1
written so that it can run again.

### Stack

Part 1 of 8 of the schema-upgrade stack:

1. #2045 [Server] Add the schema steps and a manual --upgrade-schema
command (this PR)
2. #2112 [Server] Adopt existing databases in --upgrade-schema
3. #2113 [Build] Check the schema steps on every pull request
4. #2114 [Server] Retry a schema upgrade that stopped part way
5. #2115 [Server] Add a read-only --check-schema command
6. #2116 [Build] Build the sample database instead of checking it in
7. #2117 [Server] Let only the schema steps change the schema
8. #2118 [Server] Add a temporary fallback to Hibernate schema updates

</details>

**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

This pull request and its description were written by Isaac.

---------

Signed-off-by: Shubham Bansal <[email protected]>
Co-authored-by: Isaac <[email protected]>
yili-db pushed a commit that referenced this pull request Nov 20, 2026
**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [ ] If there is a related issue, make sure it is linked to this PR.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [ ] If you've added or modified a feature, documentation in `docs` is
updated (not needed, bug fix only)

**Description of changes**

Creating a function with a long parameter type fails with a 500:

```
POST /api/2.1/unity-catalog/functions  (a parameter with a 352 character STRUCT type_text)
500 INTERNAL ... Value too long for column "TYPE_TEXT CHARACTER VARYING(255)"
```

The same happens for a long `full_data_type`, a parameter comment over
255 characters, or a long parameter default. The unitycatalog-ai client
sends each docstring argument description as the parameter comment, so a
function with a detailed docstring can't be registered. Table columns
don't have this problem because `uc_columns` stores `type_text` as a
large text column and `comment` in 65535 characters.

#2013 fixed the same thing for `uc_function_params.type_json`. This PR
widens the remaining columns the same way, with one single-statement
step per column for H2, MySQL and PostgreSQL, each with its own effect
file:

- V5 `uc_function_params.type_text` and V6 `uc_functions.full_data_type`
use the width of `uc_columns.type_text` (16777215, so CLOB, mediumtext
or text)
- V7 `uc_function_params.comment`, V8 `parameter_default` and V9
`uc_schemas.comment` use 65536, `mediumtext` on MySQL. A long schema
comment failed with the same 500 while a table comment of the same
length worked
- V10 `uc_volumes.comment` uses 65536, the volume comment's `maxLength`
in `api/all.yaml`, so every comment the API accepts fits. On MySQL that
is `mediumtext`, which also holds 65536 multi-byte characters, since
MySQL counts `text` in bytes

MySQL counts `text` in bytes, so 65535 there holds fewer characters when
they are multi-byte, while H2 and PostgreSQL count characters. All four
widened comment and default columns are therefore 65536 on H2 and
PostgreSQL and `mediumtext` on MySQL, which holds 65536 multi-byte
characters. Hibernate maps a length above 65535 to `mediumtext` on
MySQL, so the entities use 65536 and `BaselineMatchesEntitiesTest`
agrees on all three databases. The existing table, column and model
comments are still `text` on MySQL, which is a separate change.

Each step only changes a column type. On H2 the steps use the plain
`ALTER COLUMN c <type>` form, which keeps the NOT NULL on `type_text`
(the effect file shows `nullable=NO` before and after), so no step says
NOT NULL on H2 or PostgreSQL. The `comment` columns are quoted because
JSqlParser, which the step rules in #2113 use, reads COMMENT as a
keyword and can't parse the unquoted statement. Catalog, credential and
external location comments are still 255 and can follow in a separate
PR.

**Testing**

`SdkFunctionCRUDTest.testFunctionWithLongTypesAndComments` creates a
function with a long STRUCT parameter type, a long return parameter
type, a long return type, and distinct long parameter comment and
default values, and reads them back. `BaseSchemaCRUDTest` and
`BaseVolumeCRUDTest` now update the comment to a 300 character one and
read it back. `BaseVolumeCRUDTest` and `BaseSchemaCRUDTest` then update
the comment to 65536 `é` characters, over 65535 bytes in UTF-8, and read
it back, and `SdkFunctionCRUDTest` now uses 65536 `é` characters for the
parameter comment and 65536 `ü` characters for the default. With the
volume or schema column left at 65535 the update fails with a 500 on H2.
The MySQL and PostgreSQL runs in CI cover the multi-byte case there.
These fail with the 500 before the fix and pass after it on H2.
`MigrationStepRulesTest`, `BaselineMatchesEntitiesTest` and
`SchemaMigratorTest` pass on H2. I also ran the `MigrationStepRulesTest`
from #2113 against these steps with `UC_TEST_MIGRATION_CHECKS=true`, and
all 11 tests pass on H2, including `eachStepIsOneAllowedStatement` and
`typeChangesWiden`. I wrote the MySQL and PostgreSQL effect files by
hand from the existing ones because I couldn't run Docker locally, so
the upgrade tests in CI check those.

Main is merged in. It added steps V3 and V4, so these steps are now V5
to V10. #2234 also adds V5 to V10, so whichever of the two merges second
gets renumbered above the other.

---------

Signed-off-by: Maha Rana Yadavalli <[email protected]>
Co-authored-by: Maha Rana Yadavalli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] OSS create_python_function drops element types from type_json for list and dict parameters

2 participants