szehon-ho commented on code in PR #51419:
URL: https://github.com/apache/spark/pull/51419#discussion_r2246309408


##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/MetadataOnlyTable.java:
##########
@@ -0,0 +1,231 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.connector.catalog;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.spark.annotation.Evolving;
+import org.apache.spark.sql.connector.expressions.Transform;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * A concrete {@code Table} implementation that only contains the table 
metadata without
+ * implementing read/write directly. It represents a general Spark data source 
table or
+ * a Spark view, and relies on Spark to interpret the table metadata, resolve 
the table
+ * provider into a data source, or read it as a view.
+ *
+ * @since 4.1.0
+ */
+@Evolving
+public class MetadataOnlyTable implements Table {
+  private final Builder builder;
+
+  private MetadataOnlyTable(Builder builder) {
+    this.builder = builder;
+  }
+
+  public static class Builder {
+    private final Column[] columns;
+    private String name = "data_source_table_or_view";
+    private String provider = null;
+    private String location = null;
+    private String tableType = null;
+    private String owner = null;
+    private String comment = null;
+    private String collation = null;
+    private String viewText = null;
+    private String createVersion = "";
+    private long createTime = 0;
+    private Map<String, String> tableProps = Map.ofEntries();
+    private Map<String, String> serdeProps = Map.ofEntries();
+    private Transform[] partitioning = new Transform[0];
+
+    public Builder(Column[] columns) {
+      assert columns != null;
+      this.columns = columns;
+    }
+
+    public Builder(StructType schema) {
+      assert schema != null;
+      this.columns = CatalogV2Util.structTypeToV2Columns(schema);
+    }
+
+    public Builder withName(String name) {
+      this.name = name;
+      return this;
+    }
+
+    public Builder withProvider(String provider) {
+      this.provider = provider;
+      return this;
+    }
+
+    public Builder withLocation(String location) {
+      this.location = location;
+      return this;
+    }
+
+    public Builder withTableType(String tableType) {
+      this.tableType = tableType;
+      return this;
+    }
+
+    public Builder withOwner(String owner) {
+      this.owner = owner;
+      return this;
+    }
+
+    public Builder withComment(String comment) {
+      this.comment = comment;
+      return this;
+    }
+
+    public Builder withCollation(String collation) {
+      this.collation = collation;
+      return this;
+    }
+
+    public Builder withViewText(String viewText) {
+      this.viewText = viewText;
+      this.tableType = TableSummary.VIEW_TABLE_TYPE;
+      return this;
+    }
+
+    public Builder withCreateVersion(String createVersion) {
+      this.createVersion = createVersion;
+      return this;
+    }
+
+    public Builder withCreateTime(long createTime) {
+      this.createTime = createTime;
+      return this;
+    }
+
+    public Builder withTableProps(Map<String, String> tableProps) {
+      this.tableProps = tableProps;
+      return this;
+    }
+
+    public Builder withSerdeProps(Map<String, String> serdeProps) {

Review Comment:
   Just an opinion, serde is quite bound to HMS (?) and the newer DSV2 dont 
have that, will it make sense to abstract this (maybe something like 
'storageProperties')?  This is just for HMS table support?



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1Table.scala:
##########
@@ -109,6 +109,45 @@ private[sql] object V1Table {
       case _ => None
     }
   }
+
+  def toCatalogTable(
+      catalog: CatalogPlugin,
+      ident: Identifier,
+      t: MetadataOnlyTable): CatalogTable = {
+    val tableType = t.getTableType() match {
+      case TableSummary.VIEW_TABLE_TYPE => CatalogTableType.VIEW
+      case TableSummary.MANAGED_TABLE_TYPE => CatalogTableType.MANAGED
+      case _ => CatalogTableType.EXTERNAL
+    }
+    val viewText = Option(t.getViewText())
+    val tableProps = t.getTableProps().asScala.toMap
+    val (partCols, bucketSpec, clusterBySpec) = 
t.partitioning().toSeq.convertTransforms
+    CatalogTable(
+      identifier = TableIdentifier(
+        table = ident.name(),
+        database = Some(ident.namespace().lastOption.getOrElse("root")),
+        catalog = Some(catalog.name())),
+      tableType = tableType,
+      storage = CatalogStorageFormat.empty.copy(

Review Comment:
   curious, do we not need to set inputFormat/outputFormat?  



-- 
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