Skip to content

[Server] Keep function properties after create - #2233

Merged
yili-db merged 7 commits into
unitycatalog:mainfrom
maharanay22:fix-function-properties-persisted
Nov 15, 2026
Merged

yili-db merged 7 commits into
unitycatalog:mainfrom
maharanay22:fix-function-properties-persisted

Conversation

@maharanay22

@maharanay22 maharanay22 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

  • 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.
  • 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

A function's properties are only echoed in the create response and never stored. A get or list right after the create returns no properties at all:

POST /api/2.1/unity-catalog/functions   "properties": "{\"owner_team\":\"ml\",\"tier\":\"gold\"}"
  -> 200, "properties": "{\"owner_team\":\"ml\",\"tier\":\"gold\"}"
GET  /api/2.1/unity-catalog/functions/cat.sch.fn
  -> 200, no "properties"

FunctionRepository.createFunction put the request string on the response and wrote no uc_properties rows, while get and list read those rows through RepositoryUtils.attachProperties. That helper had a special case for functions that would have returned Map.toString() ({owner_team=ml, tier=gold}), which is not JSON, if any rows had existed. deleteFunction also never removed property rows.

The spec documents CreateFunction.properties and FunctionInfo.properties as a JSON-serialized key-value map encoded as a string, and the unitycatalog-ai client reads them back that way (_function_properties decodes the string with json.loads). This PR makes the server keep them:

  • Create parses properties as a single JSON object with unique keys and stores one uc_properties row per key, in the same transaction as the function. An absent field, an empty or whitespace-only string, JSON null (what the unitycatalog-ai client sends by default) or {} means no properties.
  • A value that is not a string is stored as its compact JSON text, so {"attempts":3,"enabled":true} is stored and read back as {"attempts":"3","enabled":"true"}. Numbers are parsed as exact decimals, so 0.1234567890123456789 and 1.50 keep every digit. A number written with an exponent is stored in normalized form, so 1e400 is stored as 1E+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.
  • A key longer than 255 characters is rejected with 400 INVALID_ARGUMENT, since that is the size of uc_properties.property_key and the insert would otherwise fail with a 500. Characters are counted as code points, the way PostgreSQL and MySQL count varchar(255), so a key of 255 emoji is stored there. H2 counts UTF-16 units and rejects that key with 400.
  • A key or value containing the NUL character is rejected with 400, since PostgreSQL text cannot store it.
  • If the database rejects a property row, for example two keys that MySQL's default case-insensitive collation treats as the same, such as Tier and tier, the create fails with 400 and nothing is stored.
  • The returned string is normalized. Create, get and list all return the stored properties as compact JSON with the keys sorted, so the three agree, and {} or null come back as no properties. List loads the properties of the whole page in one query, the way table listing does.
  • Deleting a function deletes its property rows. A schema or catalog force delete goes through the same method, so it cleans them up too.
  • The function-only String branch in RepositoryUtils.attachProperties is removed, since functions no longer use it.

Breaking change

These properties values returned 200 on main, which never stored the properties, and now fail with 400 INVALID_ARGUMENT:

  • "Function properties must be a single JSON object with unique keys." for an object with duplicate keys, an object followed by trailing text, text that is not JSON, and a top-level value that is not an object (an array, a bare string or a number). None of these maps to one set of key-value pairs.
  • "Function property keys cannot be longer than 255 characters." for a key longer than 255 code points.
  • "Function property keys and values cannot contain the NUL character (\u0000)." for a NUL in a key or value.
  • "Function properties contain a number whose exponent is out of range." for a number like 1e9999999999.
  • "Function properties are too large: ..." for JSON over Jackson's default stream limits: a number longer than 1000 digits, a string longer than 20,000,000 characters, or nesting deeper than 1000 levels. The message names the limits, which are read from the parser's StreamReadConstraints.
  • "Function property keys must be unique, and the database treats two of these keys as the same key." for two keys the database's collation treats as equal, such as Tier and tier under MySQL's default case-insensitive collation.
  • "The database cannot store a key or value of these function properties." for a row the database rejects otherwise, such as a key of 255 emoji on H2, which counts UTF-16 units.

PropertyDAO.MAX_KEY_LENGTH only names the existing varchar(255) size of property_key on all three databases, so there is no DDL change and no migration step. There is no spec change. The CLI's function create doesn't send properties, and the Java and Python clients pass the string through unchanged.

Testing

New tests in SdkFunctionCRUDTest:

  • testFunctionPropertiesRoundTrip creates functions with unsorted properties containing whitespace, a value holding escaped JSON, number, boolean, null and nested values, a 255-character key, no properties, JSON null, {}, an empty string and a whitespace-only string, decimals that a double cannot hold exactly and a 1e400 exponent, and checks the create, get and list responses against literal expected strings.
  • testFunctionPropertiesRoundTrip also stores a 1000-digit number and 1000 levels of nesting, the largest values Jackson's limits allow.
  • testInvalidFunctionPropertiesRejected checks 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 400 INVALID_ARGUMENT and the expected message, and leave no function or property rows behind.
  • testListPagesKeepEachFunctionsProperties lists four functions with and without properties one per page and checks each function's properties.
  • testDuplicateCreateKeepsTheExistingProperties creates a function, then tries to create it again with different properties, and checks the 400 RESOURCE_ALREADY_EXISTS and that the first function's properties and the property row count are unchanged.
  • testDeletingFunctionRemovesItsProperties counts the uc_properties rows of a function before and after a function delete, a schema force delete and a catalog force delete.
  • testPropertyKeyLengthCountsCharacters stores a key of 255 emoji on PostgreSQL and MySQL and expects 400 on H2.
  • testPropertyKeysTheDatabaseTreatsAsEqualRejected stores Tier and tier as two keys on H2 and PostgreSQL. On MySQL it switches property_key to the server default utf8mb4_0900_ai_ci (the test databases use utf8mb4_0900_bin) and expects 400 with nothing stored.

On Linux, build/sbt "server/test" passed on H2, PostgreSQL 18 and MySQL 8 with UC_TEST_MIGRATION_CHECKS=true for the first two commits. The later commits run on all three through this PR's CI matrix. For the latest commit, SdkFunctionCRUDTest passes 8 of 8 on H2 locally. For the third commit, SdkFunctionCRUDTest, the function access control test, the catalog and schema CRUD tests and BaselineMatchesEntitiesTest pass on H2. With server/src/main reset to main and the new tests kept, SdkFunctionCRUDTest fails 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 storing asText() for non-string values makes the nested value come back empty.

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]>
@yili-db

yili-db commented Nov 13, 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] 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]>
@maharanay22

Copy link
Copy Markdown
Contributor Author

@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.

@yili-db

yili-db commented Nov 14, 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, 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) {

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] 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.

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 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 =

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] 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.

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 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());

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 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.

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.

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) {

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] 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.

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, 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]>
@maharanay22

Copy link
Copy Markdown
Contributor Author

@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.

@yili-db

yili-db commented Nov 15, 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] 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]>
@maharanay22

Copy link
Copy Markdown
Contributor Author

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.

@yili-db

yili-db commented Nov 15, 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] 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"

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] 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();

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] 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.

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 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.

@yili-db
yili-db merged commit 235e2ef into unitycatalog:main Nov 15, 2026
24 checks passed
yili-db pushed a commit that referenced this pull request Nov 20, 2026
#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]>
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.

2 participants