Skip to content
Merged
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 @@ -22,6 +22,7 @@ public class FileSystemConfig
private boolean nativeAzureEnabled;
private boolean nativeS3Enabled;
private boolean nativeGcsEnabled;
private boolean nativeLocalEnabled;
private boolean cacheEnabled;

public boolean isHadoopEnabled()
Expand Down Expand Up @@ -77,6 +78,18 @@ public boolean isNativeGcsEnabled()
return nativeGcsEnabled;
}

@Config("fs.native-local.enabled")
public FileSystemConfig setNativeLocalEnabled(boolean nativeLocalEnabled)
{
this.nativeLocalEnabled = nativeLocalEnabled;
return this;
}

public boolean isNativeLocalEnabled()
{
return nativeLocalEnabled;
}

@Config("fs.native-gcs.enabled")
public FileSystemConfig setNativeGcsEnabled(boolean nativeGcsEnabled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import io.trino.filesystem.cache.TrinoFileSystemCache;
import io.trino.filesystem.gcs.GcsFileSystemFactory;
import io.trino.filesystem.gcs.GcsFileSystemModule;
import io.trino.filesystem.local.LocalFileSystemConfig;
import io.trino.filesystem.local.LocalFileSystemFactory;
import io.trino.filesystem.memory.MemoryFileSystemCache;
import io.trino.filesystem.memory.MemoryFileSystemCacheModule;
import io.trino.filesystem.s3.FileSystemS3;
Expand All @@ -51,6 +53,7 @@

import static com.google.inject.multibindings.MapBinder.newMapBinder;
import static com.google.inject.multibindings.OptionalBinder.newOptionalBinder;
import static io.airlift.configuration.ConfigBinder.configBinder;
import static java.util.Objects.requireNonNull;

public class FileSystemModule
Expand Down Expand Up @@ -119,6 +122,12 @@ protected void setup(Binder binder)
factories.addBinding("gs").to(GcsFileSystemFactory.class);
}

if (config.isNativeLocalEnabled()) {
configBinder(binder).bindConfig(LocalFileSystemConfig.class);
factories.addBinding("local").to(LocalFileSystemFactory.class);
factories.addBinding("file").to(LocalFileSystemFactory.class);
}

newOptionalBinder(binder, CachingHostAddressProvider.class).setDefault().to(DefaultCachingHostAddressProvider.class).in(Scopes.SINGLETON);
newOptionalBinder(binder, CacheKeyProvider.class).setDefault().to(DefaultCacheKeyProvider.class).in(Scopes.SINGLETON);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void testDefaults()
.setNativeAzureEnabled(false)
.setNativeS3Enabled(false)
.setNativeGcsEnabled(false)
.setNativeLocalEnabled(false)
.setCacheEnabled(false));
}

Expand All @@ -45,6 +46,7 @@ public void testExplicitPropertyMappings()
.put("fs.native-azure.enabled", "true")
.put("fs.native-s3.enabled", "true")
.put("fs.native-gcs.enabled", "true")
.put("fs.native-local.enabled", "true")
.put("fs.cache.enabled", "true")
.buildOrThrow();

Expand All @@ -54,6 +56,7 @@ public void testExplicitPropertyMappings()
.setNativeAzureEnabled(true)
.setNativeS3Enabled(true)
.setNativeGcsEnabled(true)
.setNativeLocalEnabled(true)
.setCacheEnabled(true);

assertFullMapping(properties, expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private Path toDirectoryPath(Location location)

private static void validateLocalLocation(Location location)
{
checkArgument(location.scheme().equals(Optional.of("local")), "Only 'local' scheme is supported: %s", location);
checkArgument(location.scheme().equals(Optional.of("local")) || location.scheme().equals(Optional.of("file")), "Only 'local' and 'file' scheme is supported: %s", location);
checkArgument(location.userInfo().isEmpty(), "Local location cannot contain user info: %s", location);
checkArgument(location.host().isEmpty(), "Local location cannot contain a host: %s", location);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.filesystem.local;

import io.airlift.configuration.Config;
import io.airlift.configuration.ConfigDescription;
import io.airlift.configuration.validation.FileExists;

import java.nio.file.Path;
import java.nio.file.Paths;

import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR;

public class LocalFileSystemConfig
{
private Path location = Paths.get(System.getProperty(JAVA_IO_TMPDIR.key()));

public @FileExists Path getLocation()
{
return location;
}

@ConfigDescription("Local file system root directory")
@Config("local.location")
public LocalFileSystemConfig setLocation(Path location)
{
this.location = location;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.filesystem.local;

import com.google.inject.Inject;
import io.trino.filesystem.TrinoFileSystem;
import io.trino.filesystem.TrinoFileSystemFactory;
import io.trino.spi.security.ConnectorIdentity;
Expand All @@ -32,6 +33,12 @@ public LocalFileSystemFactory(Path rootPath)
fileSystem = new LocalFileSystem(rootPath);
}

@Inject
public LocalFileSystemFactory(LocalFileSystemConfig config)
{
this(config.getLocation());
}

@Override
public TrinoFileSystem create(ConnectorIdentity identity)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.filesystem.local;

import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR;
import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping;
import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults;
import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults;

final class TestLocalFileSystemConfig
{
@Test
void testDefaults()
{
assertRecordedDefaults(recordDefaults(LocalFileSystemConfig.class)
.setLocation(Paths.get(System.getProperty(JAVA_IO_TMPDIR.key()))));
}

@Test
void testExplicitPropertyMappings(@TempDir Path tempDirectory)
{
Map<String, String> properties = ImmutableMap.<String, String>builder()
.put("local.location", tempDirectory.toString())
.buildOrThrow();

LocalFileSystemConfig expected = new LocalFileSystemConfig()
.setLocation(tempDirectory);

assertFullMapping(properties, expected);
}
}