You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "dbtsai (via GitHub)" <gi...@apache.org> on 2026/04/16 18:58:59 UTC
[PR] [SPARK-56514][SQL] Allow catalog Table objects to be passed directly to read.table() and writeTo() [spark]
dbtsai opened a new pull request, #55375:
URL: https://github.com/apache/spark/pull/55375
### What changes were proposed in this pull request?
Adds `Table.qualifiedName` and two new overloads so that `Table` objects returned by `spark.catalog.getTable()` / `spark.catalog.listTables()` can be passed directly to `spark.read.table()` and `df.writeTo()`, removing the need to manually reconstruct a qualified name string.
**New API (`@since 4.2.0`):**
- `Table.qualifiedName: String` — returns the fully qualified, backtick-quoted identifier (e.g. `` `spark_catalog`.`default`.`my_table` ``)
- `DataFrameReader.table(table: Table): DataFrame`
- `Dataset.writeTo(table: Table): DataFrameWriterV2[T]`
All three are also available in PySpark (classic and Connect) as `Table.qualifiedName`, `DataFrameReader.table(table)`, and `DataFrame.writeTo(table)`.
### Why are the changes needed?
A common pattern is filtering `listTables()` results and then loading or writing each table:
```scala
// before
val tables = spark.catalog.listTables("mydb").collect().filter(!_.isTemporary)
tables.foreach { t =>
val name = Seq(t.catalog, t.namespace.mkString("."), t.name).mkString(".")
spark.read.table(name).writeTo(name).append()
}
// after
val tables = spark.catalog.listTables("mydb").collect().filter(!_.isTemporary)
tables.foreach { t =>
spark.read.table(t).writeTo(t).append()
}
```
The catalog API already gives you a fully-described `Table` object; requiring callers to disassemble and re-join it as a string is unnecessary friction.
### Does this PR introduce _any_ user-facing change?
Yes. Three new API methods are added in Scala and Python, all marked `@since 4.2.0` / `versionadded:: 4.2.0`. No existing behavior is changed.
### How was this patch tested?
- **`sql/api` (Scala):** `Table.qualifiedName` unit tests covering full qualification, missing catalog/namespace, multi-part namespace, special characters, and embedded backticks.
- **Classic Scala:** `CatalogSuite` integration test for `read.table(Table)` (session catalog) and `writeTo(Table)` (V2 catalog); `DataFrameWriterV2Suite` end-to-end tests for both overloads.
- **Connect Scala:** `connect/CatalogSuite` integration test covering `read.table(Table)` and `writeTo(Table)`.
- **PySpark / Connect Python:** `test_table_qualified_name` (6 cases) and `test_read_table_and_write_to_accept_table_object` in `CatalogTestsMixin`, which runs against both `CatalogTests` (classic) and `CatalogParityTests` (Connect).
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Sonnet 4.6 (claude.ai/code)
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [WIP][SPARK-56514][SQL] Allow catalog Table objects to be passed directly to read.table() and writeTo() [spark]
Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #55375:
URL: https://github.com/apache/spark/pull/55375#discussion_r3096424061
##########
python/pyspark/sql/catalog.py:
##########
@@ -57,6 +57,36 @@ def database(self) -> Optional[str]:
else:
return None
+ @property
+ def qualifiedName(self) -> str:
Review Comment:
This uses `quote` implemented in python so it has a potential risk to be inconsistent with Scala QuotingUtils.quoteIdentifier. If possible, maybe we can have a test to make sure they have consistent behavior so we won't break it.
##########
python/pyspark/sql/catalog.py:
##########
@@ -57,6 +57,36 @@ def database(self) -> Optional[str]:
else:
return None
+ @property
+ def qualifiedName(self) -> str:
Review Comment:
Or shall we call JVM's implementation?
##########
python/pyspark/sql/classic/dataframe.py:
##########
@@ -1910,7 +1910,11 @@ def where(self, condition: Union[Column, str]) -> ParentDataFrame:
groupby = groupBy
drop_duplicates = dropDuplicates
- def writeTo(self, table: str) -> "DataFrameWriterV2":
+ def writeTo(self, table: Union[str, "Table"]) -> "DataFrameWriterV2":
+ from pyspark.sql.catalog import Table
+
+ if isinstance(table, Table):
+ table = table.qualifiedName
return DataFrameWriterV2(self, table)
def mergeInto(self, table: str, condition: Column) -> "MergeIntoWriter":
Review Comment:
Do we consider to support `Table` object generally for all APIs here? E.g., `mergeInto` still only accepts table as `str`.
##########
python/pyspark/sql/classic/dataframe.py:
##########
@@ -1910,7 +1910,11 @@ def where(self, condition: Union[Column, str]) -> ParentDataFrame:
groupby = groupBy
drop_duplicates = dropDuplicates
- def writeTo(self, table: str) -> "DataFrameWriterV2":
+ def writeTo(self, table: Union[str, "Table"]) -> "DataFrameWriterV2":
Review Comment:
Shall we add `versionchanged` description too?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [WIP][SPARK-56514][SQL] Allow catalog Table objects to be passed directly to read.table() and writeTo() [spark]
Posted by "lakechd (via GitHub)" <gi...@apache.org>.
lakechd commented on code in PR #55375:
URL: https://github.com/apache/spark/pull/55375#discussion_r3096122087
##########
python/pyspark/sql/connect/readwriter.py:
##########
@@ -149,7 +150,11 @@ def _df(self, plan: LogicalPlan) -> "DataFrame":
return DataFrame(plan, self._client)
- def table(self, tableName: str) -> "DataFrame":
+ def table(self, tableName: Union[str, "Table"]) -> "DataFrame":
+ from pyspark.sql.catalog import Table
+
+ if isinstance(tableName, Table):
Review Comment:
what is the estimated size for catalog table? will it impact performance?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [WIP][SPARK-56514][SQL] Allow catalog Table objects to be passed directly to read.table() and writeTo() [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #55375: [WIP][SPARK-56514][SQL] Allow catalog Table objects to be passed directly to read.table() and writeTo()
URL: https://github.com/apache/spark/pull/55375
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [WIP][SPARK-56514][SQL] Allow catalog Table objects to be passed directly to read.table() and writeTo() [spark]
Posted by "dbtsai (via GitHub)" <gi...@apache.org>.
dbtsai commented on code in PR #55375:
URL: https://github.com/apache/spark/pull/55375#discussion_r3098088185
##########
python/pyspark/sql/catalog.py:
##########
@@ -57,6 +57,36 @@ def database(self) -> Optional[str]:
else:
return None
+ @property
+ def qualifiedName(self) -> str:
Review Comment:
Since we will use this code in spark connect which is purely python. so calling from JVM is not ideal.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [WIP][SPARK-56514][SQL] Allow catalog Table objects to be passed directly to read.table() and writeTo() [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #55375:
URL: https://github.com/apache/spark/pull/55375#issuecomment-5086231914
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org