aokolnychyi commented on code in PR #56606:
URL: https://github.com/apache/spark/pull/56606#discussion_r3444569233
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/MetadataTable.java:
##########
@@ -81,12 +82,14 @@ public Map<String, String> properties() {
@Override
public Transform[] partitioning() {
- return info.partitions();
+ // Partitioning is a table-only concept; a view wrapped as a MetadataTable
has none.
+ return info instanceof TableInfo tableInfo ? tableInfo.partitions() : new
Transform[0];
}
@Override
public Constraint[] constraints() {
- return info.constraints();
+ // Constraints are a table-only concept; a view wrapped as a MetadataTable
has none.
+ return info instanceof TableInfo tableInfo ? tableInfo.constraints() : new
Constraint[0];
Review Comment:
I feel like `MetadataTable` serves multiple purposes at once, which makes it
confusing / harder to reason. Specifically, it can be used as a delegating v1
table and as a view.
= Option 1 =
We can add `Relation` as a parent for `Table` and `View`.
```
sealed interface Relation permits Table, View {}
interface View extends Relation {
ViewInfo info();
}
interface RelationCatalog extends TableCatalog, ViewCatalog {
Relation loadRelation(Identifier ident) throws NoSuchTableException;
}
DelegatingTable (replaces MetadataTable for the table side)
class DelegatingTable implements Table {
DelegatingTable(TableInfo info, String name) { ... }
}
switch (catalog.loadRelation(ident)) {
case View v -> // resolve as persistent view using v.info()
case Table t -> // resolve as table
}
```
= Option 2 =
If option 1 feels like over engineering, why not simply add `ViewAsTable`
and `DelegatingTable` as two separate classes and keep the rest of
`TableViewCatalog` logic as is? Calling it `MetadataTable` is very generic and
hard to understand.
--
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]