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


##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestMaterializedViews.java:
##########
@@ -0,0 +1,327 @@
+/*
+ * 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.iceberg.spark.extensions;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.Map;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.ParameterizedTestExtension;
+import org.apache.iceberg.Parameters;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.exceptions.RuntimeIOException;
+import org.apache.iceberg.inmemory.InMemoryCatalog;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.io.OutputFile;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.spark.MaterializedViewUtil;
+import org.apache.iceberg.spark.SparkCatalog;
+import org.apache.iceberg.spark.SparkCatalogConfig;
+import org.apache.iceberg.spark.source.SparkMaterializedView;
+import org.apache.iceberg.spark.source.SparkView;
+import org.apache.iceberg.view.RefreshState;
+import org.apache.iceberg.view.RefreshStateParser;
+import org.apache.iceberg.view.SourceTableState;
+import org.apache.iceberg.view.View;
+import org.apache.spark.sql.catalyst.analysis.NoSuchTableException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.connector.catalog.CatalogPlugin;
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.connector.catalog.TableCatalog;
+import org.apache.spark.sql.connector.catalog.ViewCatalog;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(ParameterizedTestExtension.class)
+public class TestMaterializedViews extends ExtensionsTestBase {
+  private static final Namespace NAMESPACE = Namespace.of("default");
+  private final String tableName = "table";
+  private final String materializedViewName = "materialized_view";
+
+  @BeforeEach
+  @Override
+  public void before() {
+    super.before();
+    spark.conf().set("spark.sql.defaultCatalog", catalogName);
+    sql("USE %s", catalogName);
+    sql("CREATE NAMESPACE IF NOT EXISTS %s", NAMESPACE);
+    sql("CREATE TABLE %s (id INT, data STRING)", tableName);
+  }
+
+  @AfterEach
+  public void removeTable() {
+    sql("USE %s", catalogName);
+    sql("DROP VIEW IF EXISTS %s", materializedViewName);
+    sql("DROP TABLE IF EXISTS %s", tableName);
+  }
+
+  @Parameters(name = "catalogName = {0}, implementation = {1}, config = {2}")
+  public static Object[][] parameters() {
+    Map<String, String> properties =
+        
Maps.newHashMap(SparkCatalogConfig.SPARK_WITH_MATERIALIZED_VIEWS.properties());
+    properties.put(CatalogProperties.WAREHOUSE_LOCATION, "file:" + 
getTempWarehouseDir());
+    properties.put(CatalogProperties.CATALOG_IMPL, 
InMemoryCatalogWithLocalFileIO.class.getName());
+    return new Object[][] {
+      {
+        SparkCatalogConfig.SPARK_WITH_MATERIALIZED_VIEWS.catalogName(),
+        SparkCatalogConfig.SPARK_WITH_MATERIALIZED_VIEWS.implementation(),
+        properties
+      }
+    };
+  }
+
+  private static String getTempWarehouseDir() {
+    try {
+      File tempDir = Files.createTempDirectory("warehouse-").toFile();
+      tempDir.deleteOnExit();
+      return tempDir.getAbsolutePath();
+
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  @TestTemplate
+  public void testStorageTableFieldOnViewVersion() {
+    sql("CREATE MATERIALIZED VIEW %s AS SELECT id, data FROM %s", 
materializedViewName, tableName);
+
+    View view = loadIcebergView();
+    // storage-table should be set on the view version, not as a property
+    assertThat(view.currentVersion().storageTable()).isNotNull();

Review Comment:
   executing the following statement 
   
   ```
   sql("SHOW TABLES")
   ```
   
   returns:
   
   - `default.table`
   - `default.materialized_view__storage`
   
   What is the added value of seeing `default.materialized_view__storage` in 
the table listing ?
   For reference the Trino MV  do not store the MV storage table in the 
metastore - see https://github.com/trinodb/trino/pull/18853



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