Repository navigation
[Spark] Keep data-source options named like reserved table properties - #2324
Conversation
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]>
|
/review |
…nt-option Signed-off-by: Maha Rana Yadavalli <[email protected]> # Conflicts: # connectors/spark/src/test/java/io/unitycatalog/spark/UCProxySuite.java
|
/review |
|
@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
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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]>
|
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? |
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[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:
tablePropertiesWithoutOptionson load and the inline filter increateTable. A shared helper would keep them in step. - Test coverage: no case for the
createViewpath (it now persistsoption.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 asoption.option.<key>throughDeltaTableV2.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
…lta tables Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
PR Checklist
docsis updatedDescription 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 treturns three rows starting with["# exported by tool", null]instead of the two rows thatspark.read.option("comment", "#")gives. Spark hands each option to the catalog asoption.<key>, andUCTableProperties.shouldPersistPropertyremoved that prefix before checking the reserved keys, sooption.commentmatched 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 onmain. In SQL onlycommentreaches the catalog this way, and alsotable_typeon Spark 4.0, where it isn't reserved. The parser rejects the other reserved names in OPTIONS, or drops them whenspark.sql.legacy.notReservePropertiesis set. A TBLPROPERTIES key such asoption.ownerwas 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. Vendedfs.*credentials and Spark schema JSON are still dropped with or without the prefix.UCProxy.createTableand the Spark 4.2 and latercreateViewpath 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 sameOPTIONS (comment ...)clause. Anoption.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 otheroption.keys already are. A managed Delta table shows a keptoption.commentasoption.option.commentthroughDeltaTableV2.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,createTablenow ignores a table comment equal tooption.comment, using the sameUCTableProperties.isBareCopyOfOptionrule the load path uses to drop the bare copy of each option. It has the same trade-off. Spark passes the same properties forCOMMENT '#' 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
UCTablePropertiesTestchecks each of the eight reserved names in both forms.UCProxySuite.testCsvCommentOptionSkipsCommentLinesruns a SparkSession against a mocked UC store and reads a CSV file through a table withOPTIONS (comment '#')through a second table that also hasCOMMENT 'Exported rows', and through a third withCOMMENT '#'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 fullUCProxySuitepasses on Spark 4.0.0 locally (35 of 35). The test fake now stores whatcreateTablesent, so a CSV table round-trips with its format, comment and options.UCProxySuite.testCreateTableCommentEqualToCommentOptionchecks that a CSV table drops a comment equal to the option, that an external and a managed Delta table keep it, and that each storesoption.commentand no barecommentproperty.UCViewProxySuite.testCreateViewKeepsOptionKeyNamedLikeReservedKeychecks thatcreateViewstoresoption.commentand keeps the view comment as the comment field.On
mainthe new tests fail. Putting back the old prefix-stripped check, removing the reserved-key check, checkingfs.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,UCTablePropertiesTestand thecreateTabletests inUCProxySuitepass on Spark 4.1,UCViewProxySuitepasses on 4.2 (37 of 37), andspark/javafmtCheckAlland checkstyle pass. TheUCProxySuitetests that write files through Hadoop, includingtestCsvCommentOptionSkipsCommentLines, need Hadoop's native Windows library, which this machine lacks, so they run in CI. The server-backed suites run in CI too.