osscm commented on code in PR #9830:
URL: https://github.com/apache/iceberg/pull/9830#discussion_r4211799963


##########
spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateMaterializedViewExec.scala:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.execution.datasources.v2
+
+import org.apache.iceberg.catalog.Namespace
+import org.apache.iceberg.catalog.TableIdentifier
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap
+import org.apache.iceberg.spark.MaterializedViewUtil
+import org.apache.iceberg.spark.Spark3Util
+import org.apache.iceberg.spark.SparkCatalog
+import org.apache.iceberg.spark.SparkSchemaUtil
+import org.apache.iceberg.spark.source.SparkView
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException
+import org.apache.spark.sql.catalyst.expressions.Attribute
+import org.apache.spark.sql.connector.catalog.Identifier
+import org.apache.spark.sql.connector.catalog.View
+import org.apache.spark.sql.connector.catalog.ViewCatalog
+import org.apache.spark.sql.connector.expressions.Transform
+import org.apache.spark.sql.types.StructType
+import scala.collection.JavaConverters._
+
+case class CreateMaterializedViewExec(
+    catalog: ViewCatalog,
+    ident: Identifier,
+    queryText: String,
+    viewSchema: StructType,
+    columnAliases: Seq[String],
+    columnComments: Seq[Option[String]],
+    queryColumnNames: Seq[String],
+    comment: Option[String],
+    properties: Map[String, String],
+    allowExisting: Boolean,
+    replace: Boolean,
+    storageTableIdentifier: Option[String])
+    extends LeafV2CommandExec {
+
+  override def output: Seq[Attribute] = Nil
+
+  override protected def run(): Seq[InternalRow] = {
+
+    // Check if storageTableIdentifier is provided. If not, generate a default 
identifier.
+    val sparkStorageTableIdentifier = storageTableIdentifier match {
+      case Some(identifier) => {
+        val catalogAndIdentifier = Spark3Util.catalogAndIdentifier(session, 
identifier)
+        val storageTableCatalogName = catalogAndIdentifier.catalog().name()
+        Preconditions.checkState(
+          storageTableCatalogName.equals(catalog.name()),
+          "Storage table identifier must be in the same catalog as the view." +
+            " Found storage table in catalog: %s, expected: %s.",
+          Array[Object](storageTableCatalogName, catalog.name()))
+        catalogAndIdentifier.identifier()
+      }
+      case None => 
MaterializedViewUtil.getDefaultMaterializedViewStorageTableIdentifier(ident)
+    }
+
+    // Step 1: Create the storage table BEFORE the MV view metadata.
+    // Per spec: "The storage table must exist and be accessible before the
+    // materialized view metadata is committed."
+    // A newly created MV has a storage table with no snapshots until a 
refresh is performed.
+    catalog

Review Comment:
   Thanks - OR REPLACE is now rejected up front (and covered by 
testCreateOrReplaceIsRejected), so seems to be that half is resolved. 
   
   Is storage table created unconditionally and outside the try, before the 
exists check?



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