Skip to content

Commit

Permalink
Core, Spark: Avoid deprecated methods in Guava Files (#11865)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr authored Dec 24, 2024
1 parent c6d9e0c commit d6d3cf5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.commons.io.FileUtils;
import org.apache.iceberg.io.OutputFile;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.apache.iceberg.relocated.com.google.common.io.Files;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand Down Expand Up @@ -96,7 +95,8 @@ public int getFormatVersion() {
@Benchmark
@Threads(1)
public void writeManifestFile(BenchmarkState state) throws IOException {
this.baseDir = Files.createTempDir().getAbsolutePath();
this.baseDir =
java.nio.file.Files.createTempDirectory("benchmark-").toAbsolutePath().toString();
this.manifestListFile = String.format("%s/%s.avro", baseDir, UUID.randomUUID());

try (ManifestListWriter listWriter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ TableMetadata readMetadataVersion(int version) {
}

int readVersionHint() throws IOException {
return Integer.parseInt(Files.readFirstLine(versionHintFile, StandardCharsets.UTF_8));
return Integer.parseInt(
Files.asCharSource(versionHintFile, StandardCharsets.UTF_8).readFirstLine());
}

void replaceVersionHint(int version) throws IOException {
// remove the checksum that will no longer match
new File(metadataDir, ".version-hint.text.crc").delete();
Files.write(String.valueOf(version), versionHintFile, StandardCharsets.UTF_8);
Files.asCharSink(versionHintFile, StandardCharsets.UTF_8).write(String.valueOf(version));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import static org.apache.spark.sql.functions.lit;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.sql.Timestamp;
import java.util.List;
import java.util.Locale;
Expand All @@ -32,7 +35,6 @@
import org.apache.iceberg.Table;
import org.apache.iceberg.actions.DeleteOrphanFiles;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.relocated.com.google.common.io.Files;
import org.apache.iceberg.spark.Spark3Util;
import org.apache.iceberg.spark.SparkSessionCatalog;
import org.apache.iceberg.spark.actions.SparkActions;
Expand Down Expand Up @@ -161,7 +163,14 @@ private Table table() {
}

private String catalogWarehouse() {
return Files.createTempDir().getAbsolutePath() + "/" + UUID.randomUUID() + "/";
try {
return Files.createTempDirectory("benchmark-").toAbsolutePath()
+ "/"
+ UUID.randomUUID()
+ "/";
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private void setupSpark() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.apache.spark.sql.functions.expr;

import java.io.IOException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
Expand All @@ -36,7 +37,6 @@
import org.apache.iceberg.SortOrder;
import org.apache.iceberg.Table;
import org.apache.iceberg.actions.SizeBasedFileRewriter;
import org.apache.iceberg.relocated.com.google.common.io.Files;
import org.apache.iceberg.spark.Spark3Util;
import org.apache.iceberg.spark.SparkSchemaUtil;
import org.apache.iceberg.spark.SparkSessionCatalog;
Expand Down Expand Up @@ -372,8 +372,13 @@ protected final SparkSession spark() {
}

protected String getCatalogWarehouse() {
String location = Files.createTempDir().getAbsolutePath() + "/" + UUID.randomUUID() + "/";
return location;
try {
String location =
Files.createTempDirectory("benchmark-").toAbsolutePath() + "/" + UUID.randomUUID() + "/";
return location;
} catch (IOException e) {
throw new RuntimeException(e);
}
}

protected void cleanupFiles() throws IOException {
Expand Down

0 comments on commit d6d3cf5

Please sign in to comment.