jackye1995 commented on code in PR #6449: URL: https://github.com/apache/iceberg/pull/6449#discussion_r1064046246
########## delta-lake/src/integration/java/org/apache/iceberg/delta/TestMigrateDeltaLakeTable.java: ########## @@ -0,0 +1,267 @@ +/* + * 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 java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.spark.Spark3Util; +import org.apache.iceberg.spark.SparkSessionCatalog; +import org.apache.spark.sql.Dataset; +import org.apache.spark.sql.Row; +import org.apache.spark.sql.SaveMode; +import org.apache.spark.sql.SparkSession; +import org.apache.spark.sql.connector.catalog.CatalogExtension; +import org.apache.spark.sql.connector.catalog.CatalogPlugin; +import org.apache.spark.sql.connector.catalog.TableCatalog; +import org.apache.spark.sql.delta.catalog.DeltaCatalog; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class TestMigrateDeltaLakeTable extends SparkDeltaLakeMigrationTestBase { + private static final String NAMESPACE = "default"; + + private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + private String partitionedIdentifier; + private String unpartitionedIdentifier; + + @Parameterized.Parameters(name = "Catalog Name {0} - Options {2}") + public static Object[][] parameters() { + return new Object[][] { + new Object[] { + "delta", + DeltaCatalog.class.getName(), + ImmutableMap.of( + "type", + "hive", + "default-namespace", + "default", + "parquet-enabled", + "true", + "cache-enabled", + "false" // Spark will delete tables using v1, leaving the cache out of sync + ) + } + }; + } + + @Rule public TemporaryFolder temp = new TemporaryFolder(); + @Rule public TemporaryFolder other = new TemporaryFolder(); + + private final String partitionedTableName = "partitioned_table"; + private final String unpartitionedTableName = "unpartitioned_table"; + + private final String defaultSparkCatalog = "spark_catalog"; + private String partitionedLocation; + private String unpartitionedLocation; + private final String type; + private TableCatalog catalog; + + private String catalogName; + + public TestMigrateDeltaLakeTable( + String catalogName, String implementation, Map<String, String> config) { + super(catalogName, implementation, config); + spark + .conf() + .set("spark.sql.catalog." + defaultSparkCatalog, SparkSessionCatalog.class.getName()); + this.catalog = (TableCatalog) spark.sessionState().catalogManager().catalog(catalogName); + this.type = config.get("type"); + this.catalogName = catalogName; + } + + @Before + public void before() { + try { + File partitionedFolder = temp.newFolder(); + File unpartitionedFolder = other.newFolder(); + partitionedLocation = partitionedFolder.toURI().toString(); + unpartitionedLocation = unpartitionedFolder.toURI().toString(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + partitionedIdentifier = destName(partitionedTableName); + unpartitionedIdentifier = destName(unpartitionedTableName); + + CatalogExtension delta = + (CatalogExtension) spark.sessionState().catalogManager().catalog("delta"); + // This needs to be set, otherwise Delta operations fail as the catalog is designed to override + // the default catalog (spark_catalog). + delta.setDelegateCatalog(spark.sessionState().catalogManager().currentCatalog()); + + spark.sql(String.format("DROP TABLE IF EXISTS %s", partitionedIdentifier)); + spark.sql(String.format("DROP TABLE IF EXISTS %s", unpartitionedIdentifier)); + + // Create a partitioned and unpartitioned table, doing a few inserts on each + IntStream.range(0, 3) + .forEach( + i -> { + List<SimpleRecord> record = + Lists.newArrayList(new SimpleRecord(i, ALPHABET.substring(i, i + 1))); Review Comment: can use `UUID.randomUUID().toString()` instead of doing this -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org