-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to read single parquet file hosted in AWS S3 (#4972)
Refactored local parquet reading code to support reading from URIs instead of file paths.
- Loading branch information
1 parent
2e747b4
commit db04b57
Showing
77 changed files
with
2,704 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
plugins { | ||
id 'java-library' | ||
id 'io.deephaven.project.register' | ||
} | ||
|
||
dependencies { | ||
implementation project(':Base') | ||
|
||
// Needed for SafeCloseable | ||
implementation project(':Util') | ||
|
||
compileOnly depAnnotations | ||
|
||
Classpaths.inheritJUnitPlatform(project) | ||
Classpaths.inheritAssertJ(project) | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.deephaven.project.ProjectType=JAVA_PUBLIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Util/channel/src/main/java/io/deephaven/util/channel/SeekableChannelContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.deephaven.util.channel; | ||
|
||
import io.deephaven.util.SafeCloseable; | ||
|
||
/** | ||
* Context object for reading and writing to channels created by {@link SeekableChannelsProvider}. | ||
*/ | ||
public interface SeekableChannelContext extends SafeCloseable { | ||
|
||
SeekableChannelContext NULL = new SeekableChannelContext() {}; | ||
|
||
/** | ||
* Release any resources associated with this context. The context should not be used afterward. | ||
*/ | ||
default void close() {} | ||
} |
64 changes: 64 additions & 0 deletions
64
Util/channel/src/main/java/io/deephaven/util/channel/SeekableChannelsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.util.channel; | ||
|
||
import io.deephaven.util.SafeCloseable; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.channels.SeekableByteChannel; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public interface SeekableChannelsProvider extends SafeCloseable { | ||
|
||
/** | ||
* Take the file source path or URI and convert it to a URI object. | ||
* | ||
* @param source The file source path or URI | ||
* @return The URI object | ||
*/ | ||
static URI convertToURI(final String source) { | ||
final URI uri; | ||
try { | ||
uri = new URI(source); | ||
} catch (final URISyntaxException e) { | ||
// If the URI is invalid, assume it's a file path | ||
return new File(source).toURI(); | ||
} | ||
if (uri.getScheme() == null) { | ||
// Need to convert to a "file" URI | ||
return new File(source).toURI(); | ||
} | ||
return uri; | ||
} | ||
|
||
/** | ||
* Create a new {@link SeekableChannelContext} object for creating read channels via this provider. | ||
*/ | ||
SeekableChannelContext makeContext(); | ||
|
||
/** | ||
* Check if the given context is compatible with this provider. Useful to test if we can use provided | ||
* {@code context} object for creating channels with this provider. | ||
*/ | ||
boolean isCompatibleWith(@NotNull SeekableChannelContext channelContext); | ||
|
||
default SeekableByteChannel getReadChannel(@NotNull SeekableChannelContext channelContext, @NotNull String uriStr) | ||
throws IOException { | ||
return getReadChannel(channelContext, convertToURI(uriStr)); | ||
} | ||
|
||
SeekableByteChannel getReadChannel(@NotNull SeekableChannelContext channelContext, @NotNull URI uri) | ||
throws IOException; | ||
|
||
default SeekableByteChannel getWriteChannel(@NotNull final String path, final boolean append) throws IOException { | ||
return getWriteChannel(Paths.get(path), append); | ||
} | ||
|
||
SeekableByteChannel getWriteChannel(@NotNull Path path, boolean append) throws IOException; | ||
} |
56 changes: 56 additions & 0 deletions
56
Util/channel/src/main/java/io/deephaven/util/channel/SeekableChannelsProviderLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.util.channel; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.ServiceLoader; | ||
|
||
/** | ||
* A service loader class for loading {@link SeekableChannelsProviderPlugin} implementations at runtime and provide | ||
* {@link SeekableChannelsProvider} implementations for different URI schemes, e.g., S3. | ||
*/ | ||
public final class SeekableChannelsProviderLoader { | ||
|
||
private static volatile SeekableChannelsProviderLoader instance; | ||
|
||
public static SeekableChannelsProviderLoader getInstance() { | ||
if (instance == null) { | ||
instance = new SeekableChannelsProviderLoader(); | ||
} | ||
return instance; | ||
} | ||
|
||
private final List<SeekableChannelsProviderPlugin> providers; | ||
|
||
private SeekableChannelsProviderLoader() { | ||
providers = new ArrayList<>(); | ||
// Load the plugins | ||
for (final SeekableChannelsProviderPlugin plugin : ServiceLoader.load(SeekableChannelsProviderPlugin.class)) { | ||
providers.add(plugin); | ||
} | ||
} | ||
|
||
/** | ||
* Create a new {@link SeekableChannelsProvider} based on given URI and object using the plugins loaded by the | ||
* {@link ServiceLoader}. For example, for a "S3" URI, we will create a {@link SeekableChannelsProvider} which can | ||
* read files from S3. | ||
* | ||
* @param uri The URI | ||
* @param object An optional object to pass to the {@link SeekableChannelsProviderPlugin} implementations. | ||
* @return A {@link SeekableChannelsProvider} for the given URI. | ||
*/ | ||
public SeekableChannelsProvider fromServiceLoader(@NotNull final URI uri, @Nullable final Object object) { | ||
for (final SeekableChannelsProviderPlugin plugin : providers) { | ||
if (plugin.isCompatible(uri, object)) { | ||
return plugin.createProvider(uri, object); | ||
} | ||
} | ||
throw new UnsupportedOperationException("No plugin found for uri: " + uri); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Util/channel/src/main/java/io/deephaven/util/channel/SeekableChannelsProviderPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.util.channel; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* A plugin interface for providing {@link SeekableChannelsProvider} implementations for different URI schemes, e.g. S3. | ||
* Check out {@link SeekableChannelsProviderLoader} for more details. | ||
*/ | ||
public interface SeekableChannelsProviderPlugin { | ||
/** | ||
* Check if this plugin is compatible with the given URI and config object. | ||
*/ | ||
boolean isCompatible(@NotNull URI uri, @Nullable Object config); | ||
|
||
/** | ||
* Create a {@link SeekableChannelsProvider} for the given URI and config object. | ||
*/ | ||
SeekableChannelsProvider createProvider(@NotNull URI uri, @Nullable Object object); | ||
} |
Oops, something went wrong.