Skip to content

[Spark] Keep data-source options named like reserved table properties - #2324

Merged
yili-db merged 5 commits into
unitycatalog:mainfrom
maharanay22:fix-spark-csv-comment-option
Dec 1, 2026
Merged

yili-db merged 5 commits into
unitycatalog:mainfrom
maharanay22:fix-spark-csv-comment-option

Conversation

@maharanay22

@maharanay22 maharanay22 commented Nov 20, 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

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.

shouldPersistProperty stripped the option. prefix before checking the
reserved V2 keys, so OPTIONS (comment '#') on a CSV table was sent as
option.comment, matched the reserved comment key and was dropped. Every
read then returned the comment lines as data rows. unitycatalog#1830, shipped in
0.7.0, stopped storing it. Earlier releases stored it, but the reader
never saw it until unitycatalog#2228 started stripping the option. prefix on load.
In SQL only comment reaches the catalog this way (and table_type on
Spark 4.0, where it is not reserved), since the parser rejects the other
reserved names in OPTIONS. A TBLPROPERTIES key such as option.owner was
dropped the same way.

Check the reserved keys against the key as given. Only the bare
reserved keys are dropped now. fs.* credentials and Spark schema JSON
are still dropped in both forms.

Spark also passes each option without the prefix, so OPTIONS
(comment '#') alone made "#" the table comment. For non-Delta tables,
createTable now ignores a comment equal to option.comment, the same rule
the load path uses for bare option copies.

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

yili-db commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

/review

…nt-option

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

# Conflicts:
#	connectors/spark/src/test/java/io/unitycatalog/spark/UCProxySuite.java
@yili-db

yili-db commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db

yili-db commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

@timothyw553 this changes how data-source options named like reserved table properties are stored and shown, so could you review it first? I will take another look after you approve.

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

overall LGTM, nothing production-level blocking. i left two small comments on clarifying the equal-value trade-off and the direct UCProxy test scope.

val dataSourceFormat = convertDatasourceFormat(format)
// Spark also passes each OPTIONS entry without the `option.` prefix, so OPTIONS (comment '#')
// arrives as the table comment unless a COMMENT clause replaced it. For non-Delta tables,
// which split options from properties the same way on load, a comment equal to the option is

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.

nit: the comment presents equal values as proof it's a copy, whereas spark passes the exact same properties for COMMENT '#' OPTIONS (comment '#') and we drop that description too. could we clarify the comment and add that explicit equal-value case to testCsvCommentOptionSkipsCommentLines?

-    // which split options from properties the same way on load, a comment equal to the option is
-    // that copy.
+    // equal values are treated as the option's bare copy. Spark provides the same properties
+    // for an explicit COMMENT with the same value, so that description is also dropped.

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 17dd516. I used your wording for the comment, and the CSV test now has a third table with COMMENT '#' OPTIONS (comment '#') that reads two rows and has no description.

…oo, and cover it in the CSV test

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

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The equal-value comment is addressed in 17dd516. I don't see your second comment on the UCProxy test scope, maybe it wasn't submitted. Could you post it?

@yili-db

yili-db commented Nov 26, 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] Approve. The fix compares the reserved keys as Spark passes them, keeps the option. copies, and the CSV and comment-equality tests fail without it.

The PR needs a rebase: it conflicts with main.

Non-blocking follow-ups:

  • The bare-copy rule now lives in two places: tablePropertiesWithoutOptions on load and the inline filter in createTable. A shared helper would keep them in step.
  • Test coverage: no case for the createView path (it now persists option. keys), no assertion on the stored properties, and no managed Delta case.
  • The description's re-create step for 0.7.0 external tables should also say to repeat the OPTIONS (comment ...) clause.
  • Managed Delta tables now expose the kept option.<reserved> keys as option.option.<key> through DeltaTableV2.properties, the same route existing option keys take.

…nt-option

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

# Conflicts:
#	connectors/spark/src/test/java/io/unitycatalog/spark/UCProxySuite.java
@yili-db

yili-db commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

/review

@maharanay22

Copy link
Copy Markdown
Contributor Author

Thanks. Merged main (06c1403) and did the follow-ups in e819861: a shared isBareCopyOfOption helper, a createView test, stored-property assertions, a managed Delta case, and the OPTIONS step in the description.

@yili-db
yili-db merged commit 50d7ebf into unitycatalog:main Dec 1, 2026
19 checks passed
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.

3 participants