Skip to content

[Spark] Do not persist Spark schema JSON, credentials, or reserved V2 keys - #1830

Merged
yili-db merged 4 commits into
unitycatalog:mainfrom
s-maling-celonis:fix/strip-spark-datasource-schema-props
Sep 9, 2026
Merged

yili-db merged 4 commits into
unitycatalog:mainfrom
s-maling-celonis:fix/strip-spark-datasource-schema-props

Conversation

@s-maling-celonis

@s-maling-celonis s-maling-celonis commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Spark packages StructType JSON into table properties (spark.sql.sources.schema, spark.sql.sources.schema.part.N, partition/bucket lists, and spark.sql.partitionSchema*) so Hive metastore can reconstruct schema. UC already stores schema on uc_columns, and schema.part.N routinely exceeds uc_properties.property_value (varchar(255)), so CREATE TABLE … USING PARQUET 500s for anything but a tiny schema.
  • One deny-list, UCTableProperties.shouldPersistProperty, is used by UCProxy.createTable and Spark 4.2 createView. It drops reserved V2 keys, vended fs.* credentials, and Spark schema JSON, including the option.-prefixed copies Spark adds from OPTIONS.
  • Load still rebuilds Spark schema from columns. View-only metadata (view.sqlConfig.*, schema mode, query column names) is still written after the filter.
  • Alternative to widening property_value for this Spark path (#1824). User TBLPROPERTIES and REST clients with long values are unchanged.

Test plan

  • UCTablePropertiesTest for schema keys, option. copies, fs.*, reserved V2 keys, and keys that must still persist (user props, view.sqlConfig.*)
  • ParquetExternalTableReadWriteTest.testCreateParquetTableDoesNotPersistSparkDatasourceSchema — seven-column parquet CREATE (the case that overflowed 255 chars), columns persisted, no schema property keys, SELECT * works
  • ExternalTableReadWriteTest.testCreateExternalTableSendsNoCredentialProperties asserts every stored key passes shouldPersistProperty
  • CI spark tests (4.0 / 4.1 / 4.2)

Spark stores StructType JSON in spark.sql.sources.schema.part.N, which is redundant with uc_columns and overflows varchar(255) for typical parquet schemas.

Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
Route createTable and createView through UCTableProperties.shouldPersistProperty so option.-prefixed fs.* and schema JSON keys are stripped the same way as the bare keys.

Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
@s-maling-celonis s-maling-celonis changed the title [Spark] Strip Spark datasource schema properties on CREATE TABLE [Spark] Do not persist Spark schema JSON, credentials, or reserved V2 keys Sep 4, 2026
*/
public static boolean shouldPersistProperty(String key) {
String bare = withoutOptionPrefix(key);
if (V2_TABLE_PROPERTIES.contains(key) || V2_TABLE_PROPERTIES.contains(bare)) {

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.

V2_TABLE_PROPERTIES.contains(key) is dead code because V2_TABLE_PROPERTIES does not contain any key with option. prefix and withoutOptionPrefix returns the input key if it doesn't start with option.

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 catch — contains(key) was redundant once we normalize with withoutOptionPrefix. Dropped it so the V2 check is only V2_TABLE_PROPERTIES.contains(bare).

.noneMatch(key -> key.startsWith("fs."))
.noneMatch(key -> key.startsWith(TableCatalog.OPTION_PREFIX + "fs."))
.noneMatch(UCTableProperties.V2_TABLE_PROPERTIES::contains);
assertThat(serverProperties.keySet()).allMatch(UCTableProperties::shouldPersistProperty);

@yili-db yili-db Sep 7, 2026 •

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.

This test becomes circular: it calls the same function that does the real work in test.
The original check is better. You can add extra checks on keys that would otherwise appear in the serverProperties: spark.sql.partitionSchema.something etc.

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.

Agreed — asserting shouldPersistProperty here was circular. Restored the original fs.* / option.fs.* / reserved V2 checks, and added explicit prefix matchers for spark.sql.sources.schema* and spark.sql.partitionSchema* (including option. copies) so this IT does not go through the persist filter.

Map<String, String> serverProperties =
tableInfo.getProperties() == null ? Map.of() : tableInfo.getProperties();
assertThat(serverProperties.keySet())
.noneMatch(UCTableProperties::isSparkDatasourceSchemaProperty);

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.

ditto.

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.

Same here: this test now asserts those schema keys with literal prefixes instead of isSparkDatasourceSchemaProperty.

@yili-db
yili-db merged commit 8ffaa49 into unitycatalog:main Sep 9, 2026
14 checks passed
s-maling-celonis added a commit to s-maling-celonis/unitycatalog that referenced this pull request Sep 17, 2026
Fold the varchar(255) round-trip into the view suite using a user
property, and drop the parquet schema.part.N table test that Spark
no longer persists after unitycatalog#1830.

Co-authored-by: Cursor <[email protected]>

Signed-off-by: s-maling-celonis <[email protected]>
yili-db pushed a commit that referenced this pull request Sep 21, 2026
## Summary
- Hibernate maps an unannotated `String` as `varchar(255)`. Any
`uc_properties.property_value` longer than that fails with `ERROR: value
too long for type character varying(255)` on `PropertyDAO` insert.
- [#1830](#1830)
stopped Spark from persisting Hive-style schema JSON
(`spark.sql.sources.schema.part.N`) on `createTable` / `createView`.
That does **not** cover every long value: Spark still forwards
`view.sqlConfig.*` and other user `TBLPROPERTIES`. Those still hit
`varchar(255)`.
- Map `property_value` with the same `length = 16777215` used for
`ColumnInfoDAO.typeJson`.
- **Existing deployments are not updated by this change.** The server
uses `hibernate.hbm2ddl.auto=update`, which creates missing
tables/columns but does **not** change the type or length of a column
that already exists. Upgrading the server JAR alone leaves
`varchar(255)` in place. Operators must `ALTER`
`uc_properties.property_value` (statements in
`docs/server/deployment.md`).

## Example that fails today

Delta `CREATE TABLE` with a wide schema succeeds: table schema is stored
on `uc_columns` (`type_json`), not as a table property.

`CREATE VIEW` then calls `TablesApi.createTable` with Spark view
properties (including `view.sqlConfig.*` and user `TBLPROPERTIES`). A
value longer than 255 characters 500s the insert even though the view
SQL itself is stored on `uc_tables.view_definition` (already a wide
column).

```text
io.unitycatalog.client.ApiException: createTable call failed with: 500
{"error_code":"INTERNAL","message":"Error creating table: cat.sch.activity_union: could not execute statement [ERROR: value too long for type character varying(255)] [/* insert for io.unitycatalog.server.persist.dao.PropertyDAO */ insert into uc_properties (entity_id,entity_type,property_key,property_value,id) values (?,?,?,?,?)]"}
```

The same 255-char limit still applies to any REST client that sends a
long table/view property.

## Test plan
- [ ] `SdkViewCRUDTest` /
`BaseViewCRUDTest.testCreateViewAcceptsPropertyValueLongerThanDefaultVarchar`
persists a user property longer than 255 characters
- [ ] Confirm a **new** database gets the wider column from Hibernate
- [ ] Confirm an **existing** database still has `varchar(255)` until
the documented `ALTER` is run, then `CREATE VIEW` with a long property
succeeds

---------

Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
newfront pushed a commit to newfront/unitycatalog that referenced this pull request Sep 24, 2026
…ycatalog#1824)

## Summary
- Hibernate maps an unannotated `String` as `varchar(255)`. Any
`uc_properties.property_value` longer than that fails with `ERROR: value
too long for type character varying(255)` on `PropertyDAO` insert.
- [unitycatalog#1830](unitycatalog#1830)
stopped Spark from persisting Hive-style schema JSON
(`spark.sql.sources.schema.part.N`) on `createTable` / `createView`.
That does **not** cover every long value: Spark still forwards
`view.sqlConfig.*` and other user `TBLPROPERTIES`. Those still hit
`varchar(255)`.
- Map `property_value` with the same `length = 16777215` used for
`ColumnInfoDAO.typeJson`.
- **Existing deployments are not updated by this change.** The server
uses `hibernate.hbm2ddl.auto=update`, which creates missing
tables/columns but does **not** change the type or length of a column
that already exists. Upgrading the server JAR alone leaves
`varchar(255)` in place. Operators must `ALTER`
`uc_properties.property_value` (statements in
`docs/server/deployment.md`).

## Example that fails today

Delta `CREATE TABLE` with a wide schema succeeds: table schema is stored
on `uc_columns` (`type_json`), not as a table property.

`CREATE VIEW` then calls `TablesApi.createTable` with Spark view
properties (including `view.sqlConfig.*` and user `TBLPROPERTIES`). A
value longer than 255 characters 500s the insert even though the view
SQL itself is stored on `uc_tables.view_definition` (already a wide
column).

```text
io.unitycatalog.client.ApiException: createTable call failed with: 500
{"error_code":"INTERNAL","message":"Error creating table: cat.sch.activity_union: could not execute statement [ERROR: value too long for type character varying(255)] [/* insert for io.unitycatalog.server.persist.dao.PropertyDAO */ insert into uc_properties (entity_id,entity_type,property_key,property_value,id) values (?,?,?,?,?)]"}
```

The same 255-char limit still applies to any REST client that sends a
long table/view property.

## Test plan
- [ ] `SdkViewCRUDTest` /
`BaseViewCRUDTest.testCreateViewAcceptsPropertyValueLongerThanDefaultVarchar`
persists a user property longer than 255 characters
- [ ] Confirm a **new** database gets the wider column from Hibernate
- [ ] Confirm an **existing** database still has `varchar(255)` until
the documented `ALTER` is run, then `CREATE VIEW` with a long property
succeeds

---------

Signed-off-by: s-maling-celonis <[email protected]>
Co-authored-by: Cursor <[email protected]>
yili-db pushed a commit that referenced this pull request Dec 1, 2026
…#2324)

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

A non-Delta table loses a data source option whose name is also a
reserved table property. For example, `CREATE TABLE t (s STRING, i INT)
USING CSV OPTIONS (comment '#') LOCATION '...'` stores no comment
option. So for a file holding "# exported by tool", "x,1" and "y,2",
`SELECT * FROM t` returns three rows starting with `["# exported by
tool", null]` instead of the two rows that `spark.read.option("comment",
"#")` gives. Spark hands each option to the catalog as `option.<key>`,
and `UCTableProperties.shouldPersistProperty` removed that prefix before
checking the reserved keys, so `option.comment` matched the table
comment key and was never sent to the server.

#1830, shipped in 0.7.0, stopped storing it. Earlier releases stored it,
but the reader never saw it until #2228 started stripping the `option.`
prefix on load, so tables created by 0.6.0 already have the option
stored and read correctly on `main`. In SQL only `comment` reaches the
catalog this way, and also `table_type` on Spark 4.0, where it isn't
reserved. The parser rejects the other reserved names in OPTIONS, or
drops them when `spark.sql.legacy.notReserveProperties` is set. A
TBLPROPERTIES key such as `option.owner` was dropped the same way.

The check now compares the reserved keys with the key as Spark passes
it. So the bare reserved keys are still dropped, and an `option.` key
with the same name is stored like any other option. Vended `fs.*`
credentials and Spark schema JSON are still dropped with or without the
prefix. `UCProxy.createTable` and the Spark 4.2 and later `createView`
path both use this method. Tables created by 0.7.0 have no stored
comment option. To fix an external one, drop it and create it again with
the same LOCATION and the same `OPTIONS (comment ...)` clause. An
`option.` key set through TBLPROPERTIES with one of these names is now
stored, and on a non-Delta table it's used as a reader option, as other
`option.` keys already are. A managed Delta table shows a kept
`option.comment` as `option.option.comment` through
`DeltaTableV2.properties`, the same route every other stored option key
already takes.

Spark also passes each option without the prefix, and a COMMENT clause
replaces that copy, so `OPTIONS (comment '#')` on its own made "#" the
table comment. For non-Delta tables, `createTable` now ignores a table
comment equal to `option.comment`, using the same
`UCTableProperties.isBareCopyOfOption` rule the load path uses to drop
the bare copy of each option. It has the same trade-off. Spark passes
the same properties for `COMMENT '#' OPTIONS (comment '#')` as for the
option alone, so that explicit description is dropped too and the table
has no comment. Delta tables keep the comment they are given.

**Tests**

`UCTablePropertiesTest` checks each of the eight reserved names in both
forms. `UCProxySuite.testCsvCommentOptionSkipsCommentLines` runs a
SparkSession against a mocked UC store and reads a CSV file through a
table with `OPTIONS (comment '#')` through a second table that also has
`COMMENT 'Exported rows'`, and through a third with `COMMENT '#'` equal
to the option. It checks that all three skip the comment line, that the
first and third have no table comment, and that the second keeps its
comment. The full `UCProxySuite` passes on Spark 4.0.0 locally (35 of
35). The test fake now stores what `createTable` sent, so a CSV table
round-trips with its format, comment and options.
`UCProxySuite.testCreateTableCommentEqualToCommentOption` checks that a
CSV table drops a comment equal to the option, that an external and a
managed Delta table keep it, and that each stores `option.comment` and
no bare `comment` property.
`UCViewProxySuite.testCreateViewKeepsOptionKeyNamedLikeReservedKey`
checks that `createView` stores `option.comment` and keeps the view
comment as the comment field.

On `main` the new tests fail. Putting back the old prefix-stripped
check, removing the reserved-key check, checking `fs.` without the
prefix, removing the comment rule, or dropping its non-Delta condition
each makes a test fail. Putting back the prefix-stripped reserved-key
check also fails the new stored-property and view assertions. On Windows
with JDK 17 at the current head, `UCTablePropertiesTest` and the
`createTable` tests in `UCProxySuite` pass on Spark 4.1,
`UCViewProxySuite` passes on 4.2 (37 of 37), and `spark/javafmtCheckAll`
and checkstyle pass. The `UCProxySuite` tests that write files through
Hadoop, including `testCsvCommentOptionSkipsCommentLines`, need Hadoop's
native Windows library, which this machine lacks, so they run in CI. The
server-backed suites run in CI too.

---------

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