Skip to content

Commit

Permalink
Move copy directory function to utils class
Browse files Browse the repository at this point in the history
  • Loading branch information
pajaks authored and ebyhr committed Aug 21, 2023
1 parent 6e2d23c commit 74f2c4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static com.google.common.collect.Iterators.getOnlyElement;
import static com.google.common.collect.MoreCollectors.onlyElement;
Expand All @@ -61,13 +60,13 @@
import static io.trino.plugin.deltalake.DeltaLakeQueryRunner.DELTA_CATALOG;
import static io.trino.plugin.deltalake.DeltaLakeQueryRunner.createDeltaLakeQueryRunner;
import static io.trino.plugin.deltalake.DeltaTestingConnectorSession.SESSION;
import static io.trino.plugin.deltalake.TestingDeltaLakeUtils.copyDirectoryContents;
import static io.trino.plugin.deltalake.transactionlog.DeltaLakeSchemaSupport.getColumnsMetadata;
import static io.trino.plugin.deltalake.transactionlog.checkpoint.TransactionLogTail.getEntriesFromJson;
import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT;
import static io.trino.plugin.hive.HiveTestUtils.HDFS_FILE_SYSTEM_STATS;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static java.lang.String.format;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.testng.Assert.assertFalse;
Expand Down Expand Up @@ -684,19 +683,4 @@ private static MetadataEntry loadMetadataEntry(long entryNumber, Path tableLocat
.collect(onlyElement());
return transactionLog.getMetaData();
}

private void copyDirectoryContents(Path source, Path destination)
throws IOException
{
try (Stream<Path> stream = Files.walk(source)) {
stream.forEach(file -> {
try {
Files.copy(file, destination.resolve(source.relativize(file)), REPLACE_EXISTING);
}
catch (IOException e) {
throw new RuntimeException(e);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
import io.trino.testing.DistributedQueryRunner;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;

import static io.trino.plugin.deltalake.DeltaLakeQueryRunner.DELTA_CATALOG;
import static io.trino.testing.TestingConnectorSession.SESSION;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

public final class TestingDeltaLakeUtils
{
Expand All @@ -45,4 +49,19 @@ public static List<AddFileEntry> getTableActiveFiles(TransactionLogAccess transa
TableSnapshot snapshot = transactionLogAccess.loadSnapshot(dummyTable, tableLocation, SESSION);
return transactionLogAccess.getActiveFiles(snapshot, SESSION);
}

public static void copyDirectoryContents(Path source, Path destination)
throws IOException
{
try (Stream<Path> stream = Files.walk(source)) {
stream.forEach(file -> {
try {
Files.copy(file, destination.resolve(source.relativize(file)), REPLACE_EXISTING);
}
catch (IOException e) {
throw new RuntimeException(e);
}
});
}
}
}

0 comments on commit 74f2c4d

Please sign in to comment.