Skip to content

Commit

Permalink
exposed the thread pool size variable so clients can set appropriate …
Browse files Browse the repository at this point in the history
…values (jtablesaw#818)
  • Loading branch information
lwhite1 authored Jul 13, 2020
1 parent 468be51 commit c21b21f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
16 changes: 15 additions & 1 deletion saw/src/main/java/tech/tablesaw/io/saw/SawReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,22 @@ public static Table readTable(String path) {
* @throws UncheckedIOException wrapping an IOException if the file cannot be read
*/
public static Table readTable(File file) {
return readTable(file, READER_POOL_SIZE);
}

/**
* Reads a tablesaw table into memory
*
* @param file The location of the table data. If not fully specified, it is interpreted as
* relative to the working directory. The path will typically end in ".saw", as in
* "mytables/nasdaq-2015.saw"
* @param threadPoolSize The size of the the thread-pool allocated to reading. Each column is read
* in own thread
* @throws UncheckedIOException wrapping an IOException if the file cannot be read
*/
public static Table readTable(File file, int threadPoolSize) {

ExecutorService executorService = Executors.newFixedThreadPool(READER_POOL_SIZE);
ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize);
CompletionService<Void> readerCompletionService =
new ExecutorCompletionService<>(executorService);

Expand Down
23 changes: 22 additions & 1 deletion saw/src/main/java/tech/tablesaw/io/saw/SawWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,34 @@ public class SawWriter {
* @throws UncheckedIOException wrapping IOException if the file can not be read
*/
public static String saveTable(String parentFolderName, Relation table) {
return saveTable(parentFolderName, table, WRITER_POOL_SIZE);
}

/**
* Saves the data from the given table in the location specified by parentFolderName. Within that
* folder each table has its own sub-folder, whose name is based on the name of the table.
*
* <p>NOTE: If you store a table with the same name in the same folder. The data in that folder
* will be over-written.
*
* <p>The storage format is the tablesaw compressed column-oriented format, which consists of a
* set of file in a folder. The name of the folder is based on the name of the table.
*
* @param parentFolderName The location of the table (for example: "mytables")
* @param table The table to be saved
* @param threadPoolSize The size of the the thread-pool allocated to writing. Each column is
* written in own thread
* @return The path and name of the table
* @throws UncheckedIOException wrapping IOException if the file can not be read
*/
public static String saveTable(String parentFolderName, Relation table, int threadPoolSize) {

Preconditions.checkArgument(
parentFolderName != null, "The folder name for the saw output cannot be null");
Preconditions.checkArgument(
!parentFolderName.isEmpty(), "The folder name for the saw output cannot be empty");

ExecutorService executorService = Executors.newFixedThreadPool(WRITER_POOL_SIZE);
ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize);
CompletionService<Void> writerCompletionService =
new ExecutorCompletionService<>(executorService);

Expand Down

0 comments on commit c21b21f

Please sign in to comment.