Repository navigation
[Server] Widen function parameter and return type columns - #2187
Conversation
Function parameter type_text, comment and parameter_default, the function full_data_type, and schema and volume comments were varchar(255), so a long STRUCT type or docstring comment failed with a 500. They now use the widths of the matching table and column fields, with schema step V3 for H2, MySQL and PostgreSQL, the same way as the type_json fix in unitycatalog#2013. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Two items for the whole PR.
Followup, V3 numbering: #2180 and #2181 also add a V3 step on all three databases. Whichever of the three merges second has to be renumbered above the first, because dev/check-migration-steps.sh refuses a new step that is not above the highest merged step. Could we agree the merge order now?
Question, no severity: does ALTER COLUMN type_text CLOB NOT NULL in the H2 V3 file pass the widening rules from #2113 (MigrationStepRulesTest, refusal())? I have not run them, so I cannot tell whether a NOT NULL on an existing NOT NULL column is accepted.
| @@ -0,0 +1,6 @@ | |||
| ALTER TABLE uc_function_params ALTER COLUMN type_text CLOB NOT NULL; | |||
There was a problem hiding this comment.
[AI Assisted] This step sends six statements on each database. The step rules in the stack (#2113 through #2118) hold each step to one statement (MigrationStepRulesTest, eachStepIsOneAllowedStatement), and the per-step recovery in #2114 only works when a step is a single statement: a MySQL step that stopped partway matches neither the schema before it nor the one after, so the run stops instead of recording it. Could we split V3 into one step per column change, each with its own effect file and numbered above the merged steps? The same applies to the MySQL and PostgreSQL files.
There was a problem hiding this comment.
Done. Six single-statement steps, V3 to V8, each with its own effect file. #2113's rules test passes on H2.
| .typeText(LONG_STRUCT_TYPE) | ||
| .typeJson("{\"type\":\"struct\",\"fields\":[]}") | ||
| .comment(LONG_COMMENT) | ||
| .parameterDefault(LONG_COMMENT) |
There was a problem hiding this comment.
[AI Assisted] nit: comment and parameterDefault both use LONG_COMMENT, so swapping the two columns would still pass. Two distinct 300-character values would catch that.
There was a problem hiding this comment.
Done. The comment and parameter default now use two different 300-character values.
| + ">"; | ||
|
|
||
| @Test | ||
| public void testFunctionWithLongTypesAndComments() throws ApiException { |
There was a problem hiding this comment.
[AI Assisted] nit: the test has no return param. Return rows share type_text, so adding one would cover the return path.
There was a problem hiding this comment.
Done. Added a return param with a long type_text and an assertion that it reads back.
|
Thanks a lot for this! The fix makes sense, and following the V2 pattern from #2013 made it easy to review. One thought on ordering, if you're open to it. I have a stack of PRs that adds guardrails for schema steps, starting with #2113 (which checks the steps on every pull request) through #2118. Schema steps are still new in this repo, and a merged step can't be changed later, since databases record that they ran it. So I'd suggest we land those guardrails first and then rebase this PR onto them. That seems safer than merging V3 now and finding out afterwards that it might not fit the rules, when it would be too late to change. For example, the rules in #2113 expect each step to be a single statement, so this V3 would probably become six small steps (V3 to V8). Apart from that it may well be fine as it is. I'm happy to help with the rebase or the split once the stack lands, if that's useful. Does that work for you? |
Each column change is now its own single-statement step, V3 to V8, with its own effect file on H2, MySQL and PostgreSQL. The H2 steps use the plain ALTER COLUMN form, which keeps NOT NULL on type_text, and the comment columns are quoted because JSqlParser reads COMMENT as a keyword. The function test now uses distinct long values for the parameter comment and default, and adds a return parameter with a long type. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
|
A quick follow-up with something more concrete, so you know what to expect. I cherry-picked this PR onto the top of the stack (#2118) and ran its checks on H2, PostgreSQL and MySQL:
So the change itself looks right. It mainly needs splitting into one statement per step, each with its own effect file, for example:
|
|
Thanks @shba24 and @yili-db! The split is pushed in 82d0906: six single-statement steps, V3 to V8, each with its own effect file on all three databases. I'm happy to land after #2113-#2118 and rebase onto them, regenerating the effect files with updateSchemaDumps. #2180 and #2181 can go first, and I'll renumber above them. On NOT NULL: #2113's rules refused ALTER COLUMN type_text CLOB NOT NULL when I ran them, so the H2 step now uses plain ALTER COLUMN, which keeps the existing NOT NULL. If the stack accepts the NOT NULL form, I can put it back. |
…-widths Signed-off-by: Maha Rana Yadavalli <[email protected]> # Conflicts: # server/src/test/java/io/unitycatalog/server/sdk/function/SdkFunctionCRUDTest.java
| @@ -0,0 +1 @@ | |||
| ALTER TABLE uc_volumes MODIFY COLUMN `comment` text NULL; | |||
There was a problem hiding this comment.
Blocker: MySQL TEXT limit is in bytes, so multi-byte volume comments may still be rejected
The MySQL step uses TEXT, which holds 65535 bytes, while the API limit is counted in characters. On a utf8mb4 database a long comment of multi-byte characters can exceed the byte limit and fail even though the API allows it, whereas H2 and PostgreSQL count characters. This could not be settled: the charset of the deployment was not checked (V1 declares none), and the case was not run on MySQL 8.4. The input was already rejected at the base varchar(255), so this is not a regression. The same applies to the schema comment and function parameter comment and default steps, which also use TEXT.
For example: A volume comment of 40,000 'e with acute' characters is 80,000 bytes in utf8mb4. It is under the API limit but over the TEXT limit, so on MySQL it is expected to fail.
If multi-byte comments need to work, use mediumtext for these columns and set the entity length to 16777215 so Hibernate's mapping and BaselineMatchesEntitiesTest agree. This is a wider change than this PR and would also touch the existing table, column and model comments. Otherwise, document the byte limit as a known MySQL difference. Running testMySQL8 with such a comment would confirm the behavior.
Is the TEXT byte limit acceptable here, or should these columns move to mediumtext?
There was a problem hiding this comment.
Fixed in a52eb8b. The volume comment column is now 65536, mediumtext on MySQL, with a test storing 65536 multi-byte characters.
…-widths Signed-off-by: Maha Rana Yadavalli <[email protected]> # Conflicts: # server/src/main/resources/schema-effects/h2/V3.txt # server/src/main/resources/schema-effects/mysql/V3.txt # server/src/main/resources/schema-effects/postgresql/V3.txt
…s, as mediumtext on MySQL Signed-off-by: Maha Rana Yadavalli <[email protected]>
… steps don't break it Signed-off-by: Maha Rana Yadavalli <[email protected]>
| @@ -0,0 +1 @@ | |||
| ALTER TABLE uc_schemas MODIFY COLUMN `comment` text NULL; | |||
There was a problem hiding this comment.
Blocker: Schema comment on MySQL is capped at 65,535 bytes, so long multi-byte comments may be rejected
On MySQL this step maps uc_schemas.comment to text, which holds at most 65,535 bytes, while H2 and PostgreSQL get varchar(65535), which counts characters. The schema API in api/all.yaml sets no maxLength on the comment, and SchemaRepository does not check its length, so a long multi-byte comment can be accepted on H2 and PostgreSQL but fail on MySQL. We could not settle this: the failure was not run against MySQL 8.4 (build/sbt testMySQL8), so it rests on the MySQL storage docs and on the volume change in this PR, which already moved to mediumtext for this reason. The same text mapping is used for uc_function_params.comment (V6) and uc_function_params.parameter_default (V7), so they would behave the same way.
For example: A schema comment of 32,768 'e-acute' characters is 65,536 bytes in UTF-8. It fits varchar(65535) on H2 and PostgreSQL, but exceeds the 65,535-byte text limit on MySQL.
-- mysql/V8__widen_schema_comment.sql
ALTER TABLE uc_schemas MODIFY COLUMN `comment` mediumtext NULL;
// SchemaInfoDAO
@Column(name = "comment", length = 65536)
private String comment;
// then regenerate schema-effects/mysql/V8.txt with build/sbt updateSchemaDumps
References:
- https://dev.mysql.com/doc/refman/8.4/en/storage-requirements.html: "TEXT: L + 2 bytes, where L < 2^16"
How about mapping the schema comment to mediumtext on MySQL, as the volume comment already is, and adding a multi-byte case to confirm it on testMySQL8?
There was a problem hiding this comment.
Good catch, done in a5d469a. The schema comment, function parameter comment and parameter default are now mediumtext on MySQL, like the volume comment, and their entity length is 65536, so H2 and PostgreSQL also get varchar(65536). I couldn't run Docker locally, so I wrote the MySQL effect files by hand. The MySQL 8 test and upgrade jobs in CI pass with them.
| // Update schema comment without updating name and properties | ||
| System.out.println("Testing update schema: changing comment.."); | ||
| UpdateSchema updateSchema2 = new UpdateSchema().comment(TestUtils.SCHEMA_NEW_COMMENT); | ||
| UpdateSchema updateSchema2 = new UpdateSchema().comment(TestUtils.LONG_COMMENT); |
There was a problem hiding this comment.
Nit (not a blocker): Schema and function parameter comment widths are not tested at their limit or with multi-byte text
TestUtils.LONG_COMMENT is 300 ASCII characters, so the schema test passes with any column width of 300 or more and would not notice a byte-based limit. Only the volume test (BaseVolumeCRUDTest) covers 65,536 multi-byte characters. The function parameter comment and default widths in SdkFunctionCRUDTest have the same gap.
For example: A schema comment of 40,000 'e-acute' characters (about 80,000 bytes) would pass every current schema test, whatever limit the MySQL column has.
In the existing BaseSchemaCRUDTest and SdkFunctionCRUDTest, add a boundary case with multi-byte input, like the one at BaseVolumeCRUDTest.java:151, and run it with testMySQL8. This test would also settle the schema comment question on MySQL V8.
Would you be open to adding a multi-byte boundary case to the existing schema and function tests?
There was a problem hiding this comment.
Added in a5d469a. BaseSchemaCRUDTest now stores and reads back 65536 'é' characters. SdkFunctionCRUDTest uses 65536 'é' for the parameter comment and 65536 'ü' for the default, so a swap is caught too. With the schema column left at 65535 the update fails on H2, and the MySQL 8 CI job passes with these tests.
…default to 65536, as mediumtext on MySQL, and test them with multi-byte text Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
|
[AI Assisted] This PR needs a rebase onto main. Main's latest step is now V4 ( #2234 uses the same V4 to V9 numbers. Whichever of the two merges second must renumber above the first, because |
Main added step V4 (credentials stored as text), so this branch's steps move from V4..V9 to V5..V10 on H2, MySQL and PostgreSQL, with their effect files. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
Thanks, done. I merged main and moved the six steps to V5 through V10 on all three databases, with their effect files. Whichever of this and #2234 merges second, I'll renumber that one above the other. |
| private UUID catalogId; | ||
|
|
||
| @Column(name = "comment") | ||
| @Column(name = "comment", length = 65536) |
There was a problem hiding this comment.
Nit (not a blocker): New comment columns use length 65536 while existing widened columns use 65535
The comment columns widened here (schema comment, volume comment, function parameter comment and parameter default) use length = 65536. The earlier widened columns in TableInfoDAO, FunctionInfoDAO, ColumnInfoDAO, RegisteredModelInfoDAO and ModelVersionInfoDAO use 65535. On MySQL the new columns become mediumtext while the older ones are text, and on PostgreSQL they are varchar(65536) against varchar(65535). The 65536 looks intentional, since api/all.yaml sets maxLength 65536 for the volume comment and TestUtils notes the 65535-byte limit of MySQL text. The reason is not written down, though, so the limit now differs between securables and backends.
For example: A 65536-character schema comment fits the new column, but the same-length comment on a table or column is limited by the older 65535 length.
Keep 65536 here, since lowering it would break the volume API limit. Say in the PR description why the new columns use 65536, and consider widening the older 65535 columns in a separate PR.
Could the PR description say why 65536 is used here, so the difference from the older columns is clear to reviewers?
|
/review |
Main added steps V5..V10 (unitycatalog#2187), so this branch's steps move from V5..V10 to V11..V16 on H2, MySQL and PostgreSQL, with their effect files. Signed-off-by: Maha Rana Yadavalli <[email protected]>
**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, the docs don't describe column widths)
**Description of changes**
Creating a catalog whose storage root is longer than 255 characters
fails with a 500:
```
POST /api/2.1/unity-catalog/catalogs {"name": "c", "storage_root": "s3://catalog-bucket/<1000 characters>"}
500 INTERNAL ... Value too long for column "STORAGE_ROOT CHARACTER VARYING(255)"
```
The same happens for a schema storage root, a managed volume whose
catalog or schema location is long enough that
`<location>/volumes/<uuid>` passes 255 characters, an external volume
over 255 characters, and a model version `source` over 255 characters.
Table locations don't have this problem because `uc_tables.url` is
`varchar(2048)`, and staging table locations are 2048 as well.
This PR widens these columns to 2048, the width of `uc_tables.url`, with
one single-statement step per column for H2, MySQL and PostgreSQL, each
with its own effect file, the same way #2187 widens the function
columns:
- V11 `uc_catalogs.storage_root` and V12 `uc_catalogs.storage_location`
- V13 `uc_schemas.storage_root` and V14 `uc_schemas.storage_location`
- V15 `uc_volumes.storage_location`
- V16 `uc_model_versions.source`
The matching DAO fields use one constant,
`Constants.MAX_STORAGE_LOCATION_LENGTH` (2048), which the table url and
staging table location columns now use too. Their width doesn't change.
Each step only changes a column type from `varchar(255)` to
`varchar(2048)`, and all six columns are nullable and have no default,
so the MySQL `MODIFY` restates `NULL` and drops nothing. None of the six
columns is in an index, so no index entry grows.
A new database gets the wider columns from the steps. An existing
database gets them when `bin/start-uc-server --upgrade-schema` runs the
new steps.
The steps are V11 to V16, the next numbers after the V10 step #2187
added, because `SchemaMigratorTest` expects the step versions to have no
gaps. #2260 and #1781 also add a V11, so whichever of these merges
second needs to renumber its steps.
`uc_external_locations.url` is also `varchar(255)`, but it is not
widened here. It has the `idx_url` index on all three databases, and at
2048 characters that index would go over MySQL's 3,072 byte key limit
and PostgreSQL's 2,704 byte index entry limit, which
`MigrationStepRulesTest` refuses. Widening it needs a step that drops or
replaces the index, which the step rules don't allow yet, so it can
follow separately.
**Follow-up**
Location validation against the columns and the cloud limits moved to
its own PR, #2378, which builds on this one. A root that fits its column
can still be too long for the managed locations under it, and that PR
rejects such roots before they are stored.
**Testing**
`SdkManagedLocationTest.testStoragePathsLongerThan255Characters` creates
a 1,020 character catalog root and a 1,219 character schema root and
reads them back. It also creates managed volumes under each, then an
external volume and a model version source of exactly 2,048 characters,
which are read back. On main, each of these fails with a 500.
`SchemaMigratorTest` and `MigrationStepRulesTest` check the new steps on
H2, MySQL and PostgreSQL. `javafmtCheck`, `checkstyle` and
`Test/compile` pass for `server`. The Sdk tests can't start on Windows,
so they run on CI.
---------
Signed-off-by: Maha Rana Yadavalli <[email protected]>
Co-authored-by: Maha Rana Yadavalli <[email protected]>
PR Checklist
docsis updated (not needed, bug fix only)Description of changes
Creating a function with a long parameter type fails with a 500:
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 becauseuc_columnsstorestype_textas a large text column andcommentin 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:uc_function_params.type_textand V6uc_functions.full_data_typeuse the width ofuc_columns.type_text(16777215, so CLOB, mediumtext or text)uc_function_params.comment, V8parameter_defaultand V9uc_schemas.commentuse 65536,mediumtexton MySQL. A long schema comment failed with the same 500 while a table comment of the same length workeduc_volumes.commentuses 65536, the volume comment'smaxLengthinapi/all.yaml, so every comment the API accepts fits. On MySQL that ismediumtext, which also holds 65536 multi-byte characters, since MySQL countstextin bytesMySQL counts
textin 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 andmediumtexton MySQL, which holds 65536 multi-byte characters. Hibernate maps a length above 65535 tomediumtexton MySQL, so the entities use 65536 andBaselineMatchesEntitiesTestagrees on all three databases. The existing table, column and model comments are stilltexton 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 ontype_text(the effect file showsnullable=NObefore and after), so no step says NOT NULL on H2 or PostgreSQL. Thecommentcolumns 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.testFunctionWithLongTypesAndCommentscreates 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.BaseSchemaCRUDTestandBaseVolumeCRUDTestnow update the comment to a 300 character one and read it back.BaseVolumeCRUDTestandBaseSchemaCRUDTestthen update the comment to 65536écharacters, over 65535 bytes in UTF-8, and read it back, andSdkFunctionCRUDTestnow 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,BaselineMatchesEntitiesTestandSchemaMigratorTestpass on H2. I also ran theMigrationStepRulesTestfrom #2113 against these steps withUC_TEST_MIGRATION_CHECKS=true, and all 11 tests pass on H2, includingeachStepIsOneAllowedStatementandtypeChangesWiden. 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.