Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize and secure temp file creation #4

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.util.Arrays;
import org.apache.iceberg.aliyun.AliyunProperties;
import org.apache.iceberg.exceptions.NotFoundException;
Expand Down Expand Up @@ -72,7 +73,7 @@ public class OSSOutputStream extends PositionOutputStream {

private static File newStagingFile(String ossStagingDirectory) {
try {
File stagingFile = File.createTempFile("oss-file-io-", ".tmp", new File(ossStagingDirectory));
File stagingFile = Files.createTempFile(new File(ossStagingDirectory).toPath(), "oss-file-io-", ".tmp").toFile();
stagingFile.deleteOnExit();
return stagingFile;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private void newStream() throws IOException {
}

createStagingDirectoryIfNotExists();
currentStagingFile = File.createTempFile("s3fileio-", ".tmp", stagingDirectory);
currentStagingFile = Files.createTempFile(stagingDirectory.toPath(), "s3fileio-", ".tmp").toFile();
currentStagingFile.deleteOnExit();
try {
currentPartMessageDigest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -93,7 +94,7 @@ public class SparkParquetReadersFlatDataBenchmark {

@Setup
public void setupBenchmark() throws IOException {
dataFile = File.createTempFile("parquet-flat-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-flat-data-benchmark", ".parquet").toFile();
dataFile.delete();
List<GenericData.Record> records = RandomData.generateList(SCHEMA, NUM_RECORDS, 0L);
try (FileAppender<GenericData.Record> writer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -91,7 +92,7 @@ public class SparkParquetReadersNestedDataBenchmark {

@Setup
public void setupBenchmark() throws IOException {
dataFile = File.createTempFile("parquet-nested-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-nested-data-benchmark", ".parquet").toFile();
dataFile.delete();
List<GenericData.Record> records = RandomData.generateList(SCHEMA, NUM_RECORDS, 0L);
try (FileAppender<GenericData.Record> writer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class SparkParquetWritersFlatDataBenchmark {
@Setup
public void setupBenchmark() throws IOException {
rows = RandomData.generateSpark(SCHEMA, NUM_RECORDS, 0L);
dataFile = File.createTempFile("parquet-flat-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-flat-data-benchmark", ".parquet").toFile();
dataFile.delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class SparkParquetWritersNestedDataBenchmark {
@Setup
public void setupBenchmark() throws IOException {
rows = RandomData.generateSpark(SCHEMA, NUM_RECORDS, 0L);
dataFile = File.createTempFile("parquet-nested-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-nested-data-benchmark", ".parquet").toFile();
dataFile.delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -93,7 +94,7 @@ public class SparkParquetReadersFlatDataBenchmark {

@Setup
public void setupBenchmark() throws IOException {
dataFile = File.createTempFile("parquet-flat-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-flat-data-benchmark", ".parquet").toFile();
dataFile.delete();
List<GenericData.Record> records = RandomData.generateList(SCHEMA, NUM_RECORDS, 0L);
try (FileAppender<GenericData.Record> writer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -91,7 +92,7 @@ public class SparkParquetReadersNestedDataBenchmark {

@Setup
public void setupBenchmark() throws IOException {
dataFile = File.createTempFile("parquet-nested-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-nested-data-benchmark", ".parquet").toFile();
dataFile.delete();
List<GenericData.Record> records = RandomData.generateList(SCHEMA, NUM_RECORDS, 0L);
try (FileAppender<GenericData.Record> writer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class SparkParquetWritersFlatDataBenchmark {
@Setup
public void setupBenchmark() throws IOException {
rows = RandomData.generateSpark(SCHEMA, NUM_RECORDS, 0L);
dataFile = File.createTempFile("parquet-flat-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-flat-data-benchmark", ".parquet").toFile();
dataFile.delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class SparkParquetWritersNestedDataBenchmark {
@Setup
public void setupBenchmark() throws IOException {
rows = RandomData.generateSpark(SCHEMA, NUM_RECORDS, 0L);
dataFile = File.createTempFile("parquet-nested-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-nested-data-benchmark", ".parquet").toFile();
dataFile.delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -93,7 +94,7 @@ public class SparkParquetReadersFlatDataBenchmark {

@Setup
public void setupBenchmark() throws IOException {
dataFile = File.createTempFile("parquet-flat-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-flat-data-benchmark", ".parquet").toFile();
dataFile.delete();
List<GenericData.Record> records = RandomData.generateList(SCHEMA, NUM_RECORDS, 0L);
try (FileAppender<GenericData.Record> writer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -91,7 +92,7 @@ public class SparkParquetReadersNestedDataBenchmark {

@Setup
public void setupBenchmark() throws IOException {
dataFile = File.createTempFile("parquet-nested-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-nested-data-benchmark", ".parquet").toFile();
dataFile.delete();
List<GenericData.Record> records = RandomData.generateList(SCHEMA, NUM_RECORDS, 0L);
try (FileAppender<GenericData.Record> writer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class SparkParquetWritersFlatDataBenchmark {
@Setup
public void setupBenchmark() throws IOException {
rows = RandomData.generateSpark(SCHEMA, NUM_RECORDS, 0L);
dataFile = File.createTempFile("parquet-flat-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-flat-data-benchmark", ".parquet").toFile();
dataFile.delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class SparkParquetWritersNestedDataBenchmark {
@Setup
public void setupBenchmark() throws IOException {
rows = RandomData.generateSpark(SCHEMA, NUM_RECORDS, 0L);
dataFile = File.createTempFile("parquet-nested-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-nested-data-benchmark", ".parquet").toFile();
dataFile.delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -93,7 +94,7 @@ public class SparkParquetReadersFlatDataBenchmark {

@Setup
public void setupBenchmark() throws IOException {
dataFile = File.createTempFile("parquet-flat-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-flat-data-benchmark", ".parquet").toFile();
dataFile.delete();
List<GenericData.Record> records = RandomData.generateList(SCHEMA, NUM_RECORDS, 0L);
try (FileAppender<GenericData.Record> writer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -91,7 +92,7 @@ public class SparkParquetReadersNestedDataBenchmark {

@Setup
public void setupBenchmark() throws IOException {
dataFile = File.createTempFile("parquet-nested-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-nested-data-benchmark", ".parquet").toFile();
dataFile.delete();
List<GenericData.Record> records = RandomData.generateList(SCHEMA, NUM_RECORDS, 0L);
try (FileAppender<GenericData.Record> writer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class SparkParquetWritersFlatDataBenchmark {
@Setup
public void setupBenchmark() throws IOException {
rows = RandomData.generateSpark(SCHEMA, NUM_RECORDS, 0L);
dataFile = File.createTempFile("parquet-flat-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-flat-data-benchmark", ".parquet").toFile();
dataFile.delete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.iceberg.spark.data.parquet;

import java.nio.file.Files;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;

Expand Down Expand Up @@ -81,7 +82,7 @@ public class SparkParquetWritersNestedDataBenchmark {
@Setup
public void setupBenchmark() throws IOException {
rows = RandomData.generateSpark(SCHEMA, NUM_RECORDS, 0L);
dataFile = File.createTempFile("parquet-nested-data-benchmark", ".parquet");
dataFile = Files.createTempFile("parquet-nested-data-benchmark", ".parquet").toFile();
dataFile.delete();
}

Expand Down