vladislav-sidorovich commented on code in PR #15407:
URL: https://github.com/apache/iceberg/pull/15407#discussion_r3450928683


##########
delta-lake/src/test/java/org/apache/iceberg/delta/TestBaseSnapshotDeltaLakeKernelTableAction.java:
##########
@@ -0,0 +1,383 @@
+/*
+ * 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.delta;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import io.delta.kernel.Operation;
+import io.delta.kernel.Table;
+import io.delta.kernel.Transaction;
+import io.delta.kernel.TransactionBuilder;
+import io.delta.kernel.defaults.engine.DefaultEngine;
+import io.delta.kernel.engine.Engine;
+import io.delta.kernel.types.IntegerType;
+import io.delta.kernel.types.StringType;
+import io.delta.kernel.types.StructType;
+import io.delta.kernel.utils.CloseableIterable;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.BaseTable;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.catalog.Catalog;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.hadoop.HadoopCatalog;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.util.ContentFileUtil;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class TestBaseSnapshotDeltaLakeKernelTableAction {
+  private static final String DELTA_GOLDEN_TABLES_ROOT = "delta/golden/";
+
+  @TempDir private File sourceDeltaFolder;
+  @TempDir private File icebergWarehouseFolder;
+  private String sourceTableLocation;
+  private final Configuration testHadoopConf = new Configuration();
+  private String newTableLocation;
+  private Catalog testCatalog;
+
+  @BeforeEach
+  public void before() throws IOException {
+    sourceTableLocation = sourceDeltaFolder.toURI().toString();
+
+    Path icebergTablePath = 
icebergWarehouseFolder.toPath().resolve("iceberg_table");
+    newTableLocation = icebergTablePath.toString();
+    Files.createDirectories(icebergTablePath);
+
+    Map<String, String> properties = Maps.newHashMap();
+    properties.put(CatalogProperties.WAREHOUSE_LOCATION, 
icebergWarehouseFolder.toString());
+
+    HadoopCatalog icebergCatalog = new HadoopCatalog();
+    icebergCatalog.setConf(new Configuration());
+    icebergCatalog.initialize("hadoop_catalog", properties);
+    testCatalog = icebergCatalog;
+  }
+
+  @Test
+  public void testRequiredTableIdentifier() {
+    SnapshotDeltaLakeTable testAction =
+        new BaseSnapshotDeltaLakeKernelTableAction(sourceTableLocation)
+            .icebergCatalog(testCatalog)
+            .deltaLakeConfiguration(testHadoopConf)
+            .tableLocation(newTableLocation);
+    assertThatThrownBy(testAction::execute)
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage(
+            "Iceberg catalog and identifier cannot be null. Make sure to 
configure the action with a valid Iceberg catalog and identifier.");
+  }
+
+  @Test
+  public void testRequiredIcebergCatalog() {
+    SnapshotDeltaLakeTable testAction =
+        new BaseSnapshotDeltaLakeKernelTableAction(sourceTableLocation)
+            .as(TableIdentifier.of("test", "test"))
+            .deltaLakeConfiguration(testHadoopConf)
+            .tableLocation(newTableLocation);
+    assertThatThrownBy(testAction::execute)
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage(
+            "Iceberg catalog and identifier cannot be null. Make sure to 
configure the action with a valid Iceberg catalog and identifier.");
+  }
+
+  @Test
+  public void testRequiredDeltaLakeConfiguration() {
+    SnapshotDeltaLakeTable testAction =
+        new BaseSnapshotDeltaLakeKernelTableAction(sourceTableLocation)
+            .as(TableIdentifier.of("test", "test"))
+            .icebergCatalog(testCatalog)
+            .tableLocation(newTableLocation);
+    assertThatThrownBy(testAction::execute)
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Make sure to configure the action with a valid 
deltaLakeConfiguration");
+  }
+
+  @Test
+  public void testDeltaTableColumnMappingFeatureDisabled() throws Exception {
+    Engine engine = DefaultEngine.create(testHadoopConf);
+    Transaction txn =
+        createEmptyDeltaTableTransaction(engine)
+            .withTableProperties(engine, Map.of("delta.columnMapping.mode", 
"name"))
+            .build(engine);
+    txn.commit(engine, CloseableIterable.emptyIterable());
+
+    SnapshotDeltaLakeTable testAction =
+        new BaseSnapshotDeltaLakeKernelTableAction(sourceTableLocation)
+            .as(TableIdentifier.of("iceberg_table"))
+            .deltaLakeConfiguration(testHadoopConf)
+            .icebergCatalog(testCatalog)
+            .tableLocation(newTableLocation);
+
+    // Act & check
+    assertThatThrownBy(testAction::execute)
+        .isInstanceOf(UnsupportedOperationException.class)
+        .hasMessage("Conversion of Delta Lake tables with columnMapping 
feature is not supported.");
+  }
+
+  @Test
+  public void testEmptyTableConversion() {
+    Engine engine = DefaultEngine.create(testHadoopConf);
+    createEmptyDeltaTableTransaction(engine)
+        .build(engine)
+        .commit(engine, CloseableIterable.emptyIterable());
+
+    TableIdentifier icebergTable = TableIdentifier.of("iceberg_table");
+    SnapshotDeltaLakeTable testAction =
+        new BaseSnapshotDeltaLakeKernelTableAction(sourceTableLocation)
+            .as(icebergTable)
+            .deltaLakeConfiguration(testHadoopConf)
+            .icebergCatalog(testCatalog)
+            .tableLocation(newTableLocation);
+
+    assertThat(testCatalog.tableExists(icebergTable)).isFalse();
+
+    testAction.execute();
+
+    assertThat(testCatalog.tableExists(icebergTable)).isTrue();
+
+    org.apache.iceberg.Table table = testCatalog.loadTable(icebergTable);
+    assertThat(((BaseTable) 
table).operations().current().formatVersion()).isEqualTo(3);
+  }
+
+  @Test
+  public void testTableCreated() throws Exception {
+    loadDeltaLakeGoldenTable("basic-decimal-table");
+
+    TableIdentifier icebergTable = TableIdentifier.of("iceberg_table");
+    SnapshotDeltaLakeTable testAction =
+        new BaseSnapshotDeltaLakeKernelTableAction(sourceTableLocation)
+            .as(icebergTable)
+            .deltaLakeConfiguration(testHadoopConf)
+            .icebergCatalog(testCatalog)
+            .tableLocation(newTableLocation);
+
+    assertThat(testCatalog.tableExists(icebergTable)).isFalse();
+
+    testAction.execute();
+
+    assertThat(testCatalog.tableExists(icebergTable)).isTrue();
+  }
+
+  @Test
+  public void testDefaultTableProperties() throws Exception {
+    loadDeltaLakeGoldenTable("basic-decimal-table");
+
+    TableIdentifier icebergTableIdentifier = 
TableIdentifier.of("iceberg_table");
+    SnapshotDeltaLakeTable testAction =
+        new BaseSnapshotDeltaLakeKernelTableAction(sourceTableLocation)
+            .as(icebergTableIdentifier)
+            .deltaLakeConfiguration(testHadoopConf)
+            .icebergCatalog(testCatalog)
+            .tableLocation(newTableLocation);
+
+    assertThat(testCatalog.tableExists(icebergTableIdentifier)).isFalse();
+
+    testAction.execute();
+
+    assertThat(testCatalog.tableExists(icebergTableIdentifier)).isTrue();
+
+    Map<String, String> properties = 
testCatalog.loadTable(icebergTableIdentifier).properties();
+    
assertThat(properties.get("original_location")).isEqualTo(sourceTableLocation);
+    assertThat(properties.get("snapshot_source")).isEqualTo("delta");
+    
assertThat(properties.containsKey(TableProperties.DEFAULT_NAME_MAPPING)).isTrue();
+  }
+
+  @Test
+  public void testCustomTableProperties() throws Exception {
+    loadDeltaLakeGoldenTable("basic-decimal-table");
+
+    TableIdentifier icebergTableIdentifier = 
TableIdentifier.of("iceberg_table");
+    SnapshotDeltaLakeTable testAction =
+        new BaseSnapshotDeltaLakeKernelTableAction(sourceTableLocation)
+            .as(icebergTableIdentifier)
+            .deltaLakeConfiguration(testHadoopConf)
+            .icebergCatalog(testCatalog)
+            .tableLocation(newTableLocation)
+            .tableProperty("custom_prop_1", "custom val 1")
+            .tableProperty("custom_prop_2", "custom val 2")
+            .tableProperties(
+                ImmutableMap.of(
+                    "custom_map_prop1", "val 1",
+                    "custom_map_prop2", "val 2"));
+
+    assertThat(testCatalog.tableExists(icebergTableIdentifier)).isFalse();
+
+    testAction.execute();
+
+    assertThat(testCatalog.tableExists(icebergTableIdentifier)).isTrue();
+
+    Map<String, String> properties = 
testCatalog.loadTable(icebergTableIdentifier).properties();
+    assertThat(properties.get("custom_prop_1")).isEqualTo("custom val 1");
+    assertThat(properties.get("custom_prop_2")).isEqualTo("custom val 2");
+    assertThat(properties.get("custom_map_prop1")).isEqualTo("val 1");
+    assertThat(properties.get("custom_map_prop2")).isEqualTo("val 2");
+  }
+
+  @Test
+  void testDeltaTableNotExist() {
+    SnapshotDeltaLakeTable testAction =
+        new BaseSnapshotDeltaLakeKernelTableAction(sourceTableLocation)
+            .as(TableIdentifier.of("test", "test"))
+            .deltaLakeConfiguration(testHadoopConf)
+            .icebergCatalog(testCatalog)
+            .tableLocation(newTableLocation);
+
+    assertThatThrownBy(testAction::execute)
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage(
+            "Delta Lake table does not exist at the given location: %s", 
sourceTableLocation);
+  }
+
+  @Test
+  public void testDeltaTableDVSupported() throws Exception {

Review Comment:
   The integration test has this assert 
org.apache.iceberg.delta.TestSnapshotDeltaLakeKernelTable#checkTagContentAndOrder
 and this assert verify number of tag/versions in delta and Iceberg and it also 
verify the data by `SELECT * AS OF VERSION`. 
   
   So, there is no bug for DVs related the the same data file (as we discussed 
offline) and there is test coverage. 
   



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