Repository navigation
[Server] Keep function properties after create - #2233
Conversation
Create stored nothing for a function's properties, so get and list returned none, and deleting a function left no rows behind only because none were written. Parse the JSON object of string values on create, store it in uc_properties, return it as JSON on create, get and list, and delete the rows with the function. Reject any other value with INVALID_ARGUMENT instead of dropping it. Signed-off-by: Maha Rana Yadavalli <[email protected]>
…rties Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] The fix stores function properties as uc_properties rows in the create transaction, returns them on get and list, and removes them on delete. The tests check the stored rows, which is the right test.
Two changes are needed before merge: a key over 255 characters should return INVALID_ARGUMENT instead of a 500 (inline), and the create path should keep accepting the inputs main accepted (inline). The PR description should list the four inputs that still fail as a breaking change with the reason.
Not in this diff: the properties descriptions in api/all.yaml (lines 2270 and 2345) should stay close to the public contract, "JSON-serialized key-value pair map, encoded (escaped) as a string." The server-specific behavior belongs in the PR description, which should state that the returned string is normalized: keys sorted, compact JSON, and {} or null returned as no properties.
… keys Treat an empty or whitespace-only properties string as no properties, store non-string values as their JSON text, and reject keys longer than uc_properties.property_key with INVALID_ARGUMENT instead of a 500. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
@yili-db, thanks for the review. This PR does not change api/all.yaml, and both properties descriptions still have the public wording. The description now covers the normalized output, non-string values read back as text, and the breaking change. |
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Thanks, the points on keys, blank and non-string values, the message and the helper are addressed in bad3bab. One blocker remains (NUL characters, inline). Please also correct the description for numbers (inline) and confirm the MySQL collation (inline).
Follow-up: keys over 255 characters on the catalog, schema and table paths still return a 500 today. A cross-linked issue would keep that from being forgotten.
The description says tests passed on H2, PostgreSQL and MySQL for earlier commits. The latest commit ran on H2, so PostgreSQL and MySQL are not yet exercised for it.
| } | ||
| Map<String, String> parsed = new HashMap<>(); | ||
| for (Map.Entry<String, JsonNode> field : node.properties()) { | ||
| if (field.getKey().length() > PropertyDAO.MAX_KEY_LENGTH) { |
There was a problem hiding this comment.
[AI Assisted] A key or value containing a NUL character passes parsing, and the insert then fails on PostgreSQL because text columns cannot store NUL. The error is not mapped, so the request returns a 500 and no function is created. On main the same request returned 200. Could parseProperties reject NUL characters in keys and values with INVALID_ARGUMENT, and could a test cover one? The tests for this commit ran on H2 only, so PostgreSQL does not exercise this path.
There was a problem hiding this comment.
Done in fa70707. A NUL character in a key or value now returns 400 INVALID_ARGUMENT, with a test for each.
| private final SessionFactory sessionFactory; | ||
| private static final PagedListingHelper<FunctionInfoDAO> LISTING_HELPER = | ||
| new PagedListingHelper<>(FunctionInfoDAO.class); | ||
| private static final ObjectReader STRICT_JSON_READER = |
There was a problem hiding this comment.
[AI Assisted] Numbers are not stored as their exact JSON text. The reader parses floats as doubles, so {"amount":0.1234567890123456789} is stored as "0.12345678901234568", and {"big":1e400} is stored as "Infinity", which is not JSON. The description says non-string values are stored as their JSON text. Could the reader use DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS? With it, the first value is kept exactly and the second is stored as 1E+400. A round-trip case would cover both.
There was a problem hiding this comment.
Done. The reader keeps exact decimals, so 0.1234567890123456789 is stored as written and 1e400 as 1E+400. Both are in the round trip test, and I fixed the description.
| + " characters."); | ||
| } | ||
| JsonNode value = field.getValue(); | ||
| parsed.put(field.getKey(), value.isTextual() ? value.textValue() : value.toString()); |
There was a problem hiding this comment.
[AI Assisted] The duplicate-key check compares Java strings, but the unique constraint on uc_properties uses the database collation. The MySQL baseline sets no collation, so the server default applies, which is case-insensitive in MySQL 8. {"Tier":"a","tier":"b"} would pass this check and then fail at flush with a 500. Could the check match the database's equality, or could the violation map to INVALID_ARGUMENT? I have not confirmed the collation on a live MySQL, so please check the test database.
There was a problem hiding this comment.
The test databases use utf8mb4_0900_bin, so they compare exactly. A rejected property row now returns 400 with nothing stored. The MySQL test switches the column to utf8mb4_0900_ai_ci and covers Tier and tier.
| } | ||
| Map<String, String> parsed = new HashMap<>(); | ||
| for (Map.Entry<String, JsonNode> field : node.properties()) { | ||
| if (field.getKey().length() > PropertyDAO.MAX_KEY_LENGTH) { |
There was a problem hiding this comment.
[AI Assisted] nit: String.length() counts UTF-16 units, so a key of 128 emoji (256 units) is rejected, although varchar(255) counts characters and the key fits. codePointCount would match the column.
There was a problem hiding this comment.
Done, keys are counted with codePointCount. 255 emoji are stored on PostgreSQL and MySQL. H2 counts UTF-16 units, so it returns 400 there.
…se cannot store Parse JSON numbers in function properties as exact decimals, reject NUL characters in keys and values, count key length in characters, and return 400 when the database rejects a property row, such as keys its collation treats as equal. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
@yili-db, thanks. The latest commit now runs on H2, PostgreSQL 18 and MySQL 8 in this PR's CI. I'll open a separate PR for the long keys on catalogs, schemas and tables. |
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] The breaking-change section still says four kinds of value. Several more inputs that main accepted now return 400 and are not listed: a key or value containing NUL, a key longer than 255 code points, an exponent out of range, a number longer than 1000 digits or nesting deeper than 1000 (Jackson's default stream limits), and two keys the database treats as equal. Could the list be updated?
Test gaps: there is no paged list test with functions that have mixed properties, and no test that a duplicate-name create leaves the existing function's properties and row count unchanged.
Optional: the property_key column is still varchar(255) on all three databases, the same as before. MAX_KEY_LENGTH only names that existing length, so it changes no DDL and needs no migration step.
…ties-persisted Signed-off-by: Maha Rana Yadavalli <[email protected]> # Conflicts: # server/src/main/java/io/unitycatalog/server/persist/utils/RepositoryUtils.java
…ng and duplicate-create tests Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
Thanks. The breaking-change list now covers every new 400 with its message, and both test gaps are added: a paged list with mixed properties, and a duplicate create that leaves the first function's properties and row count unchanged. MAX_KEY_LENGTH only names the existing varchar(255), so there is no DDL change or migration. |
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Approving. The breaking-change list, the stream-limit message, the flush comment, and the test coverage for paging and duplicate creates are addressed, and the database mapping stays local as explained in the Javadoc.
Follow-ups:
- The NUL message in the breaking list reads
(\^@), but the code says(\u0000). Please copy the exact text. - Malformed properties are now checked before the schema lookup and the duplicate check. A missing schema returns 400 instead of 404, and a duplicate create returns 400 instead of 409. Is that intended? A line in the description would help.
| throw new BaseException( | ||
| ErrorCode.INVALID_ARGUMENT, | ||
| String.format( | ||
| "Function properties are too large: numbers can have at most %d digits, strings at" |
There was a problem hiding this comment.
[AI Assisted] nit: a key longer than Jackson's 50,000-character name limit also raises StreamConstraintsException, and this message does not describe that limit. Could the message say a key name is too long for that case, or could the name limit be added to the list?
| session.persist(dao); | ||
| // Write the function and its parameters first, so only property rows reach | ||
| // flushProperties and its mapping of database errors to property errors. | ||
| session.flush(); |
There was a problem hiding this comment.
[AI Assisted] nit: when there are no properties, both flushes and the empty persist still run. Guarding them with if (!properties.isEmpty()) would keep the common path unchanged.
There was a problem hiding this comment.
Done in 70b05ed. The flush, the property persists and flushProperties now run only when properties is not empty, so creating a function without properties works as before.
#2319) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] 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 **Description of changes** Transferring ownership of a function that has properties fails with a 500. For example, after creating `main.default.fn` with `properties` set to `{"team":"ml"}`, `PATCH /api/2.1/unity-catalog/functions/main.default.fn` with `{"owner": "[email protected]"}` returns `INTERNAL` "Failed to update function: java.lang.NoSuchMethodException: io.unitycatalog.server.model.FunctionInfo.setProperties(java.util.Map)". The transaction rolls back, so the owner and the OWNER grant stay with the previous owner, and the function can't be transferred while it has properties. Functions without properties are not affected. The function update added in #2149 builds its response with `RepositoryUtils.attachProperties`. That helper looks up a `setProperties(Map)` method by reflection, but `FunctionInfo.properties` is a JSON string. #2149 was written while `attachProperties` still had a special case for functions, and #2233 removed that special case after function properties moved to their own JSON rendering and nothing else called it for functions. The two PRs merged in the opposite order, so on `main` every transfer of a function stored with properties hits the `Map` lookup and fails. The fix renders the update response's properties the same way `getFunction` and `listFunctions` do, so a transfer returns the same properties JSON as a later get. The stored properties are not touched by the update. The other callers of `attachProperties` pass catalogs, schemas and tables, whose properties are maps, so they are unaffected. **Tests** `OwnershipRepositoryTest.functionTransferKeepsProperties` transfers a function stored with properties. It checks that the new owner is saved and holds the only OWNER grant, that `getFunction` still returns the original properties, and that the update response returns the same properties. It fails on `main` with the `NoSuchMethodException` above, and it also fails if the update response drops the properties. `build/sbt "server/testOnly io.unitycatalog.server.persist.OwnershipRepositoryTest"` passes on H2 on Windows with JDK 17, and so do `server/javafmtCheckAll` and the checkstyle tasks. The change has no SQL of its own, so MySQL and PostgreSQL run in 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
A function's
propertiesare only echoed in the create response and never stored. A get or list right after the create returns no properties at all:FunctionRepository.createFunctionput the request string on the response and wrote nouc_propertiesrows, while get and list read those rows throughRepositoryUtils.attachProperties. That helper had a special case for functions that would have returnedMap.toString()({owner_team=ml, tier=gold}), which is not JSON, if any rows had existed.deleteFunctionalso never removed property rows.The spec documents
CreateFunction.propertiesandFunctionInfo.propertiesas a JSON-serialized key-value map encoded as a string, and the unitycatalog-ai client reads them back that way (_function_propertiesdecodes the string withjson.loads). This PR makes the server keep them:propertiesas a single JSON object with unique keys and stores oneuc_propertiesrow per key, in the same transaction as the function. An absent field, an empty or whitespace-only string, JSONnull(what the unitycatalog-ai client sends by default) or{}means no properties.{"attempts":3,"enabled":true}is stored and read back as{"attempts":"3","enabled":"true"}. Numbers are parsed as exact decimals, so0.1234567890123456789and1.50keep every digit. A number written with an exponent is stored in normalized form, so1e400is stored as1E+400, and an exponent too large to parse is rejected with 400. The read-back returns the string"3"where the client sent the number 3. A nested value comes back as its compact JSON text inside a string.INVALID_ARGUMENT, since that is the size ofuc_properties.property_keyand the insert would otherwise fail with a 500. Characters are counted as code points, the way PostgreSQL and MySQL countvarchar(255), so a key of 255 emoji is stored there. H2 counts UTF-16 units and rejects that key with 400.Tierandtier, the create fails with 400 and nothing is stored.{}ornullcome back as no properties. List loads the properties of the whole page in one query, the way table listing does.Stringbranch inRepositoryUtils.attachPropertiesis removed, since functions no longer use it.Breaking change
These
propertiesvalues returned 200 on main, which never stored the properties, and now fail with 400INVALID_ARGUMENT:1e9999999999.StreamReadConstraints.Tierandtierunder MySQL's default case-insensitive collation.PropertyDAO.MAX_KEY_LENGTHonly names the existingvarchar(255)size ofproperty_keyon all three databases, so there is no DDL change and no migration step. There is no spec change. The CLI'sfunction createdoesn't send properties, and the Java and Python clients pass the string through unchanged.Testing
New tests in
SdkFunctionCRUDTest:testFunctionPropertiesRoundTripcreates functions with unsorted properties containing whitespace, a value holding escaped JSON, number, boolean, null and nested values, a 255-character key, no properties, JSONnull,{}, an empty string and a whitespace-only string, decimals that a double cannot hold exactly and a1e400exponent, and checks the create, get and list responses against literal expected strings.testFunctionPropertiesRoundTripalso stores a 1000-digit number and 1000 levels of nesting, the largest values Jackson's limits allow.testInvalidFunctionPropertiesRejectedchecks that seven malformed values, a key of 256 characters or 256 emoji, a NUL character in a key or a value, an exponent too large to parse, a 1001-digit number and 1001 levels of nesting each fail with 400INVALID_ARGUMENTand the expected message, and leave no function or property rows behind.testListPagesKeepEachFunctionsPropertieslists four functions with and without properties one per page and checks each function's properties.testDuplicateCreateKeepsTheExistingPropertiescreates a function, then tries to create it again with different properties, and checks the 400RESOURCE_ALREADY_EXISTSand that the first function's properties and the property row count are unchanged.testDeletingFunctionRemovesItsPropertiescounts theuc_propertiesrows of a function before and after a function delete, a schema force delete and a catalog force delete.testPropertyKeyLengthCountsCharactersstores a key of 255 emoji on PostgreSQL and MySQL and expects 400 on H2.testPropertyKeysTheDatabaseTreatsAsEqualRejectedstoresTierandtieras two keys on H2 and PostgreSQL. On MySQL it switchesproperty_keyto the server defaultutf8mb4_0900_ai_ci(the test databases useutf8mb4_0900_bin) and expects 400 with nothing stored.On Linux,
build/sbt "server/test"passed on H2, PostgreSQL 18 and MySQL 8 withUC_TEST_MIGRATION_CHECKS=truefor the first two commits. The later commits run on all three through this PR's CI matrix. For the latest commit,SdkFunctionCRUDTestpasses 8 of 8 on H2 locally. For the third commit,SdkFunctionCRUDTest, the function access control test, the catalog and schema CRUD tests andBaselineMatchesEntitiesTestpass on H2. Withserver/src/mainreset to main and the new tests kept,SdkFunctionCRUDTestfails 3 of 4: the round trip test gets the raw request string back from create, the invalid input test gets a 200, and the delete test finds no stored rows. Separately, removing the key length check makes the 256-character key return a 500, treating a blank string as JSON makes the round trip test get a 400, and storingasText()for non-string values makes the nested value come back empty.