spark-test commented on code in PR #60576:
URL: https://github.com/apache/spark/pull/60576#discussion_r4594153632


##########
python/pyspark/sql/tests/test_readwriter.py:
##########
@@ -420,6 +420,25 @@ def test_table_overwrite(self):
         with self.assertRaisesRegex(AnalysisException, 
"TABLE_OR_VIEW_NOT_FOUND"):
             df.writeTo("test_table").overwrite(lit(True))
 
+    def test_write_modes_with_options_and_properties(self):

Review Comment:
   **Non-blocking (P2):** As written, the test's checks fail only if `create()` 
breaks, the table property is dropped, or a mode is mapped to one that raises a 
different error. They cannot catch the regressions this test is meant to cover:
   
   - `replace()` and `createOrReplace()`: for a session-catalog target, 
`CreateTableHelper.lowerReplaceTableAsSelect` rejects REPLACE TABLE AS SELECT 
because parquet is not a v2 provider. It never reads `orCreate` or checks 
whether `test_table` exists, so both calls raise the same 
`UNSUPPORTED_FEATURE.TABLE_OPERATION`.
   - `append()` and `overwritePartitions()`: `ResolveRelations` raises the same 
`Cannot write into v1 table` for every V2 write whose target is a v1 table.
   - `option("compression", "snappy")`: the option only reaches the v1 table's 
storage properties, which `SHOW TBLPROPERTIES` does not list, and snappy is 
already the default parquet codec.
   
   So if `WriteOperationV2.command`, the server's `transformWriteOperationV2`, 
or the classic pass-throughs in `readwriter.py` swapped `replace()` with 
`createOrReplace()` or `append()` with `overwritePartitions()`, or stopped 
forwarding `option()` values, this test would still pass in both 
`ReadwriterV2Tests` and `ReadwriterV2ParityTests`. No other test would catch it 
either: no other Python test runs these modes or checks a V2 write option, and 
the Connect server and Scala end-to-end tests never run `replace()` or 
`createOrReplace()` and run `append()` and `overwritePartitions()` only against 
empty tables. Users would then see, for example, `overwritePartitions()` 
appending rows instead of replacing them.
   
   To make the checks distinguishing in both suites, run the paired modes 
against an in-memory v2 catalog (set `spark.sql.catalog.testcat` to 
`org.apache.spark.sql.connector.catalog.InMemoryCatalog` with `sql_conf`, as 
`test_metadata_column` in `test_dataframe.py` does), and set a non-default 
option such as `compression` = `gzip` and check that it appears in the `SHOW 
CREATE TABLE` output of the parquet table.
   
   **Verification:**
   - **Regression:** replace() on a missing v2 table fails while 
createOrReplace() creates it, so mapping either method to the other makes the 
test fail in the run that uses that mapping: the classic run for the classic 
Python methods, and the Spark Connect run for the Connect client and the 
server's replay of the write.
   - **Regression:** append() and overwritePartitions() against a v2 table that 
already holds rows leave different row counts, so mapping either method to the 
other makes the test fail in the run that uses that mapping: the classic run 
for the classic Python methods, and the Spark Connect run for the Connect 
client and the server's replay of the write.
   - **Regression:** An option set to a value other than its default is 
observed on the created table, so a change that stops forwarding option() 
values makes the test fail in the run that uses that path: the classic run for 
the classic Python option(), and the Spark Connect run for the Connect client 
and the server.
   - **Behavior:** With the mappings intact, the extended test passes in both 
runs, including the existing rejection checks on the parquet session-catalog 
table, and it drops every table it creates.



##########
python/pyspark/sql/tests/test_readwriter.py:
##########
@@ -420,6 +420,25 @@ def test_table_overwrite(self):
         with self.assertRaisesRegex(AnalysisException, 
"TABLE_OR_VIEW_NOT_FOUND"):
             df.writeTo("test_table").overwrite(lit(True))
 
+    def test_write_modes_with_options_and_properties(self):
+        df = self.spark.range(3)
+        with self.table("test_table"):
+            writer = 
df.writeTo("test_table").using("parquet").option("compression", "snappy")
+            writer.tableProperty("prop", "value").create()
+            self.assertEqual(3, self.spark.table("test_table").count())
+            props = self.spark.sql("SHOW TBLPROPERTIES test_table").collect()
+            self.assertIn(("prop", "value"), [tuple(r) for r in props])
+
+            # The session catalog only has v1 tables, which reject the other 
V2 write modes.

Review Comment:
   **Nit (P3):** This comment gives the wrong reason for the rejections. The 
session catalog can hold v2 tables: `V2SessionCatalog.loadTable` returns one 
for a non-file v2 provider, and `test_table` is v1 only because parquet is a 
file source. `replace()` and `createOrReplace()` are also not rejected because 
of the existing v1 table: `lowerReplaceTableAsSelect` rejects REPLACE TABLE AS 
SELECT because the requested parquet provider is not a v2 provider, so 
`createOrReplace()` fails the same way when no table exists. Only `append()` 
and `overwritePartitions()` fail because `test_table` is a v1 table. With the 
current wording, a reader cannot see why the two replace checks cannot tell 
those modes apart, or where to look if file sources later become v2 providers.
   
   ```suggestion
               # parquet is not a v2 provider, so replace() and 
createOrReplace() fail even
               # without test_table; append() and overwritePartitions() fail 
because test_table is v1.
   ```
   
   **Verification:**
   - **Inspection:** The comment above the rejection checks names the parquet 
provider as the reason REPLACE TABLE AS SELECT is rejected and the v1 target as 
the reason the two V2 writes are rejected, and makes no claim that the session 
catalog holds only v1 tables.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to